Verified Commit 0dacd2df authored by Štěpán Henek's avatar Štěpán Henek 🌩

WIP: submenus

parent 3cd5901e
......@@ -22,8 +22,7 @@ import logging
import time
import uuid
from bottle import Bottle, request, template, response, jinja2_template
from urllib.parse import urlencode
from bottle import Bottle, request, template, response
import bottle
from foris import fapi
......@@ -50,6 +49,8 @@ class ConfigPageMixin(object):
template = "config/main"
template_type = "simple"
subpages: typing.Iterable[typing.Type['ConfigPageMixin']] = []
def call_action(self, action):
"""Call config page action.
......@@ -432,6 +433,12 @@ class RemoteConfigPage(ConfigPageMixin, remote.RemoteHandler):
return ConfigPageMixin.is_enabled_static(cls)
class SubordinatesWifiConfigPage(ConfigPageMixin, subordinates.SubordinatesWifiHandler):
slug = "suboridnates-wifi"
menu_order = 1 # submenu
template = "config/subordinates"
class SubordinatesConfigPage(ConfigPageMixin, subordinates.SubordinatesConfigHandler):
slug = "subordinates"
menu_order = 12
......@@ -440,6 +447,10 @@ class SubordinatesConfigPage(ConfigPageMixin, subordinates.SubordinatesConfigHan
userfriendly_title = gettext("Managed devices")
template_type = "jinja2"
subpages = [
SubordinatesWifiConfigPage
]
def render(self, **kwargs):
data = current_state.backend.perform("subordinates", "list")
......@@ -1088,6 +1099,10 @@ def get_config_pages():
""" Returns sorted config pages
"""
res = sorted(config_pages.values(), key=lambda e: (e.menu_order, e.slug))
# sort subpages
for page in res:
page.subpages.sort(key=lambda e: (e.menu_order, e.slug))
return res
......
......@@ -22,10 +22,12 @@ from foris import fapi
from foris.form import File, Hidden, Textbox
from foris.state import current_state
from foris.utils.translators import (
gettext_dummy as gettext,
gettext as _,
)
from .base import BaseConfigHandler
from .wifi import WifiEditForm
class SubordinatesConfigHandler(BaseConfigHandler):
......@@ -189,3 +191,11 @@ class SubsubordinatesEditForm(fapi.ForisAjaxForm):
sub_form.add_callback(form_cb)
return sub_form
class SubordinatesWifiHandler(BaseConfigHandler):
userfriendly_title = gettext("Wi-Fi")
def get_form(self):
ajax_form = WifiEditForm(self.data)
return ajax_form.foris_form
......@@ -182,3 +182,7 @@ $nav-item-border: 2px solid #ddd
float: right
width: 50%
border-left: $nav-item-border
#menu .submenu-item
padding-left: 1.5em
background-color: lighten(desaturate($sidebar-background-color, 20), 5)
......@@ -74,6 +74,21 @@
{% endif %}
</a>
</li>
{% for subpage in config_page.subpages %}
{% if subpage.is_visible() and subpage.is_enabled() %}
<li class="{{ "active" if active_config_page_key is defined and subpage.slug == active_config_page_key else "" }} submenu-item">
<a href="{{ url("config_page", page_name=subpage.slug) }}"><i class="fas fa-level-up-alt rotate-90"></i> {{ subpage.userfriendly_title }}
{% if subpage.get_menu_tag()["show"] %}
<span title="{{ subpage.get_menu_tag()["hint"]}}" style="{{"" if subpage.get_menu_tag()["show"] else "display: none" }}" id="{{ subpage.slug }}_menu_tag" class="menu-tag">
{{ subpage.get_menu_tag()["text"]|safe }}
</span>
{% endif %}
</a>
{% elif subpage.is_visible() %}
<li><span class="link-disabled">{{ subpage.userfriendly_title }}</span></li>
{% endif %}
</li>
{% endfor %}
{% elif config_page.is_visible() %}
<li><span class="link-disabled">{{ config_page.userfriendly_title }}</span></li>
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment