From 5a2b8f7ff9f54c18cc9fa0204400d9891dad9d13 Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Sun, 22 Jan 2023 19:16:33 +0100 Subject: [PATCH] Improve navbar --- includes/sys_menu.php | 49 ++--------- includes/sys_template.php | 49 +++-------- includes/view/ShiftsFilterRenderer.php | 2 +- includes/view/UserHintsRenderer.php | 61 ++++++------- resources/assets/js/forms.js | 7 ++ resources/assets/themes/base.scss | 1 + resources/assets/themes/colored-links.scss | 13 +++ resources/views/layouts/parts/navbar.twig | 85 +++++++++++++------ src/Renderer/Twig/Extensions/Legacy.php | 2 +- .../Renderer/Twig/Extensions/LegacyTest.php | 2 +- 10 files changed, 129 insertions(+), 142 deletions(-) create mode 100644 resources/assets/themes/colored-links.scss diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 135179f9..7dcb3c91 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -23,9 +23,9 @@ function header_render_hints() { $user = auth()->user(); - $hints_renderer = new UserHintsRenderer(); - if ($user) { + $hints_renderer = new UserHintsRenderer(); + $hints_renderer->addHint(admin_new_questions()); $hints_renderer->addHint(user_angeltypes_unconfirmed_hint()); $hints_renderer->addHint(render_user_departure_date_hint()); @@ -36,9 +36,11 @@ function header_render_hints() $hints_renderer->addHint(render_user_arrived_hint(), true); $hints_renderer->addHint(render_user_tshirt_hint(), true); $hints_renderer->addHint(render_user_dect_hint(), true); + + return $hints_renderer->render(); } - return $hints_renderer->render(); + return ''; } /** @@ -51,39 +53,6 @@ function current_page() return request()->query->get('p') ?: str_replace('-', '_', request()->path()); } -/** - * @return array - */ -function make_user_submenu() -{ - $page = current_page(); - $user_submenu = make_language_select(); - - if (auth()->can('user_settings') || auth()->can('logout')) { - $user_submenu[] = toolbar_dropdown_item_divider(); - } - - if (auth()->can('user_settings')) { - $user_submenu[] = toolbar_dropdown_item( - page_link_to('settings/profile'), - __('Settings'), - $page == 'settings/profile', - 'person-fill-gear' - ); - } - - if (auth()->can('logout')) { - $user_submenu[] = toolbar_dropdown_item( - page_link_to('logout'), - __('Logout'), - $page == 'logout', - 'box-arrow-left', - ); - } - - return $user_submenu; -} - /** * @return string */ @@ -146,10 +115,10 @@ function make_navigation() } if (count($admin_menu) > 0) { - $menu[] = toolbar_dropdown('', __('Admin'), $admin_menu); + $menu[] = toolbar_dropdown(__('Admin'), $admin_menu); } - return ''; + return join("\n", $menu); } /** @@ -195,7 +164,7 @@ function make_room_navigation($menu) $room_menu[] = toolbar_dropdown_item(room_link($room), $room->name, false, 'pin-map-fill'); } if (count($room_menu) > 0) { - $menu[] = toolbar_dropdown('map-marker', __('Rooms'), $room_menu); + $menu[] = toolbar_dropdown(__('Rooms'), $room_menu); } return $menu; } @@ -212,7 +181,7 @@ function make_language_select() $items = []; foreach (config('locales') as $locale => $name) { - $url = url($request->getPathInfo(), ['set-locale' => $locale]); + $url = url($request->getPathInfo(), [...$request->getQueryParams(), 'set-locale' => $locale]); $items[] = toolbar_dropdown_item( htmlspecialchars($url), diff --git a/includes/sys_template.php b/includes/sys_template.php index b5979913..49915baf 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -186,7 +186,7 @@ function toolbar_pills($items) function toolbar_item_link($href, $icon, $label, $active = false) { return '
  • {icon} {label}
  • ', + '
  • {icon} {label}
  • ', [ '{href}' => $href, '{icon}' => $icon === null ? '' : '', '{label}' => $label, - '{active}' => $active ? ' active' : '' + '{active}' => $active ? ' active' : '', + '{aria}' => $active ? ' aria-current="page"' : '' ] ); } @@ -212,20 +213,19 @@ function toolbar_dropdown_item_divider(): string } /** - * @param string $icon * @param string $label * @param array $submenu - * @param string $class + * @param bool $active * @return string */ -function toolbar_dropdown($icon, $label, $submenu, $class = ''): string +function toolbar_dropdown($label, $submenu, $active = false): string { $template = << - -