Moved robot container listing to own tab and method for better composability
This commit is contained in:
parent
e42b5f1740
commit
b8a353b9af
|
@ -66,11 +66,38 @@ class Robot:
|
||||||
self.processes = []
|
self.processes = []
|
||||||
robots.add(self)
|
robots.add(self)
|
||||||
|
|
||||||
|
async def ui_containers(self, element):
|
||||||
|
docker_elements = {}
|
||||||
|
container_status = {}
|
||||||
|
with element:
|
||||||
|
while True:
|
||||||
|
#Poll for data that changes
|
||||||
|
for container in self.containers():
|
||||||
|
try:
|
||||||
|
health = container.attrs['State']['Health']['Status']
|
||||||
|
except KeyError:
|
||||||
|
health = "Unknown"
|
||||||
|
|
||||||
|
container_status[container] = f"{container.name} {container.status} {health}"
|
||||||
|
if container not in docker_elements:
|
||||||
|
docker_elements[container] = ui.element().classes("w-full")
|
||||||
|
with docker_elements[container]:
|
||||||
|
ui.label().bind_text(container_status, container)
|
||||||
|
logelement = ui.expansion("Logs").style('margin: 10px;').classes('w-full')
|
||||||
|
asyncio.create_task(container_logs(container, logelement))
|
||||||
|
#Check for containers that have been removed
|
||||||
|
removed = set(docker_elements.keys()) - set(self.containers())
|
||||||
|
for container in removed:
|
||||||
|
self.robot_ui.remove(docker_elements[container])
|
||||||
|
docker_elements.pop(container)
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
async def ui(self, element):
|
async def ui(self, element):
|
||||||
adocker = aiodocker.Docker()
|
adocker = aiodocker.Docker()
|
||||||
|
|
||||||
with element:
|
with element:
|
||||||
robot_ui = ui.element().classes("w-full outline p-4")
|
self.robot_ui = ui.element().classes("w-full outline p-4")
|
||||||
with robot_ui:
|
with self.robot_ui:
|
||||||
ui.label(f"{self.robot_type}")
|
ui.label(f"{self.robot_type}")
|
||||||
ui.label(f"""Sysid: {self.sysid}""")
|
ui.label(f"""Sysid: {self.sysid}""")
|
||||||
ui.button("Start", on_click=self.start).classes("m-2")
|
ui.button("Start", on_click=self.start).classes("m-2")
|
||||||
|
@ -80,29 +107,11 @@ class Robot:
|
||||||
robots.remove(self)
|
robots.remove(self)
|
||||||
element.remove(robot_ui)
|
element.remove(robot_ui)
|
||||||
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
ui.button("Delete", on_click=delete_robot).classes("m-2")
|
||||||
docker_elements = {}
|
with ui.tabs() as tabs:
|
||||||
container_status = {}
|
tab_containers = ui.tab('Containers')
|
||||||
while True:
|
with ui.tab_panels(tabs, value=tab_containers):
|
||||||
#Poll for data that changes
|
tab = ui.tab_panel(tab_containers).classes("w-full")
|
||||||
for container in self.containers():
|
asyncio.create_task(self.ui_containers(tab))
|
||||||
try:
|
|
||||||
health = container.attrs['State']['Health']['Status']
|
|
||||||
except KeyError:
|
|
||||||
health = "Unknown"
|
|
||||||
|
|
||||||
container_status[container] = f"{container.name} {container.status} {health}"
|
|
||||||
if container not in docker_elements:
|
|
||||||
docker_elements[container] = ui.element()
|
|
||||||
with docker_elements[container]:
|
|
||||||
ui.label().bind_text(container_status, container)
|
|
||||||
logelement = ui.expansion("Logs").style('margin: 10px;').classes('w-full')
|
|
||||||
asyncio.create_task(container_logs(container, logelement))
|
|
||||||
#Check for containers that have been removed
|
|
||||||
removed = set(docker_elements.keys()) - set(self.containers())
|
|
||||||
for container in removed:
|
|
||||||
robot_ui.remove(docker_elements[container])
|
|
||||||
docker_elements.pop(container)
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
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