argos/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts

282 lines
8.4 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2023-10-06 10:10:53 +02:00
import { MatDialog } from '@angular/material/dialog';
2019-05-08 14:48:57 +02:00
import { TranslateService } from '@ngx-translate/core';
import { AuthService } from '../../core/services/auth/auth.service';
import { UserDialogComponent } from '../misc/navigation/user-dialog/user-dialog.component';
import { AppRole } from '../../core/common/enum/app-role';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { LanguageDialogComponent } from '../language/dialog/language-dialog.component';
import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { HttpClient } from '@angular/common/http';
2019-04-24 11:26:53 +02:00
declare interface RouteInfo {
2019-05-08 14:48:57 +02:00
path: string;
title: string;
icon: string;
url?: string;
2019-04-24 11:26:53 +02:00
}
declare interface GroupMenuItem {
title: string;
routes: RouteInfo[];
2019-05-08 17:24:30 +02:00
requiresAuthentication: boolean;
requiresSpecialPermission?: AppRole;
requiresAdmin: boolean;
isGeneral: boolean;
2019-04-24 11:26:53 +02:00
}
export const GENERAL_ROUTES: RouteInfo[] = [
{ path: '/home', title: 'SIDE-BAR.DASHBOARD', icon: 'home' }
2019-04-24 11:26:53 +02:00
];
export const DMP_ROUTES: RouteInfo[] = [
{ path: '/plans', title: 'SIDE-BAR.MY-DMPS', icon: 'library_books' },
2023-11-29 14:26:40 +01:00
{ path: '/descriptions', title: 'SIDE-BAR.MY-DESCRIPTIONS', icon: 'dns' },
// { path: '/plans/new', title: 'SIDE-BAR.ADD-EXPERT', icon: 'playlist_add' }
];
export const DATASETS_ROUTES: RouteInfo[] = [
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'library_books' },
{ path: '/explore-descriptions', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'dns' },
2019-04-24 11:26:53 +02:00
];
export const PUBLIC_ROUTES: RouteInfo[] = [
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'library_books' },
{ path: '/explore-descriptions', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'dns' }
2019-07-29 16:08:49 +02:00
];
// export const GRANTS_ROUTES: RouteInfo[] = [
// { path: '/grants', title: 'SIDE-BAR.MY-GRANTS', icon: 'work_outline' }
// ];
export const ADMIN_ROUTES: RouteInfo[] = [
{ path: '/dmp-blueprints', title: 'SIDE-BAR.DMP-BLUEPRINTS', icon: 'library_books' },
2023-11-29 14:26:40 +01:00
{ path: '/description-templates', title: 'SIDE-BAR.DESCRIPTION-TEMPLATES', icon: 'description' },
{ path: '/description-template-type', title: 'SIDE-BAR.DESCRIPTION-TEMPLATE-TYPES', icon: 'stack' },
{ path: '/references', title: 'SIDE-BAR.REFERENCES', icon: 'dataset_linked' },
{ path: '/reference-type', title: 'SIDE-BAR.REFERENCE-TYPES', icon: 'add_link' },
{ path: '/tenants', title: 'SIDE-BAR.TENANTS', icon: 'tenancy' },
2020-01-27 17:38:24 +01:00
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' },
2023-11-27 17:22:13 +01:00
{ path: '/languages', title: 'SIDE-BAR.LANGUAGES', icon: 'language' },
2023-12-19 18:08:17 +01:00
{ path: '/supportive-material', title: 'SIDE-BAR.SUPPORTIVE-MATERIAL', icon: 'dataset_linked' },
{ path: '/notification-templates', title: 'SIDE-BAR.NOTIFICATION-TEMPLATES', icon: 'build'},
2023-12-14 14:02:13 +01:00
{ path: '/index-managment', title: 'SIDE-BAR.MAINTENANCE', icon: 'build'}
];
export const DATASET_TEMPLATE_ROUTES: RouteInfo[] = [
2023-11-29 14:26:40 +01:00
{ path: '/description-templates', title: 'SIDE-BAR.DESCRIPTION-TEMPLATES', icon: 'description' }
];
export const INFO_ROUTES: RouteInfo[] = [
{ path: '/co-branding', title: 'SIDE-BAR.CO-BRANDING', icon: 'toll' },
{ path: '/contact-support', title: 'SIDE-BAR.SUPPORT', icon: 'help' },
2020-10-02 13:40:20 +02:00
{ path: '/feedback', title: 'SIDE-BAR.FEEDBACK', icon: 'feedback', url: 'https://docs.google.com/forms/d/12RSCrUjdSDp2LZLpjDKOi44cN1fLDD2q1-F66SqZIis/viewform?edit_requested=true' }
];
2019-04-24 11:26:53 +02:00
// export const HISTORY_ROUTES: RouteInfo[] = [
2019-05-08 14:48:57 +02:00
// { path: '/typography', title: 'SIDE-BAR.HISTORY-VISITED', icon: 'visibility'},
// { path: '/icons', title: 'SIDE-BAR.HISTORY-EDITED', icon: 'edit'}
2019-04-24 11:26:53 +02:00
// ];
@Component({
2019-05-08 14:48:57 +02:00
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.css', './sidebar.component.scss']
2019-04-24 11:26:53 +02:00
})
export class SidebarComponent implements OnInit {
2019-05-08 14:48:57 +02:00
generalItems: GroupMenuItem;
dmpItems: GroupMenuItem;
adminItems: GroupMenuItem;
datasetTemplateItems: GroupMenuItem;
2019-05-08 14:48:57 +02:00
// historyItems: GroupMenuItem;
datasetItems: GroupMenuItem;
grantItems: GroupMenuItem;
2019-05-08 14:48:57 +02:00
publicItems: GroupMenuItem;
infoItems: GroupMenuItem;
2019-05-08 14:48:57 +02:00
groupMenuItems: GroupMenuItem[] = [];
private toggleButton: any;
currentRoute: string;
2019-04-24 11:26:53 +02:00
2019-06-05 09:19:28 +02:00
constructor(
public translate: TranslateService,
private authentication: AuthService,
private dialog: MatDialog,
public router: Router,
private location: Location,
private httpClient: HttpClient,
private matomoService: MatomoService
) {
2019-06-05 09:19:28 +02:00
}
2019-04-24 11:26:53 +02:00
2019-05-08 14:48:57 +02:00
ngOnInit() {
this.matomoService.trackPageView('Sidebar');
this.currentRoute = this.router.url;
2019-05-08 14:48:57 +02:00
this.generalItems = {
title: 'SIDE-BAR.GENERAL',
2019-05-08 17:24:30 +02:00
routes: GENERAL_ROUTES,
requiresAuthentication: false,
requiresAdmin: false,
isGeneral: true
2019-05-08 14:48:57 +02:00
}
this.groupMenuItems.push(this.generalItems);
2019-04-24 11:26:53 +02:00
2019-05-08 14:48:57 +02:00
this.dmpItems = {
title: 'SIDE-BAR.DMP',
2019-05-08 17:24:30 +02:00
routes: DMP_ROUTES,
requiresAuthentication: true,
requiresAdmin: false,
isGeneral: false
2019-05-08 14:48:57 +02:00
}
this.groupMenuItems.push(this.dmpItems);
2019-04-24 11:26:53 +02:00
this.datasetItems = {
title: 'SIDE-BAR.DATASETS',
routes: DATASETS_ROUTES,
requiresAuthentication: true,
requiresAdmin: false,
isGeneral: false
}
this.groupMenuItems.push(this.datasetItems);
// ----------- UNCOMMENT TO ADD AGAIN GRANTS --------
// this.grantItems = {
// title: 'SIDE-BAR.GRANTS',
// routes: GRANTS_ROUTES,
// requiresAuthentication: true,
// requiresAdmin: false,
// isGeneral: false
// }
// this.groupMenuItems.push(this.grantItems);
this.adminItems = {
title: 'SIDE-BAR.ADMIN',
routes: ADMIN_ROUTES,
requiresAuthentication: true,
requiresAdmin: true,
isGeneral: false
}
this.groupMenuItems.push(this.adminItems);
this.datasetTemplateItems = {
title: 'SIDE-BAR.ADMIN',
routes: DATASET_TEMPLATE_ROUTES,
requiresAuthentication: true,
2023-12-12 16:51:40 +01:00
requiresSpecialPermission: AppRole.DescriptionTemplateEditor,
requiresAdmin: false,
isGeneral: false
}
this.groupMenuItems.push(this.datasetTemplateItems);
2019-05-08 14:48:57 +02:00
this.publicItems = {
title: 'SIDE-BAR.PUBLIC',
2019-05-08 17:24:30 +02:00
routes: PUBLIC_ROUTES,
requiresAuthentication: false,
requiresAdmin: false,
isGeneral: false
2019-05-08 14:48:57 +02:00
}
this.groupMenuItems.push(this.publicItems);
this.infoItems = {
title: "",
routes: INFO_ROUTES,
requiresAuthentication: false,
requiresAdmin: false,
isGeneral: false
}
this.groupMenuItems.push(this.infoItems);
this.router.events.subscribe((event) => this.currentRoute = this.router.url);
// this.historyItems = {
// title: 'SIDE-BAR.HISTORY',
// routes: HISTORY_ROUTES
// }
// this.groupMenuItems.push(this.historyItems);
2019-04-24 11:26:53 +02:00
}
public principalHasAvatar(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.getUserProfileAvatarUrl() != null && this.authentication.getUserProfileAvatarUrl().length > 0;
}
public getPrincipalAvatar(): string {
2023-10-11 16:53:12 +02:00
return this.authentication.getUserProfileAvatarUrl();
}
2019-11-22 17:28:20 +01:00
public getDefaultAvatar(): string {
return 'assets/images/profile-placeholder.png';
}
public applyFallbackAvatar(ev: Event) {
(ev.target as HTMLImageElement).src = this.getDefaultAvatar();
}
public isAuthenticated(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.currentAccountIsAuthenticated();
}
public isAdmin(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.hasRole(AppRole.Admin);
}
2023-10-11 16:53:12 +02:00
public hasPermission(role: AppRole): boolean {
return this.authentication.hasRole(role);
}
isLoginRouteActivated(): boolean {
return this.location.path().indexOf('/login') > -1;
}
2019-06-05 09:19:28 +02:00
public logout(): void {
2023-10-11 16:53:12 +02:00
this.router.navigate(['/logout']);
2019-06-05 09:19:28 +02:00
}
showItem(value: GroupMenuItem) {
if (this.isAuthenticated()) {
if (value.requiresAdmin) {
return this.isAdmin();
}
else if (value.requiresSpecialPermission !== undefined) {
return this.hasPermission(value.requiresSpecialPermission);
}
else {
return value.isGeneral || value.requiresAuthentication;
}
}
else {
return !value.requiresAuthentication;
}
}
openProfile() {
const dialogRef = this.dialog.open(UserDialogComponent, {
hasBackdrop: true,
autoFocus: false,
closeOnNavigation: true,
disableClose: false,
position: { top: '64px', right: '1em' },
panelClass: 'custom-userbox'
});
}
public onInvalidUrl(): boolean {
return this.currentRoute === '/language-editor' || this.currentRoute === '/profile';
}
public openLanguageDialog() {
if (this.dialog.openDialogs.length > 0) {
this.dialog.closeAll();
}
else {
const dialogRef = this.dialog.open(LanguageDialogComponent, {
disableClose: true,
data: {
isDialog: true
}
});
}
}
public openFeedback(groupMenuRoute: RouteInfo) {
window.open(groupMenuRoute.url, '_blank');
}
2019-04-24 11:26:53 +02:00
}