forked from TillRepo/IrSender
implement grouping to the web ui
This commit is contained in:
+144
-40
@@ -1301,7 +1301,8 @@ def timeout_result(
|
|||||||
|
|
||||||
def render_index():
|
def render_index():
|
||||||
|
|
||||||
cards = []
|
groups = {}
|
||||||
|
|
||||||
|
|
||||||
for command_id, command in CONFIG["commands"].items():
|
for command_id, command in CONFIG["commands"].items():
|
||||||
|
|
||||||
@@ -1312,60 +1313,108 @@ def render_index():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
title = html.escape(
|
title = command.get(
|
||||||
command.get(
|
"web_title",
|
||||||
"web_title",
|
command_id
|
||||||
command_id
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
description = html.escape(
|
description = command.get(
|
||||||
command.get(
|
"description",
|
||||||
"description",
|
""
|
||||||
""
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
cards.append(
|
# Gruppe anhand des ersten Wortes
|
||||||
f"""
|
group_name = title.split(
|
||||||
<div class="card">
|
" ",
|
||||||
|
1
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
groups.setdefault(
|
||||||
|
group_name,
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
groups[group_name].append(
|
||||||
|
{
|
||||||
|
"id": command_id,
|
||||||
|
"title": title,
|
||||||
|
"description": description
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sections = []
|
||||||
|
|
||||||
|
|
||||||
|
for group_name, commands in sorted(
|
||||||
|
groups.items()
|
||||||
|
):
|
||||||
|
|
||||||
|
|
||||||
|
buttons = []
|
||||||
|
|
||||||
|
|
||||||
|
for cmd in commands:
|
||||||
|
|
||||||
|
|
||||||
|
buttons.append(
|
||||||
|
f"""
|
||||||
<form method="post"
|
<form method="post"
|
||||||
action="/web/run/{command_id}">
|
action="/web/run/{html.escape(cmd["id"])}">
|
||||||
|
|
||||||
|
|
||||||
<input type="hidden"
|
<input type="hidden"
|
||||||
name="csrf"
|
name="csrf"
|
||||||
value="{WEB_CSRF_TOKEN}">
|
value="{WEB_CSRF_TOKEN}">
|
||||||
|
|
||||||
|
|
||||||
<div class="card-title">
|
<button class="action-button"
|
||||||
{title}
|
type="submit">
|
||||||
</div>
|
|
||||||
|
|
||||||
|
{html.escape(cmd["title"])}
|
||||||
|
|
||||||
<div class="card-description">
|
|
||||||
{description}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<button type="submit">
|
|
||||||
▶ Ausführen
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sections.append(
|
||||||
|
f"""
|
||||||
|
|
||||||
|
<div class="group-card">
|
||||||
|
|
||||||
|
|
||||||
|
<div class="group-title">
|
||||||
|
|
||||||
|
{html.escape(group_name)}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="button-grid">
|
||||||
|
|
||||||
|
{"".join(buttons)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if not cards:
|
|
||||||
|
|
||||||
cards.append(
|
if not sections:
|
||||||
|
|
||||||
|
sections.append(
|
||||||
"""
|
"""
|
||||||
<div class="empty">
|
<div class="empty">
|
||||||
Keine Befehle verfügbar.
|
Keine Befehle verfügbar.
|
||||||
@@ -1374,23 +1423,14 @@ Keine Befehle verfügbar.
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return render_page(
|
return render_page(
|
||||||
|
|
||||||
"IR Steuerung",
|
"IR Steuerung",
|
||||||
|
|
||||||
"""
|
"\n".join(sections)
|
||||||
<div class="grid">
|
|
||||||
"""
|
|
||||||
+
|
|
||||||
"\n".join(cards)
|
|
||||||
+
|
|
||||||
"""
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def render_page(
|
def render_page(
|
||||||
title,
|
title,
|
||||||
body
|
body
|
||||||
@@ -1579,6 +1619,70 @@ h1 {{
|
|||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
.group-card {{}
|
||||||
|
|
||||||
|
background:
|
||||||
|
var(--card);
|
||||||
|
|
||||||
|
border-radius:
|
||||||
|
16px;
|
||||||
|
|
||||||
|
padding:
|
||||||
|
20px;
|
||||||
|
|
||||||
|
margin-bottom:
|
||||||
|
25px;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.group-title {{}
|
||||||
|
|
||||||
|
font-size:
|
||||||
|
1.4rem;
|
||||||
|
|
||||||
|
font-weight:
|
||||||
|
700;
|
||||||
|
|
||||||
|
margin-bottom:
|
||||||
|
15px;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.button-grid {{
|
||||||
|
|
||||||
|
display:
|
||||||
|
grid;
|
||||||
|
|
||||||
|
grid-template-columns:
|
||||||
|
repeat(
|
||||||
|
auto-fit,
|
||||||
|
minmax(
|
||||||
|
150px,
|
||||||
|
1fr
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
gap:
|
||||||
|
12px;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.action-button {{
|
||||||
|
|
||||||
|
width:
|
||||||
|
100%;
|
||||||
|
|
||||||
|
margin:
|
||||||
|
0;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
button {{
|
button {{
|
||||||
|
|||||||
Reference in New Issue
Block a user