Skip to content

Commit

Permalink
separate pages for create and my apps
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Sep 20, 2023
1 parent 098f203 commit b6f1587
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
7 changes: 5 additions & 2 deletions jhub_apps/launcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import panel as pn

from jhub_apps.launcher.panel_app import create_app
from jhub_apps.launcher.panel_app import create_app, create_app_page


def app(origin_host):
pn.serve(
{"/": create_app},
{
"/": create_app,
"/create": create_app_page,
},
port=5000,
allow_websocket_origin=[origin_host],
show=False,
Expand Down
55 changes: 37 additions & 18 deletions jhub_apps/launcher/panel_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ def _get_server_apps(username):


class ListItem(pn.Column): # Change the base class to pn.Column
def __init__(self, app: App, input_form_widget: InputFormWidget, **params):
def __init__(self, app: App, **params):
self.app = app
self.input_form_widget = input_form_widget
self.username = params.get("username")

# Define Panel buttons
Expand All @@ -91,7 +90,7 @@ def __init__(self, app: App, input_form_widget: InputFormWidget, **params):
## {self.app.name}
{self.app.description or "No description found for app"}
""",
margin=(0, 20, 0, 10)
margin=(0, 20, 0, 10),
),
# self.view_button,
buttons,
Expand Down Expand Up @@ -136,20 +135,27 @@ def on_delete(self, event):
self.content.visible = False


def create_list_apps(input_form_widget, username):
def create_list_apps(username):
print("Create Dashboards Layout")
list_items = []
apps = _get_server_apps(username)
for app in apps:
list_item = ListItem(
app=app, input_form_widget=input_form_widget, username=username
)
list_item = ListItem(app=app, username=username)
list_items.append(list_item)

heading = pn.pane.Markdown("## Your Apps", sizing_mode="stretch_width")
# Wrap everything in a Column with the list-container class
apps_grid = pn.GridBox(*list_items, ncols=4)
create_app_button = pn.widgets.Button(
name=CREATE_APP_BTN_TXT, button_type="primary"
)
code = f"window.location.href = '/services/japps/create'"
create_app_button.js_on_click(code=code)
layout = pn.Column(
pn.Row(
create_app_button,
sizing_mode="fixed",
),
heading,
apps_grid,
css_classes=["list-container"],
Expand Down Expand Up @@ -250,6 +256,28 @@ def get_username():
return username[0].decode()


def create_app_page():
input_form_widget, input_form = get_input_form_widget()
username = get_username()

def button_callback(event):
_create_server(event, input_form_widget, input_form, username)

input_form_widget.button_widget.on_click(button_callback)

your_apps_button = pn.widgets.Button(name="Apps", button_type="primary")
code = f"window.location.href = '/services/japps/'"
your_apps_button.js_on_click(code=code)

return pn.Column(
pn.Row(
your_apps_button,
sizing_mode="fixed",
),
input_form,
)


def create_app():
print("*" * 100)
print("CREATING APP")
Expand All @@ -258,14 +286,5 @@ def create_app():
print("*" * 100)
if not username:
return pn.pane.Markdown("# No user found!")
input_form_widget, input_form = get_input_form_widget()
created_apps = create_list_apps(input_form_widget, username)
apps_page = create_apps_page(input_form, created_apps)

def button_callback(event):
_create_server(event, input_form_widget, input_form, username)
apps_page.pop(-1)
apps_page.append(create_list_apps(input_form_widget, username))

input_form_widget.button_widget.on_click(button_callback)
return apps_page
created_apps = create_list_apps(username)
return pn.Row(created_apps)
11 changes: 7 additions & 4 deletions jhub_apps/service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ def decorated(*args, **kwargs):
return decorated


@app.route(prefix)
@app.route(f"{prefix}/")
@app.route(f"{prefix}/<path:subpath>")
@authenticated
def index(user):
"Non-authenticated function that returns {'Hello': 'World'}"
script = server_document("/services/launcher", arguments={"username": user["name"]})
def index(user, subpath=None):
subpath = subpath if subpath else ""
script = server_document(
f"/services/launcher/{subpath}", arguments={"username": user["name"]}
)
return render_template(
"launcher_base.html", **{"request": request, "script": script}
)
Expand Down

0 comments on commit b6f1587

Please sign in to comment.