Skip to content

Commit 10dafbd

Browse files
author
Andrei Neagu
committed
refactor page rendering
1 parent d65d155 commit 10dafbd

File tree

1 file changed

+55
-47
lines changed
  • services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/frontend/routes

1 file changed

+55
-47
lines changed

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/frontend/routes/_service.py

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,60 @@
2020
router = APIRouter()
2121

2222

23+
def _render_remove_from_tracking(node_id):
24+
with ui.dialog() as confirm_dialog, ui.card():
25+
26+
async def remove_from_tracking():
27+
confirm_dialog.close()
28+
await httpx.AsyncClient(timeout=10).get(
29+
f"http://localhost:{DEFAULT_FASTAPI_PORT}/service/{node_id}/tracker:remove"
30+
)
31+
32+
ui.notify(f"Service {node_id} removed from tracking")
33+
ui.navigate.to("/")
34+
35+
ui.markdown(f"Remove the service **{node_id}** form the tracker?")
36+
ui.label(
37+
"This action will result in the removal of the service form the internal tracker. "
38+
"This action should be used whn you are facing issues and the service is not "
39+
"automatically removed."
40+
)
41+
ui.label(
42+
"NOTE 1: the system normally cleans up services but it might take a few minutes. "
43+
"Only use this option when you have observed enough time passing without any change."
44+
).classes("text-red-600")
45+
ui.label(
46+
"NOTE 2: This will break the fronted for the user! If the user has the service opened, "
47+
"it will no longer receive an status updates."
48+
).classes("text-red-600")
49+
50+
with ui.row():
51+
ui.button("Remove service", color="red", on_click=remove_from_tracking)
52+
ui.button("Cancel", on_click=confirm_dialog.close)
53+
54+
ui.button(
55+
"Remove from tracking",
56+
icon="remove_circle",
57+
color="red",
58+
on_click=confirm_dialog.open,
59+
).tooltip("Removes the service form the dynamic-scheduler's internal tracking")
60+
61+
62+
def _render_danger_zone(node_id: NodeID) -> None:
63+
ui.separator()
64+
65+
ui.markdown("**Danger Zone, beware!**").classes("text-2xl text-red-700")
66+
ui.label(
67+
"Do not use these actions if you do not know what they are doing."
68+
).classes("text-red-700")
69+
70+
ui.label(
71+
"They are reserved as means of recovering the system form a failing state."
72+
).classes("text-red-700")
73+
74+
_render_remove_from_tracking(node_id)
75+
76+
2377
@router.page("/service/{node_id}:details")
2478
async def service_details(node_id: NodeID):
2579
with base_page(title=f"{node_id} details"):
@@ -50,53 +104,7 @@ async def service_details(node_id: NodeID):
50104
ui.markdown("**Raw serialized data (the one used to render the above**")
51105
ui.code(service_model.model_dump_json(indent=2), language="json")
52106

53-
ui.separator()
54-
55-
ui.markdown("**Danger Zone, beware!**").classes("text-2xl text-red-700")
56-
ui.label(
57-
"Do not use these actions if you do not know what they are doing."
58-
).classes("text-red-700")
59-
60-
ui.label(
61-
"They are reserved as means of recovering the system form a failing state."
62-
).classes("text-red-700")
63-
64-
with ui.dialog() as confirm_dialog, ui.card():
65-
66-
async def remove_from_tracking():
67-
confirm_dialog.close()
68-
await httpx.AsyncClient(timeout=10).get(
69-
f"http://localhost:{DEFAULT_FASTAPI_PORT}/service/{node_id}/tracker:remove"
70-
)
71-
72-
ui.notify(f"Service {node_id} removed from tracking")
73-
ui.navigate.to("/")
74-
75-
ui.markdown(f"Remove the service **{node_id}** form the tracker?")
76-
ui.label(
77-
"This action will result in the removal of the service form the internal tracker. "
78-
"This action should be used whn you are facing issues and the service is not "
79-
"automatically removed."
80-
)
81-
ui.label(
82-
"NOTE 1: the system normally cleans up services but it might take a few minutes. "
83-
"Only use this option when you have observed enough time passing without any change."
84-
).classes("text-red-600")
85-
ui.label(
86-
"NOTE 2: This will break the fronted for the user! If the user has the service opened, "
87-
"it will no longer receive an status updates."
88-
).classes("text-red-600")
89-
90-
with ui.row():
91-
ui.button("Remove service", color="red", on_click=remove_from_tracking)
92-
ui.button("Cancel", on_click=confirm_dialog.close)
93-
94-
ui.button(
95-
"Remove from tracking",
96-
icon="remove_circle",
97-
color="red",
98-
on_click=confirm_dialog.open,
99-
).tooltip("Removes the service form the dynamic-scheduler's internal tracking")
107+
_render_danger_zone(node_id)
100108

101109

102110
@router.page("/service/{node_id}:stop")

0 commit comments

Comments
 (0)