Sync: [ALAS] List tasks instead of collapsing them in submodules

This commit is contained in:
LmeSzinc 2023-06-17 23:11:57 +08:00
parent b29d6fcc61
commit 1a564b4e8e
11 changed files with 148 additions and 95 deletions

View File

@ -117,6 +117,22 @@ footer {
margin-bottom: .25rem !important;
}
.hr-task-group-box {
display: flex;
align-items: center;
margin-bottom: 0.5rem;
}
.hr-task-group-line {
border-top: 0.125rem solid;
flex-grow: 1;
}
.hr-task-group-text {
margin: 0 0.5rem;
font-size: 0.875rem;
}
input[type="checkbox"] {
width: 1.25rem;
height: 1.25rem;
@ -246,6 +262,7 @@ pre.rich-traceback-code {
#pywebio-scope-menu {
z-index: 90;
padding-left: .5rem;
padding-right: .5rem;
padding-top: 1.2rem;
overflow-y: auto;
width: 12rem;
@ -337,6 +354,10 @@ pre.rich-traceback-code {
overflow-y: auto;
}
#pywebio-scope-groups:not(:has(*)) {
display: none;
}
#pywebio-scope-navigator {
margin: .5rem 1rem .5rem;
height: min-content;

View File

@ -36,6 +36,14 @@
background-color: #40444b !important;
}
.hr-task-group-line {
border-top-color: #adb5bd;
}
.hr-task-group-text {
color: #adb5bd;
}
.form-control,
.bootstrap-select > select {
border-bottom: .125rem solid #7a77bb;

View File

@ -37,6 +37,14 @@
background-color: #eaecef !important;
}
.hr-task-group-line {
border-top-color: #d0d0d0;
}
.hr-task-group-text {
color: #777777;
}
.form-control,
.bootstrap-select > select {
border-bottom: .125rem solid #4e4c97;

View File

@ -1,6 +1,8 @@
{
"Task": {
"Alas": [
"Alas": {
"menu": "list",
"page": "setting",
"tasks": [
"Alas",
"Restart"
]

View File

@ -4,6 +4,10 @@
# ==================== Alas ====================
Alas:
menu: 'list'
page: 'setting'
tasks:
Alas:
- Emulator
- EmulatorInfo

View File

@ -67,8 +67,9 @@ class ConfigGenerator:
@cached_property
def task(self):
"""
<task_group>:
<task>:
- <group>
<group>:
"""
return read_file(filepath_argument('task'))
@ -112,7 +113,10 @@ class ConfigGenerator:
"""
# Construct args
data = {}
for task, groups in self.task.items():
for path, groups in deep_iter(self.task, depth=3):
if 'tasks' not in path:
continue
task = path[2]
# Add storage to all task
groups.append('Storage')
for group in groups:
@ -164,7 +168,10 @@ class ConfigGenerator:
deep_set(data, keys=p + ['value'], value=v)
deep_set(data, keys=p + ['display'], value='hide')
# Set command
for task in self.task.keys():
for path, groups in deep_iter(self.task, depth=3):
if 'tasks' not in path:
continue
task = path[2]
if deep_get(data, keys=f'{task}.Scheduler.Command'):
deep_set(data, keys=f'{task}.Scheduler.Command.value', value=task)
deep_set(data, keys=f'{task}.Scheduler.Command.display', value='hide')
@ -220,12 +227,12 @@ class ConfigGenerator:
deep_set(new, keys=k, value=v)
# Menu
for path, data in deep_iter(self.menu, depth=2):
func, group = path
deep_load(['Menu', func])
deep_load(['Menu', group])
for task in data:
deep_load([func, task])
for path, data in deep_iter(self.task, depth=3):
if 'tasks' not in path:
continue
task_group, _, task = path
deep_load(['Menu', task_group])
deep_load(['Task', task])
# Arguments
visited_group = set()
for path, data in deep_iter(self.argument, depth=2):
@ -273,23 +280,18 @@ class ConfigGenerator:
"""
data = {}
# Task menu
group = ''
tasks = []
with open(filepath_argument('task'), 'r', encoding='utf-8') as f:
for line in f.readlines():
line = line.strip('\n')
if '=====' in line:
if tasks:
deep_set(data, keys=f'Task.{group}', value=tasks)
group = line.strip('#=- ')
tasks = []
if group:
if line.endswith(':'):
tasks.append(line.strip('\n=-#: '))
if tasks:
deep_set(data, keys=f'Task.{group}', value=tasks)
for task_group in self.task.keys():
value = deep_get(self.task, keys=[task_group, 'menu'])
if value not in ['collapse', 'list']:
value = 'collapse'
deep_set(data, keys=[task_group, 'menu'], value=value)
value = deep_get(self.task, keys=[task_group, 'page'])
if value not in ['setting', 'tool']:
value = 'setting'
deep_set(data, keys=[task_group, 'page'], value=value)
tasks = deep_get(self.task, keys=[task_group, 'tasks'], default={})
tasks = list(tasks.keys())
deep_set(data, keys=[task_group, 'tasks'], value=tasks)
return data

View File

@ -1,9 +1,5 @@
{
"Menu": {
"Task": {
"name": "",
"help": ""
},
"Alas": {
"name": "SRC",
"help": ""

View File

@ -1,9 +1,5 @@
{
"Menu": {
"Task": {
"name": "",
"help": ""
},
"Alas": {
"name": "Menu.Alas.name",
"help": "Menu.Alas.help"

View File

@ -1,9 +1,5 @@
{
"Menu": {
"Task": {
"name": "",
"help": ""
},
"Alas": {
"name": "SRC",
"help": ""

View File

@ -1,9 +1,5 @@
{
"Menu": {
"Task": {
"name": "",
"help": ""
},
"Alas": {
"name": "SRC",
"help": ""

View File

@ -167,41 +167,50 @@ class AlasGUI(Frame):
Set menu
"""
put_buttons(
[
{
[{
"label": t("Gui.MenuAlas.Overview"),
"value": "Overview",
"color": "menu",
}
],
}],
onclick=[self.alas_overview],
).style(f"--menu-Overview--"),
).style(f"--menu-Overview--")
for key, tasks in deep_iter(self.ALAS_MENU, depth=2):
# path = '.'.join(key)
menu = key[1]
if menu == "Tool":
for menu, task_data in self.ALAS_MENU.items():
if task_data.get("page") == "tool":
_onclick = self.alas_daemon_overview
else:
_onclick = self.alas_set_group
task_btn_list = []
for task in tasks:
task_btn_list.append(
if task_data.get("menu") == "collapse":
task_btn_list = [
put_buttons(
[
{
[{
"label": t(f"Task.{task}.name"),
"value": task,
"color": "menu",
}
],
}],
onclick=_onclick,
).style(f"--menu-{task}--")
)
for task in task_data.get("tasks", [])
]
put_collapse(title=t(f"Menu.{menu}.name"), content=task_btn_list)
else:
title = t(f"Menu.{menu}.name")
put_html('<div class="hr-task-group-box">'
'<span class="hr-task-group-line"></span>'
f'<span class="hr-task-group-text">{title}</span>'
'<span class="hr-task-group-line"></span>'
'</div>'
)
for task in task_data.get("tasks", []):
put_buttons(
[{
"label": t(f"Task.{task}.name"),
"value": task,
"color": "menu",
}],
onclick=_onclick,
).style(f"--menu-{task}--").style(f"padding-left: 0.75rem")
self.alas_overview()
@ -625,6 +634,21 @@ class AlasGUI(Frame):
continue
self.set_group(group, arg_dict, config, task)
run_js("""
$("#pywebio-scope-log").css(
"grid-row-start",
-2 - $("#pywebio-scope-_daemon").children().filter(
function(){
return $(this).css("display") === "none";
}
).length
);
$("#pywebio-scope-log").css(
"grid-row-end",
-1
);
""")
self.task_handler.add(switch_scheduler.g(), 1, True)
self.task_handler.add(switch_log_scroll.g(), 1, True)
self.task_handler.add(log.put_log(self.alas), 0.25, True)