forked from TillRepo/IrSender
ui grouping
This commit is contained in:
+150
-5
@@ -493,6 +493,7 @@ class ApiHandler(
|
|||||||
).path
|
).path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if path == "/":
|
if path == "/":
|
||||||
|
|
||||||
self.send_html(
|
self.send_html(
|
||||||
@@ -504,6 +505,23 @@ class ApiHandler(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
group_match = re.fullmatch(
|
||||||
|
r"/group/([a-zA-Z0-9_-]+)",
|
||||||
|
path
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if group_match:
|
||||||
|
|
||||||
|
self.send_html(
|
||||||
|
200,
|
||||||
|
render_group(
|
||||||
|
group_match.group(1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
if path == "/health":
|
if path == "/health":
|
||||||
|
|
||||||
self.send_json(
|
self.send_json(
|
||||||
@@ -1386,11 +1404,14 @@ def render_index():
|
|||||||
|
|
||||||
|
|
||||||
sections.append(
|
sections.append(
|
||||||
f"""
|
f"""
|
||||||
|
|
||||||
|
<a class="group-link"
|
||||||
|
href="/group/{html.escape(group_name)}">
|
||||||
|
|
||||||
|
|
||||||
<div class="group-card">
|
<div class="group-card">
|
||||||
|
|
||||||
|
|
||||||
<div class="group-title">
|
<div class="group-title">
|
||||||
|
|
||||||
{html.escape(group_name)}
|
{html.escape(group_name)}
|
||||||
@@ -1398,17 +1419,20 @@ def render_index():
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="button-grid">
|
<div class="group-count">
|
||||||
|
|
||||||
{"".join(buttons)}
|
{len(commands)} Befehle
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1431,6 +1455,96 @@ Keine Befehle verfügbar.
|
|||||||
"\n".join(sections)
|
"\n".join(sections)
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def render_group(group_name):
|
||||||
|
|
||||||
|
buttons = []
|
||||||
|
|
||||||
|
|
||||||
|
for command_id, command in CONFIG["commands"].items():
|
||||||
|
|
||||||
|
|
||||||
|
if not command.get(
|
||||||
|
"web_enabled",
|
||||||
|
False
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
title = command.get(
|
||||||
|
"web_title",
|
||||||
|
command_id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
current_group = title.split(
|
||||||
|
" ",
|
||||||
|
1
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
if current_group != group_name:
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
buttons.append(
|
||||||
|
f"""
|
||||||
|
<form method="post"
|
||||||
|
action="/web/run/{command_id}">
|
||||||
|
|
||||||
|
|
||||||
|
<input type="hidden"
|
||||||
|
name="csrf"
|
||||||
|
value="{WEB_CSRF_TOKEN}">
|
||||||
|
|
||||||
|
|
||||||
|
<button class="action-button"
|
||||||
|
type="submit">
|
||||||
|
|
||||||
|
{html.escape(title)}
|
||||||
|
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if not buttons:
|
||||||
|
|
||||||
|
return render_page(
|
||||||
|
"Fehler",
|
||||||
|
"<div class='empty'>Gruppe nicht gefunden.</div>"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
return render_page(
|
||||||
|
|
||||||
|
group_name,
|
||||||
|
|
||||||
|
f"""
|
||||||
|
|
||||||
|
<a class="back"
|
||||||
|
href="/">
|
||||||
|
|
||||||
|
← Gruppen
|
||||||
|
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="button-grid">
|
||||||
|
|
||||||
|
{"".join(buttons)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
)
|
||||||
def render_page(
|
def render_page(
|
||||||
title,
|
title,
|
||||||
body
|
body
|
||||||
@@ -1556,6 +1670,37 @@ h1 {{
|
|||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
.group-link {{
|
||||||
|
|
||||||
|
text-decoration:
|
||||||
|
none;
|
||||||
|
|
||||||
|
color:
|
||||||
|
inherit;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.group-card:hover {{
|
||||||
|
|
||||||
|
background:
|
||||||
|
var(--card-hover);
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.group-count {{
|
||||||
|
|
||||||
|
color:
|
||||||
|
var(--secondary);
|
||||||
|
|
||||||
|
margin-top:
|
||||||
|
8px;
|
||||||
|
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.card {{
|
.card {{
|
||||||
|
|||||||
Reference in New Issue
Block a user