chore: refactor menu building

This commit is contained in:
Björn Fromme
2024-02-07 11:53:07 +01:00
parent 0b1dd73902
commit 1ab36e6ce5
6 changed files with 349 additions and 323 deletions
+46 -79
View File
@@ -26,51 +26,6 @@ abstract class AbstractMenuBuilder
return $this->factory->createItem('root'); return $this->factory->createItem('root');
} }
protected function createMenu(array $menuItems): ItemInterface
{
$menu = $this->createRootElement();
foreach ($menuItems as $menuItem) {
$addedItem = $this->createMenuItem($menu, $menuItem);
if (isset($menuItem['hideChildren'])&& true === $menuItem['hideChildren']) {
$addedItem->setDisplayChildren(false);
}
if (isset($menuItem['children'])) {
foreach ($menuItem['children'] as $subMenuItem) {
$addedSubItem = $this->createMenuItem($addedItem, $subMenuItem);
if (isset($subMenuItem['children'])) {
$addedSubItem->setDisplayChildren(false);
foreach ($subMenuItem['children'] as $hiddenItem) {
$this->createMenuItem($addedSubItem, $hiddenItem);
}
}
}
}
}
return $menu;
}
protected function createMenuItem(ItemInterface $menu, array $options): ItemInterface
{
$itemOptions = [];
if (false !== $options['route']) {
$itemOptions['route'] = $options['route'];
$itemOptions['linkAttributes'] = ['title' => $options['title']];
}
if (isset($options['routeParameters'])) {
$itemOptions['routeParameters'] = $options['routeParameters'];
}
if (isset($options['icon'])) {
$itemOptions['extras']['icon'] = $options['icon'];
}
return $menu
->addChild($options['title'], $itemOptions)
->setChildrenAttribute('title', $options['title'])
;
}
protected function getDefaultRouteParameters(string $parameter = 'id', string $default = '0'): array protected function getDefaultRouteParameters(string $parameter = 'id', string $default = '0'): array
{ {
return [$parameter => $this->requestStack->getMainRequest()->get($parameter, $default)]; return [$parameter => $this->requestStack->getMainRequest()->get($parameter, $default)];
@@ -80,11 +35,15 @@ abstract class AbstractMenuBuilder
{ {
if ($this->security->isGranted('ROLE_ADMIN')) { if ($this->security->isGranted('ROLE_ADMIN')) {
$this->addDivider($menu); $this->addDivider($menu);
$menu $menu->addChild('zum Adminbereich', [
->addChild('zum Adminbereich', ['route' => 'app_admin_index']) 'route' => 'app_admin_index',
->setChildrenAttribute('title', 'zum Adminbereich') 'linkAttributes' => [
->setExtra('icon', 'user') 'title' => 'zum Adminbereich',
; ],
'extras' => [
'icon' => 'user',
],
]);
} }
} }
@@ -92,11 +51,15 @@ abstract class AbstractMenuBuilder
{ {
if ($this->security->isGranted('ROLE_TEAMER')) { if ($this->security->isGranted('ROLE_TEAMER')) {
$this->addDivider($menu); $this->addDivider($menu);
$menu $menu->addChild('zum Teambereich', [
->addChild('zum Teambereich', ['route' => 'app_teamer_index']) 'route' => 'app_teamer_index',
->setChildrenAttribute('title', 'zum Teambereich') 'linkAttributes' => [
->setExtra('icon', 'user') 'title' => 'zum Teambereich',
; ],
'extras' => [
'icon' => 'user',
],
]);
} }
} }
@@ -104,11 +67,15 @@ abstract class AbstractMenuBuilder
{ {
if ($this->security->isGranted('ROLE_HOUSE_MANAGER')) { if ($this->security->isGranted('ROLE_HOUSE_MANAGER')) {
$this->addDivider($menu); $this->addDivider($menu);
$menu $menu->addChild('zum Hausleitungsbereich', [
->addChild('zum Hausleitungsbereich', ['route' => 'app_house_manager_index']) 'route' => 'app_house_manager_index',
->setChildrenAttribute('title', 'zum Hausleitungsbereich') 'linkAttributes' => [
->setExtra('icon', 'user') 'title' => 'zum Hausleitungsbereich',
; ],
'extras' => [
'icon' => 'user',
],
]);
} }
} }
@@ -121,26 +88,26 @@ abstract class AbstractMenuBuilder
if ($token instanceof SwitchUserToken) { if ($token instanceof SwitchUserToken) {
/** @var User $originalUser */ /** @var User $originalUser */
$originalUser = $token->getOriginalToken()->getUser(); $originalUser = $token->getOriginalToken()->getUser();
$menu $menu->addChild('zum eigenen Benutzer', [
->addChild('Logout', [ 'route' => $originalUser->getDefaultRoute(),
'route' => $originalUser->getDefaultRoute(), 'routeParameters' => ['_switch_user' => '_exit'],
'routeParameters' => ['_switch_user' => '_exit'], 'linkAttributes' => [
'linkAttributes' => [ 'title' => 'zurück',
'title' => 'zurück', ],
], 'extras' => [
]) 'icon' => 'logout',
->setExtra('icon', 'logout') ],
; ]);
} else { } else {
$menu $menu->addChild('Logout', [
->addChild('Logout', [ 'route' => 'app_security_logout',
'route' => 'app_security_logout', 'linkAttributes' => [
'linkAttributes' => [ 'title' => 'Logout',
'title' => 'Logout', ],
], 'extras' => [
]) 'icon' => 'logout',
->setExtra('icon', 'logout') ],
; ]);
} }
} }
+196 -151
View File
@@ -6,158 +6,167 @@ use Knp\Menu\ItemInterface;
class AdminMenuBuilder extends AbstractMenuBuilder class AdminMenuBuilder extends AbstractMenuBuilder
{ {
private function getMainMenuItems(): array
{
return [
[
'route' => 'app_admin_index',
'title' => 'Dashboard',
'icon' => 'chart',
],
[
'route' => 'app_admin_assignment_index',
'title' => 'Einsatzübersicht',
'icon' => 'calendar',
'hideChildren' => true,
'children' => [
[
'route' => 'app_admin_assignment_detail',
'title' => 'Einsatzdetails',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
],
],
[
'route' => 'app_admin_application_index',
'title' => 'Bewerbungsübersicht',
'icon' => 'mail',
],
[
'route' => 'app_admin_document_index',
'title' => 'Dokumentenübersicht',
'icon' => 'document',
],
[
'route' => 'app_admin_teamer_index',
'title' => 'Teamübersicht',
'icon' => 'users',
'hideChildren' => true,
'children' => $this->getTeamerMenuItems(),
],
[
'route' => false,
'title' => 'Einstellungen',
'icon' => 'settings',
'children' => [
[
'route' => 'app_admin_system_availability_index',
'title' => 'Verfügbarkeiten',
],
[
'route' => 'app_admin_system_fee_index',
'title' => 'Honorare',
],
[
'route' => 'app_admin_system_training_index',
'title' => 'Fortbildungen',
],
[
'route' => 'app_admin_system_job_profile_index',
'title' => 'Jobprofile',
'children' => [
[
'route' => 'app_admin_system_job_profile_create',
'title' => 'Jobprofil anlegen',
],
[
'route' => 'app_admin_system_job_profile_edit',
'routeParameters' => $this->getDefaultRouteParameters(),
'title' => 'Jobprofil bearbeiten',
],
],
],
[
'route' => 'app_admin_system_feedback_set_index',
'title' => 'Feedback-Vorlagen',
'children' => [
[
'route' => 'app_admin_system_feedback_set_create',
'title' => 'Feedback-Vorlage anlegen',
],
[
'route' => 'app_admin_system_feedback_set_edit',
'routeParameters' => $this->getDefaultRouteParameters(),
'title' => 'Feedback-Vorlage bearbeiten',
],
],
],
[
'route' => 'app_admin_system_faq_index',
'title' => 'FAQ',
'children' => [
[
'route' => 'app_admin_system_faq_create',
'title' => 'FAQ-Eintrag anlegen',
],
[
'route' => 'app_admin_system_faq_edit',
'routeParameters' => $this->getDefaultRouteParameters(),
'title' => 'FAQ-Eintrag bearbeiten',
],
],
],
[
'route' => 'app_admin_system_document_index',
'title' => 'Dokumente',
],
[
'route' => 'app_admin_system_contact_index',
'title' => 'Ansprechperson',
],
],
],
[
'route' => 'app_admin_log_index',
'title' => 'Logs',
'icon' => 'list',
],
];
}
private function getTeamerMenuItems(): array
{
return [
[
'route' => 'app_admin_teamer_profile',
'title' => 'Stammdaten & Foto',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
[
'route' => 'app_admin_teamer_skills',
'title' => 'Jobprofile & Skills',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
[
'route' => 'app_admin_teamer_availability',
'title' => 'Verfügbarkeit',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
[
'route' => 'app_admin_teamer_crm_selections',
'title' => 'Selektionsmerkmale',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
[
'route' => 'app_admin_teamer_recent_assignments',
'title' => 'Vergangene Einsätze',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
],
];
}
public function createMainMenu(array $options): ItemInterface public function createMainMenu(array $options): ItemInterface
{ {
$menu = $this->createMenu($this->getMainMenuItems()); $menu = $this->createRootElement();
$menu->addChild('Dashboard', [
'route' => 'app_admin_index',
'linkAttributes' => [
'title' => 'Dashboard',
],
'extras' => [
'icon' => 'chart',
],
]);
$menu->addChild('Einsatzübersicht', [
'route' => 'app_admin_assignment_index',
'linkAttributes' => [
'title' => 'Einsatzübersicht',
],
'extras' => [
'icon' => 'calendar',
'routes' => [
['pattern' => '/^app_admin_assignment_/'],
],
],
]);
$menu->addChild('Bewerbungsübersicht', [
'route' => 'app_admin_application_index',
'linkAttributes' => [
'title' => 'Bewerbungsübersicht',
],
'extras' => [
'icon' => 'mail',
],
]);
$menu->addChild('Dokumentenübersicht', [
'route' => 'app_admin_document_index',
'linkAttributes' => [
'title' => 'Dokumentenübersicht',
],
'extras' => [
'icon' => 'document',
],
]);
$menu->addChild('Teamübersicht', [
'route' => 'app_admin_teamer_index',
'linkAttributes' => [
'title' => 'Teamübersicht',
],
'extras' => [
'icon' => 'users',
'routes' => [
['pattern' => '/^app_admin_teamer_/']
],
],
]);
$settingsMenu = $menu->addChild('Einstellungen', [
'linkAttributes' => [
'title' => 'Einstellungen',
],
'extras' => [
'icon' => 'settings',
],
]);
$settingsMenu->addChild('Verfügbarkeiten', [
'route' => 'app_admin_system_availability_index',
'linkAttributes' => [
'title' => 'Verfügbarkeiten',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_availability_/']
],
],
]);
$settingsMenu->addChild('Honorare', [
'route' => 'app_admin_system_fee_index',
'linkAttributes' => [
'title' => 'Honorare',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_fee_/']
],
],
]);
$settingsMenu->addChild('Fortbildungen', [
'route' => 'app_admin_system_training_index',
'linkAttributes' => [
'title' => 'Fortbildungen',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_training_/']
],
],
]);
$settingsMenu->addChild('Jobprofile', [
'route' => 'app_admin_system_job_profile_index',
'linkAttributes' => [
'title' => 'Jobprofile',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_job_profile_/']
],
],
]);
$settingsMenu->addChild('Feedbackvorlagen', [
'route' => 'app_admin_system_feedback_set_index',
'linkAttributes' => [
'title' => 'Feedbackvorlagen',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_feedback_set_/']
],
],
]);
$settingsMenu->addChild('FAQ', [
'route' => 'app_admin_system_faq_index',
'linkAttributes' => [
'title' => 'FAQ',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_faq_/']
],
],
]);
$settingsMenu->addChild('Dokumente', [
'route' => 'app_admin_system_document_index',
'linkAttributes' => [
'title' => 'Dokumente',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_document_/']
],
],
]);
$settingsMenu->addChild('Ansprechpersonen', [
'route' => 'app_admin_system_contact_index',
'linkAttributes' => [
'title' => 'Ansprechpersonen',
],
'extras' => [
'routes' => [
['pattern' => '/^app_admin_system_contact_/']
],
],
]);
$menu->addChild('Logs', [
'route' => 'app_admin_log_index',
'linkAttributes' => [
'title' => 'Logs',
],
'extras' => [
'icon' => 'list',
],
]);
$this->addTeamerItem($menu); $this->addTeamerItem($menu);
$this->addHouseManagerItem($menu); $this->addHouseManagerItem($menu);
@@ -168,7 +177,43 @@ class AdminMenuBuilder extends AbstractMenuBuilder
public function createTeamerMenu(array $options): ItemInterface public function createTeamerMenu(array $options): ItemInterface
{ {
$menu = $this->createMenu($this->getTeamerMenuItems()); $menu = $this->createRootElement();
$menu->addChild('Stammdaten & Foto', [
'route' => 'app_admin_teamer_profile',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
'linkAttributes' => [
'title' => 'Stammdaten & Foto',
],
]);
$menu->addChild('Jobprofile & Skills', [
'route' => 'app_admin_teamer_skills',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
'linkAttributes' => [
'title' => 'Jobprofile & Skills',
],
]);
$menu->addChild('Verfügbarkeit', [
'route' => 'app_admin_teamer_availability',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
'linkAttributes' => [
'title' => 'Verfügbarkeit',
],
]);
$menu->addChild('Selektionsmerkmale', [
'route' => 'app_admin_teamer_crm_selections',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
'linkAttributes' => [
'title' => 'Selektionsmerkmale',
],
]);
$menu->addChild('Vergangene Einsätze', [
'route' => 'app_admin_teamer_recent_assignments',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
'linkAttributes' => [
'title' => 'Vergangene Einsätze',
],
]);
$this->addDivider($menu); $this->addDivider($menu);
+16 -15
View File
@@ -8,28 +8,29 @@ class HouseManagerMenuBuilder extends AbstractMenuBuilder
{ {
public function createMainMenu(array $options): ItemInterface public function createMainMenu(array $options): ItemInterface
{ {
$menuItems = [ $menu = $this->createRootElement();
[
'route' => 'app_house_manager_index', $menu->addChild('Dashboard', [
'route' => 'app_house_manager_index',
'linkAttributes' => [
'title' => 'Dashboard', 'title' => 'Dashboard',
],
'extras' => [
'icon' => 'chart', 'icon' => 'chart',
], ],
[ ]);
'route' => 'app_house_manager_feedback_index', $menu->addChild('Feedback', [
'route' => 'app_house_manager_feedback_index',
'linkAttributes' => [
'title' => 'Feedback', 'title' => 'Feedback',
],
'extras' => [
'icon' => 'feedback', 'icon' => 'feedback',
'hideChildren' => true, 'routes' => [
'children' => [ ['pattern' => '/^app_house_manager_feedback_/'],
[
'route' => 'app_house_manager_feedback_provide',
'title' => 'Feedback abgeben',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
]
], ],
], ],
]; ]);
$menu = $this->createMenu($menuItems);
$this->addAdminItem($menu); $this->addAdminItem($menu);
$this->addTeamerItem($menu); $this->addTeamerItem($menu);
+89 -76
View File
@@ -8,97 +8,110 @@ class TeamerMenuBuilder extends AbstractMenuBuilder
{ {
public function createMainMenu(array $options): ItemInterface public function createMainMenu(array $options): ItemInterface
{ {
$menuItems = [ $menu = $this->createRootElement();
[
'route' => 'app_teamer_index', $menu->addChild('Dashboard', [
'route' => 'app_teamer_index',
'linkAttributes' => [
'title' => 'Dashboard', 'title' => 'Dashboard',
],
'extras' => [
'icon' => 'chart', 'icon' => 'chart',
], ],
[ ]);
'route' => 'app_teamer_assignment_index', $menu->addChild('Einsatzübersicht', [
'route' => 'app_teamer_assignment_index',
'linkAttributes' => [
'title' => 'Einsatzübersicht', 'title' => 'Einsatzübersicht',
],
'extras' => [
'icon' => 'calendar', 'icon' => 'calendar',
'hideChildren' => true, 'routes' => [
'children' => [ ['pattern' => '/^app_teamer_assignment_/']
[
'route' => 'app_teamer_assignment_detail',
'title' => 'Einsatzdetails',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
]
], ],
], ],
[ ]);
'route' => false, $profileMenu = $menu->addChild('Mein Profil', [
'title' => 'Mein Profil', 'extras' => [
'icon' => 'profile', 'icon' => 'profile',
'children' => [
[
'route' => 'app_teamer_profile_index',
'title' => 'Stammdaten und Foto',
],
[
'route' => 'app_teamer_profile_skills',
'title' => 'Jobprofile & Skills',
],
[
'route' => 'app_teamer_profile_availability_index',
'title' => 'Meine Verfügbarkeit',
],
],
], ],
[ ]);
'route' => false, $profileMenu->addChild('Stammdaten & Foto', [
'title' => 'Meine Einsätze', 'route' => 'app_teamer_profile_index',
'linkAttributes' => [
'title' => 'Stammdaten & Foto',
],
]);
$profileMenu->addChild('Jobprofile & Skills', [
'route' => 'app_teamer_profile_skills',
'linkAttributes' => [
'title' => 'Jobprofile & Skills',
],
]);
$profileMenu->addChild('Meine Verfügbarkeit', [
'route' => 'app_teamer_profile_availability_index',
'linkAttributes' => [
'title' => 'Meine Verfügbarkeit',
],
]);
$dispositionMenu = $menu->addChild('Meine Einsätze', [
'extras' => [
'icon' => 'bus', 'icon' => 'bus',
'children' => [#
[
'route' => 'app_teamer_bookmark_index',
'title' => 'Merkliste',
'children' => [
[
'route' => 'app_teamer_assignment_detail',
'title' => 'Einsatzdetails',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
]
],
],
[
'route' => 'app_teamer_application_index',
'title' => 'Offene Bewerbungen',
],
[
'route' => 'app_teamer_disposition_upcoming',
'title' => 'Nächste Einsätze',
],
[
'route' => 'app_teamer_disposition_recent',
'title' => 'Letzte Einsätze',
],
],
], ],
[ ]);
'route' => 'app_teamer_document', $dispositionMenu->addChild('Merkliste', [
'route' => 'app_teamer_bookmark_index',
'linkAttributes' => [
'title' => 'Merkliste',
],
]);
$dispositionMenu->addChild('Offene Bewerbungen', [
'route' => 'app_teamer_application_index',
'linkAttributes' => [
'title' => 'Offene Bewerbungen',
],
]);
$dispositionMenu->addChild('Nächste Einsätze', [
'route' => 'app_teamer_disposition_upcoming',
'linkAttributes' => [
'title' => 'Nächste Einsätze',
],
]);
$dispositionMenu->addChild('Letze Einsätze', [
'route' => 'app_teamer_disposition_recent',
'linkAttributes' => [
'title' => 'Letze Einsätze',
],
]);
$menu->addChild('Dokumente', [
'route' => 'app_teamer_document',
'linkAttributes' => [
'title' => 'Dokumente', 'title' => 'Dokumente',
],
'extras' => [
'icon' => 'document', 'icon' => 'document',
], ],
[ ]);
'route' => false,
'title' => 'FAQ & Kontakt',
'icon' => 'info',
'children' => [
[
'route' => 'app_teamer_faq',
'title' => 'FAQ',
],
[
'route' => 'app_teamer_contact',
'title' => 'Kontakt',
],
],
],
];
$menu = $this->createMenu($menuItems); $infoMenu = $menu->addChild('FAQ & Kontakt', [
'extras' => [
'icon' => 'info',
],
]);
$infoMenu->addChild('FAQ', [
'route' => 'app_teamer_faq',
'linkAttributes' => [
'title' => 'FAQ',
],
]);
$infoMenu->addChild('Kontakt', [
'route' => 'app_teamer_contact',
'linkAttributes' => [
'title' => 'Kontakt',
],
]);
$this->addAdminItem($menu); $this->addAdminItem($menu);
$this->addHouseManagerItem($menu); $this->addHouseManagerItem($menu);
+1 -1
View File
@@ -61,7 +61,7 @@
aria-expanded="false"> aria-expanded="false">
{{ block('label') }} {{ block('label') }}
</button> </button>
{% elseif item.extras.divider == true %} {% elseif item.extras.divider is defined %}
<hr class="my-4 h-px bg-gray-200"> <hr class="my-4 h-px bg-gray-200">
{% else %} {% else %}
<div class="hover:bg-gray-50 group flex gap-x-3 rounded-md p-2 text-sm leading-5 font-semibold text-gray-700" role="button"> <div class="hover:bg-gray-50 group flex gap-x-3 rounded-md p-2 text-sm leading-5 font-semibold text-gray-700" role="button">
@@ -1,4 +1,4 @@
{% extends 'layout.html.twig' %} {% extends 'admin/layout.html.twig' %}
{% block title %}Verfügbarkeit {{ teamer }}{% endblock %} {% block title %}Verfügbarkeit {{ teamer }}{% endblock %}