Moved robot container listing to own tab and method for better composability
This commit is contained in:
parent
e42b5f1740
commit
b8a353b9af
|
@ -66,22 +66,10 @@ class Robot:
|
||||||
self.processes = []
|
self.processes = []
|
||||||
robots.add(self)
|
robots.add(self)
|
||||||
|
|
||||||
async def ui(self, element):
|
async def ui_containers(self, element):
|
||||||
adocker = aiodocker.Docker()
|
|
||||||
with element:
|
|
||||||
robot_ui = ui.element().classes("w-full outline p-4")
|
|
||||||
with robot_ui:
|
|
||||||
ui.label(f"{self.robot_type}")
|
|
||||||
ui.label(f"""Sysid: {self.sysid}""")
|
|
||||||
ui.button("Start", on_click=self.start).classes("m-2")
|
|
||||||
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
|
||||||
async def delete_robot():
|
|
||||||
await self.async_stop()
|
|
||||||
robots.remove(self)
|
|
||||||
element.remove(robot_ui)
|
|
||||||
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
|
||||||
docker_elements = {}
|
docker_elements = {}
|
||||||
container_status = {}
|
container_status = {}
|
||||||
|
with element:
|
||||||
while True:
|
while True:
|
||||||
#Poll for data that changes
|
#Poll for data that changes
|
||||||
for container in self.containers():
|
for container in self.containers():
|
||||||
|
@ -92,7 +80,7 @@ class Robot:
|
||||||
|
|
||||||
container_status[container] = f"{container.name} {container.status} {health}"
|
container_status[container] = f"{container.name} {container.status} {health}"
|
||||||
if container not in docker_elements:
|
if container not in docker_elements:
|
||||||
docker_elements[container] = ui.element()
|
docker_elements[container] = ui.element().classes("w-full")
|
||||||
with docker_elements[container]:
|
with docker_elements[container]:
|
||||||
ui.label().bind_text(container_status, container)
|
ui.label().bind_text(container_status, container)
|
||||||
logelement = ui.expansion("Logs").style('margin: 10px;').classes('w-full')
|
logelement = ui.expansion("Logs").style('margin: 10px;').classes('w-full')
|
||||||
|
@ -100,10 +88,31 @@ class Robot:
|
||||||
#Check for containers that have been removed
|
#Check for containers that have been removed
|
||||||
removed = set(docker_elements.keys()) - set(self.containers())
|
removed = set(docker_elements.keys()) - set(self.containers())
|
||||||
for container in removed:
|
for container in removed:
|
||||||
robot_ui.remove(docker_elements[container])
|
self.robot_ui.remove(docker_elements[container])
|
||||||
docker_elements.pop(container)
|
docker_elements.pop(container)
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
async def ui(self, element):
|
||||||
|
adocker = aiodocker.Docker()
|
||||||
|
|
||||||
|
with element:
|
||||||
|
self.robot_ui = ui.element().classes("w-full outline p-4")
|
||||||
|
with self.robot_ui:
|
||||||
|
ui.label(f"{self.robot_type}")
|
||||||
|
ui.label(f"""Sysid: {self.sysid}""")
|
||||||
|
ui.button("Start", on_click=self.start).classes("m-2")
|
||||||
|
ui.button("Stop", on_click=self.async_stop).classes("m-2")
|
||||||
|
async def delete_robot():
|
||||||
|
await self.async_stop()
|
||||||
|
robots.remove(self)
|
||||||
|
element.remove(robot_ui)
|
||||||
|
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
||||||
|
with ui.tabs() as tabs:
|
||||||
|
tab_containers = ui.tab('Containers')
|
||||||
|
with ui.tab_panels(tabs, value=tab_containers):
|
||||||
|
tab = ui.tab_panel(tab_containers).classes("w-full")
|
||||||
|
asyncio.create_task(self.ui_containers(tab))
|
||||||
|
|
||||||
async def async_stop(self):
|
async def async_stop(self):
|
||||||
return await run.io_bound(self.stop)
|
return await run.io_bound(self.stop)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue