Skip to content

Commit

Permalink
[wip] server page
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Jan 15, 2024
1 parent 73ff5c7 commit ce7abe6
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 205 deletions.
12 changes: 8 additions & 4 deletions frontend/src/environments/LogDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ function _EnvironmentLogButton(props: IEnvironmentLogButton) {
const handleOpen = () => {
setOpen(true);
if (divRef.current) {
terminalRef.current.terminal.open(divRef.current);
terminalRef.current.fitAddon.fit();
const {terminal, fitAddon} = terminalFactory()
terminalRef.current.terminal = terminal
terminalRef.current.fitAddon = fitAddon

terminal.open(divRef.current);
fitAddon.fit();
const jhData = (window as any).jhdata;
const baseUrl = jhData.base_url;
const xsrfToken = jhData.xsrf_token;
Expand Down Expand Up @@ -65,8 +69,8 @@ function _EnvironmentLogButton(props: IEnvironmentLogButton) {
setBuilt(true);
return;
}
terminalRef.current.terminal.write(data.message);
terminalRef.current.fitAddon.fit();
terminal.write(data.message);
fitAddon.fit();
};
}
};
Expand Down
2 changes: 2 additions & 0 deletions jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@

user = getpass.getuser()
c.Authenticator.admin_users = {user, "alice"}
c.JupyterHub.allow_named_servers = True
c.JupyterHub.ip = '0.0.0.0'
4 changes: 2 additions & 2 deletions tljh_repo2docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .builder import BuildHandler
from .docker import list_images
from .imagesOld import ImagesHandlerOld
from .servers import ServersHandler
from .images import ImagesHandler
from .logs import LogsHandler

Expand Down Expand Up @@ -197,7 +197,7 @@ def tljh_custom_jupyterhub_config(c):
# register the handlers to manage the user images
c.JupyterHub.extra_handlers.extend(
[
(r"environments-old", ImagesHandlerOld),
(r"servers", ServersHandler),
(r"environments", ImagesHandler),
(r"api/environments", BuildHandler),
(r"api/environments/([^/]+)/logs", LogsHandler),
Expand Down
28 changes: 0 additions & 28 deletions tljh_repo2docker/imagesOld.py

This file was deleted.

37 changes: 37 additions & 0 deletions tljh_repo2docker/servers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from inspect import isawaitable
from jupyterhub.handlers.base import BaseHandler
from jupyterhub.utils import admin_only
from tornado import web

from .docker import list_containers, list_images


class ServersHandler(BaseHandler):
"""
Handler to show the list of servers available
"""

@web.authenticated
async def get(self):
images = await list_images()
user = self.current_user
if user.running:
# trigger poll_and_notify event in case of a server that died
await user.spawner.poll_and_notify()
auth_state = await user.get_auth_state()
print('########', auth_state)

result = self.render_template(
"servers.html",
images=images,
allow_named_servers=self.allow_named_servers,
named_server_limit_per_user=await self.get_current_user_named_server_limit(),
spawners=user.orm_user._orm_spawners,
default_server=user.spawner,
auth_state=auth_state
)

if isawaitable(result):
self.write(await result)
else:
self.write(result)
170 changes: 0 additions & 170 deletions tljh_repo2docker/templates/images-old.html

This file was deleted.

3 changes: 2 additions & 1 deletion tljh_repo2docker/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

{% block nav_bar_left_items %}
<li><a href="{{base_url}}home">Home</a></li>
<li><a href="{{base_url}}servers">Servers</a></li>
<li><a href="{{base_url}}token">Token</a></li>
{% if user.admin %}
<li><a href="{{base_url}}admin">Admin</a></li>
<li><a href="{{base_url}}environments">Environments</a></li>
<li><a href="{{base_url}}environments-old">Environments Old</a></li>
<!-- <li><a href="{{base_url}}environments-old">Environments Old</a></li> -->
{% if services %}
{% for service in services %}
<li><a href="{{service.prefix}}" style="text-transform: capitalize;">{{service.name}}</a></li>
Expand Down
13 changes: 13 additions & 0 deletions tljh_repo2docker/templates/servers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "page.html" %} {% block main %}
<div id="servers-root">
<script id="tljh-page-data" type="application/json">
{
"images": {{ images | tojson }},
"allow_named_servers": {{allow_named_servers}},
"named_server_limit_per_user": {{named_server_limit_per_user}},
"spawners": {{spawners}},
"default_server": {{default_server}}
}
</script>
</div>
{% endblock %}

0 comments on commit ce7abe6

Please sign in to comment.