Mercurial > libervia-web
changeset 1618:5d9889f14012 default tip @
server: start major redesign
- Add icons to menu items
- Switch menu items representation from tuple to dictionary for future extensibility:
- Include icon information
- Prepare for additional data
- Remove "login" from main menu, add login page URL to template data, as it is now a separate right-aligned item
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 23:07:01 +0200 |
parents | e338426ed4de |
children | |
files | libervia/web/server/constants.py libervia/web/server/pages.py libervia/web/server/resources.py libervia/web/server/server.py |
diffstat | 4 files changed, 45 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/web/server/constants.py Wed Aug 07 00:02:40 2024 +0200 +++ b/libervia/web/server/constants.py Sat Oct 26 23:07:01 2024 +0200 @@ -101,6 +101,19 @@ # probably). ] + DEFAULT_ICONS = { + "chat": "comments", + "blog": "blog", + "forums": "message", + "photos": "images", + "files": "file-lines", + "calendar": "calendar", + "events": "calendar-check", + "lists": "rectangle-list", + "merge-requests": "code-pull-request", + "calls": "video", + } + ## Session flags ## FLAG_CONFIRM = "CONFIRM"
--- a/libervia/web/server/pages.py Wed Aug 07 00:02:40 2024 +0200 +++ b/libervia/web/server/pages.py Sat Oct 26 23:07:01 2024 +0200 @@ -267,6 +267,10 @@ return self.vhost_root.main_menu @property + def login_url(self): + return self.vhost_root.login_url + + @property def default_theme(self): return self.vhost_root.default_theme @@ -1421,7 +1425,7 @@ uri = request.uri.decode() try: template_data["current_page"] = next( - m[0] for m in self.main_menu if uri.startswith(m[1]) + m["name"] for m in self.main_menu if uri.startswith(m["url"]) ) except StopIteration: pass @@ -1687,7 +1691,8 @@ "csrf_token": "" if profile is None else session_data.csrf_token, "session_uuid": "public" if profile is None else session_data.uuid, "breadcrumbs": [], - "tz_name": time.tzname[0] + "tz_name": time.tzname[0], + "login_url": self.login_url } # XXX: here is the code which need to be executed once
--- a/libervia/web/server/resources.py Wed Aug 07 00:02:40 2024 +0200 +++ b/libervia/web/server/resources.py Sat Oct 26 23:07:01 2024 +0200 @@ -123,6 +123,7 @@ self.pages_redirects = {} self.cached_urls = {} self.main_menu = None + self.login_url = None # map Libervia application names => data self.libervia_apps = {} self.build_path = host.get_build_path(site_name) @@ -536,7 +537,17 @@ "menu_json in configuration.").format(msg=e.args[0]) log.error(log_msg) raise exceptions.ConfigError(log_msg) - main_menu.append((page_name, url)) + + if page_name == "login": + self.login_url = url + continue + icon = C.DEFAULT_ICONS.get(page_name, "") + + main_menu.append({ + "name": page_name, + "url": url, + "icon": icon + }) self.main_menu = main_menu def _normalize_url(self, url, lower=True):
--- a/libervia/web/server/server.py Wed Aug 07 00:02:40 2024 +0200 +++ b/libervia/web/server/server.py Sat Oct 26 23:07:01 2024 +0200 @@ -305,15 +305,17 @@ '/', C.TPL_RESOURCE, template_data.site or C.SITE_NAME_DEFAULT, C.TEMPLATE_TPL_DIR, template_data.theme, relative_url) - def _move_first_level_to_dict(self, options, key, keys_to_keep): - """Read a config option and put value at first level into u'' dict + def _move_first_level_to_dict( + self, options: dict, key: str, keys_to_keep: list[str] + ) -> None: + """Read a config option and put value at first level into '' dict This is useful to put values for Libervia official site directly in dictionary, and to use site_name as keys when external sites are used. options will be modified in place - @param options(dict): options to modify - @param key(unicode): setting key to modify - @param keys_to_keep(list(unicode)): keys allowed in first level + @param options: Dictionary of options to modify in place. + @param key: The key in the options dictionary to process. + @param keys_to_keep: List of keys that are allowed to remain at the first level. """ try: conf = options[key] @@ -476,7 +478,12 @@ if not '' in menu: menu[''] = C.DEFAULT_MENU for site, value in self.options["menu_extra_json"].items(): - menu[site].extend(value) + try: + menu[site].extend(value) + except KeyError: + log.warning( + "Configuration error: the key {site!r} is missing from \"menu_json\"." + ) # service profile if not self.options['build-only']: