332 lines
8.9 KiB
TypeScript
332 lines
8.9 KiB
TypeScript
import { Component, computed, inject, input, output } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { NavigationEnd, Router, RouterModule } from '@angular/router';
|
|
import { toSignal } from '@angular/core/rxjs-interop';
|
|
import { filter, map } from 'rxjs';
|
|
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 {
|
|
FounderSortBy,
|
|
SortDirection,
|
|
TopicSortBy,
|
|
WorkSortBy,
|
|
} from '../../../api';
|
|
import { workQueryParamKeys } from '../../../resolvers/work-page.resolver';
|
|
import { MatMenuModule } from '@angular/material/menu';
|
|
import {
|
|
BOOKMARKS_ICON,
|
|
DASHBOARD_ICON,
|
|
DOUBLE_ARROW_LEFT_ICON,
|
|
DOUBLE_ARROW_RIGHT_ICON,
|
|
FOUNDER_ICON,
|
|
HIERARCHY_ICON,
|
|
INSTITUTION_ICON,
|
|
JOBS_ICON,
|
|
KEYWORDS_ICON,
|
|
LOGOUT_ICON,
|
|
MANAGE_ACCOUNTS_ICON,
|
|
NEWS_ICON,
|
|
NETWORK_ICON,
|
|
ORGANIZATIONS_ICON,
|
|
PATENT_ICON,
|
|
PERSONS_ICON,
|
|
PROJECT_ICON,
|
|
PUBLICATION_ICON,
|
|
TOPIC_ICON,
|
|
} from '../icons';
|
|
|
|
type NavItem = {
|
|
label: string;
|
|
icon: string;
|
|
route: string;
|
|
disabled: boolean;
|
|
queryParams?: Record<string, string | number | boolean>;
|
|
adminOnly?: boolean;
|
|
superAdminOnly?: boolean;
|
|
managerOrAdminOnly?: boolean;
|
|
detailRoutePrefixes?: string[];
|
|
};
|
|
|
|
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 {
|
|
readonly LOGOUT_ICON = LOGOUT_ICON;
|
|
readonly DOUBLE_ARROW_LEFT_ICON = DOUBLE_ARROW_LEFT_ICON;
|
|
readonly DOUBLE_ARROW_RIGHT_ICON = DOUBLE_ARROW_RIGHT_ICON;
|
|
|
|
collapsed = input(false);
|
|
canCollapse = input(false);
|
|
toggleCollapsed = output<void>();
|
|
|
|
private readonly router = inject(Router);
|
|
|
|
private readonly currentPath = toSignal(
|
|
this.router.events.pipe(
|
|
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
|
|
map((event) => event.urlAfterRedirects.split('?')[0]),
|
|
),
|
|
{ initialValue: this.router.url.split('?')[0] },
|
|
);
|
|
|
|
isItemActive(item: NavItem): boolean {
|
|
const path = this.currentPath();
|
|
// `/founders/:authorId` is the multiplier-network detail route. Do not
|
|
// highlight the founder-potential dashboard for that path.
|
|
if (item.route === '/founders' && path.startsWith('/founders/')) {
|
|
return false;
|
|
}
|
|
if (
|
|
(item.detailRoutePrefixes ?? []).some((prefix) => path.startsWith(prefix))
|
|
) {
|
|
return true;
|
|
}
|
|
if (path === item.route || path.startsWith(`${item.route}/`)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
readonly navItems = computed<NavItem[]>(() => {
|
|
const items: NavItem[] = [
|
|
{
|
|
label: 'Dashboard',
|
|
icon: DASHBOARD_ICON,
|
|
route: '/dashboard',
|
|
disabled: false,
|
|
},
|
|
{
|
|
label: 'Personen',
|
|
icon: PERSONS_ICON,
|
|
route: '/persons',
|
|
queryParams: activeInstitutionPersonListQueryParams(
|
|
this.credentialService.effectiveInstitutionId(),
|
|
this.credentialService.organizationName(),
|
|
),
|
|
disabled: false,
|
|
detailRoutePrefixes: ['/person/'],
|
|
},
|
|
{
|
|
label: 'Bookmarks',
|
|
icon: BOOKMARKS_ICON,
|
|
route: '/bookmarks',
|
|
disabled: false,
|
|
},
|
|
{
|
|
label: 'Nachrichten',
|
|
icon: NEWS_ICON,
|
|
route: '/news',
|
|
disabled: false,
|
|
},
|
|
{
|
|
label: 'Institutionen',
|
|
icon: INSTITUTION_ICON,
|
|
route: '/institutions',
|
|
disabled: false,
|
|
queryParams: {
|
|
search: '',
|
|
page: 0,
|
|
size: 10,
|
|
sort_by: 'works_count',
|
|
sorting_order: SortDirection.Desc,
|
|
},
|
|
detailRoutePrefixes: ['/institution/'],
|
|
},
|
|
{
|
|
label: 'Publikationen',
|
|
icon: PUBLICATION_ICON,
|
|
route: '/publications',
|
|
disabled: false,
|
|
queryParams: {
|
|
[workQueryParamKeys.title]: '',
|
|
[workQueryParamKeys.page]: 0,
|
|
[workQueryParamKeys.size]: 10,
|
|
[workQueryParamKeys.sortBy]: WorkSortBy.CitedByCount,
|
|
[workQueryParamKeys.sortDirection]: SortDirection.Desc,
|
|
},
|
|
detailRoutePrefixes: ['/publication/'],
|
|
},
|
|
{
|
|
label: 'Themen',
|
|
icon: TOPIC_ICON,
|
|
route: '/topics',
|
|
disabled: false,
|
|
queryParams: {
|
|
[topicQueryParamKeys.query]: '',
|
|
[topicQueryParamKeys.page]: 0,
|
|
[topicQueryParamKeys.size]: 10,
|
|
[topicQueryParamKeys.sortBy]: TopicSortBy.CitedByCount,
|
|
[topicQueryParamKeys.sortDirection]: SortDirection.Desc,
|
|
},
|
|
detailRoutePrefixes: ['/topic/'],
|
|
},
|
|
{
|
|
label: 'Projekte',
|
|
icon: PROJECT_ICON,
|
|
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: PATENT_ICON,
|
|
route: '/patents',
|
|
disabled: false,
|
|
detailRoutePrefixes: ['/patent/'],
|
|
},
|
|
{
|
|
label: 'Keywords',
|
|
icon: KEYWORDS_ICON,
|
|
route: '/keywords',
|
|
disabled: false,
|
|
queryParams: {
|
|
mode: 'url',
|
|
},
|
|
},
|
|
{
|
|
label: 'Hierarchie',
|
|
icon: HIERARCHY_ICON,
|
|
route: '/hierarchy',
|
|
disabled: false,
|
|
},
|
|
{
|
|
label: 'Gründungspotenzial',
|
|
icon: FOUNDER_ICON,
|
|
route: '/founders',
|
|
disabled: false,
|
|
queryParams: {
|
|
screened: 'true',
|
|
page: 0,
|
|
size: 10,
|
|
sortBy: FounderSortBy.ExternalPercentile,
|
|
sortOrder: SortDirection.Desc,
|
|
},
|
|
},
|
|
{
|
|
label: 'Multiplikatoren',
|
|
icon: NETWORK_ICON,
|
|
route: '/multipliers',
|
|
disabled: false,
|
|
queryParams: {
|
|
page: 0,
|
|
size: 10,
|
|
sortBy: 'max',
|
|
sortOrder: 'desc',
|
|
peerRankField: 'max',
|
|
},
|
|
detailRoutePrefixes: ['/founders/'],
|
|
},
|
|
{
|
|
label: 'Accounts',
|
|
icon: MANAGE_ACCOUNTS_ICON,
|
|
route: '/accounts',
|
|
disabled: false,
|
|
managerOrAdminOnly: true,
|
|
},
|
|
{
|
|
label: 'Organisationen',
|
|
icon: ORGANIZATIONS_ICON,
|
|
route: '/organizations',
|
|
disabled: false,
|
|
superAdminOnly: true,
|
|
},
|
|
{
|
|
label: 'Jobs',
|
|
icon: JOBS_ICON,
|
|
route: '/jobs',
|
|
disabled: false,
|
|
superAdminOnly: true,
|
|
},
|
|
];
|
|
return items;
|
|
});
|
|
readonly navItemGroups = computed<NavItemGroup[]>(() => {
|
|
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) {}
|
|
|
|
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();
|
|
});
|
|
}
|
|
}
|