import { Component, computed, inject, input, output } from '@angular/core'; import { CommonModule } from '@angular/common'; import { IsActiveMatchOptions, Router, RouterModule } from '@angular/router'; import { MatIconModule } from '@angular/material/icon'; import { MatListModule } from '@angular/material/list'; import { MatButtonModule } from '@angular/material/button'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CredentialService } from '../../services/credential.service'; import { ThemeService } from '../../services/theme.service'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatDialog } from '@angular/material/dialog'; import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component'; import { MatCardContent, MatCardModule } from '@angular/material/card'; import { MatProgressSpinner } from '@angular/material/progress-spinner'; import { activeInstitutionPersonListQueryParams } from '../../person-list-query-params'; import { topicQueryParamKeys } from '../../../resolvers/topic-page.resolver'; import { SortDirection, TopicSortBy, WorkSortBy } from '../../../api'; import { workQueryParamKeys } from '../../../resolvers/work-page.resolver'; import { MatMenuModule } from '@angular/material/menu'; type NavItem = { label: string; icon: string; route: string; disabled: boolean; queryParams?: Record; adminOnly?: boolean; superAdminOnly?: boolean; managerOrAdminOnly?: boolean; }; type NavItemGroup = { label: string; items: NavItem[]; adminOnly?: boolean; superAdminOnly?: boolean; managerOrAdminOnly?: boolean; }; @Component({ selector: 'app-menu', imports: [ CommonModule, RouterModule, MatIconModule, MatListModule, MatProgressBarModule, MatButtonModule, MatTooltipModule, MatCardModule, MatCardContent, MatProgressSpinner, MatMenuModule, ], templateUrl: './app-menu.component.html', styleUrl: './app-menu.component.scss', standalone: true, }) export class AppMenuComponent { collapsed = input(false); canCollapse = input(false); toggleCollapsed = output(); readonly navLinkActiveOptions: IsActiveMatchOptions = { paths: 'subset', queryParams: 'ignored', matrixParams: 'ignored', fragment: 'ignored', }; readonly navItems = computed(() => { const items: NavItem[] = [ { label: 'Dashboard', icon: 'dashboard', route: '/dashboard', disabled: false, }, { label: 'Personen', icon: 'groups', route: '/persons', queryParams: activeInstitutionPersonListQueryParams( this.credentialService.effectiveInstitutionId(), this.credentialService.organizationName(), ), disabled: false, }, { label: 'Bookmarks', icon: 'bookmarks', route: '/bookmarks', disabled: false, }, { label: 'News', icon: 'newspaper', route: '/news', disabled: false, }, { label: 'Institutionen', icon: 'apartment', route: '/institutions', disabled: false, queryParams: { search: '', page: 0, size: 10, sort_by: 'works_count', sorting_order: SortDirection.Desc, }, }, { label: 'Publikationen', icon: 'menu_book', route: '/publications', disabled: false, queryParams: { [workQueryParamKeys.title]: '', [workQueryParamKeys.page]: 0, [workQueryParamKeys.size]: 10, [workQueryParamKeys.sortBy]: WorkSortBy.CitedByCount, [workQueryParamKeys.sortDirection]: SortDirection.Desc, }, }, { label: 'Themen', icon: 'topic', route: '/topics', disabled: false, queryParams: { [topicQueryParamKeys.query]: '', [topicQueryParamKeys.page]: 0, [topicQueryParamKeys.size]: 10, [topicQueryParamKeys.sortBy]: TopicSortBy.CitedByCount, [topicQueryParamKeys.sortDirection]: SortDirection.Desc, }, }, { label: 'Projekte', icon: 'work', route: '/projects', disabled: false, queryParams: { search: '', page: 0, size: 10, selected_project_types: 'eu,bund,dfg', sort_by: 'title', sorting_order: 'asc', }, }, { label: 'Patente', icon: 'workspace_premium', route: '/patents', disabled: false, }, { label: 'Keywords', icon: 'join_left', route: '/keywords', disabled: false, queryParams: { mode: 'url', }, }, { label: 'Accounts', icon: 'manage_accounts', route: '/accounts', disabled: false, managerOrAdminOnly: true, }, { label: 'Organisationen', icon: 'domain', route: '/organizations', disabled: false, superAdminOnly: true, }, { label: 'Jobs', icon: 'sync', route: '/jobs', disabled: false, superAdminOnly: true, }, ]; return items; }); readonly navItemGroups = computed(() => { const navItems = this.navItems(); return [ { label: 'Navigation', items: navItems.filter( (item) => !item.adminOnly && !item.superAdminOnly && !item.managerOrAdminOnly, ), }, { label: 'Administration', items: navItems.filter( (item) => (item.adminOnly || item.managerOrAdminOnly) && !item.superAdminOnly, ), managerOrAdminOnly: true, }, { label: 'Super Administration', items: navItems.filter((item) => item.superAdminOnly), superAdminOnly: true, }, ]; }); constructor( public credentialService: CredentialService, private readonly router: Router, ) {} isNavigating = computed(() => !!this.router.currentNavigation()); readonly themeService = inject(ThemeService); private readonly dialog = inject(MatDialog); onLogout() { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { data: { title: 'Abmelden', message: 'Möchtest Du Dich wirklich abmelden?', confirmText: 'Abmelden', cancelText: 'Abbrechen', }, }); dialogRef.componentInstance.confirmDelete.subscribe(() => { void this.credentialService.logoutAccount(); }); } }