Files
smartguide/webapp/src/app/shared/ui/app-menu/app-menu.component.ts
T
Mats Paul Tončik ab18134c58
LocationBasedServices/smartguide/pipeline/head This commit looks good
Added initial account page
2026-06-30 14:28:30 +02:00

175 lines
4.3 KiB
TypeScript

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 { 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';
type NavItem = {
label: string;
icon: string;
route: string;
disabled: boolean;
queryParams?: Record<string, string | number | boolean>;
adminOnly?: boolean;
superAdminOnly?: boolean;
};
type NavItemGroup = {
label: string;
items: NavItem[];
adminOnly?: boolean;
superAdminOnly?: boolean;
};
@Component({
selector: 'app-menu',
imports: [
CommonModule,
RouterModule,
MatIconModule,
MatListModule,
MatProgressBarModule,
MatButtonModule,
MatTooltipModule,
MatCardModule,
MatCardContent,
],
templateUrl: './app-menu.component.html',
styleUrl: './app-menu.component.scss',
standalone: true,
})
export class AppMenuComponent {
collapsed = input(false);
canCollapse = input(false);
toggleCollapsed = output<void>();
readonly navLinkActiveOptions: IsActiveMatchOptions = {
paths: 'subset',
queryParams: 'ignored',
matrixParams: 'ignored',
fragment: 'ignored',
};
navItems: NavItem[] = [
{
label: 'Dashboard',
icon: 'dashboard',
route: '/dashboard',
disabled: false,
},
{
label: 'Personen',
icon: 'groups',
route: '/persons',
queryParams: {
institutionName: this.credentialService.organizationName.value,
},
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: '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: 'Accounts',
icon: 'manage_accounts',
route: '/accounts',
disabled: false,
adminOnly: true,
},
{
label: 'Organisationen',
icon: 'domain',
route: '/organizations',
disabled: false,
superAdminOnly: true,
},
];
navItemGroups: NavItemGroup[] = [
{
label: 'Navigation',
items: this.navItems.filter(
(item) => !item.adminOnly && !item.superAdminOnly,
),
},
{
label: 'Administration',
items: this.navItems.filter(
(item) => item.adminOnly && !item.superAdminOnly,
),
adminOnly: true,
},
{
label: 'Super Administration',
items: this.navItems.filter((item) => item.superAdminOnly),
superAdminOnly: true,
},
];
constructor(
public credentialService: CredentialService,
private readonly router: Router,
) {}
isNavigating = computed(() => !!this.router.currentNavigation());
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(() => {
this.credentialService.logoutAccount().subscribe({
next: (result) => {
if (result === 'stopped-impersonating') {
this.router.navigate(['/accounts']);
} else {
this.router.navigate(['/login']);
}
},
});
});
}
}