2019-06-18 10:40:12 +02:00
|
|
|
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';
|
2019-04-30 16:14:24 +02:00
|
|
|
import { AuthService } from '../../core/services/auth/auth.service';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { UserDialogComponent } from '../navbar/user-dialog/user-dialog.component';
|
2019-05-21 09:01:00 +02:00
|
|
|
import { AppRole } from '../../core/common/enum/app-role';
|
2019-06-06 10:53:30 +02:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Location } from '@angular/common';
|
2020-02-18 15:47:58 +01:00
|
|
|
import { LanguageDialogComponent } from '../language/dialog/language-dialog.component';
|
2020-12-14 18:28:13 +01:00
|
|
|
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;
|
2020-08-28 15:13:33 +02:00
|
|
|
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;
|
2021-04-06 18:03:00 +02:00
|
|
|
requiresSpecialPermission?: AppRole;
|
2019-05-21 09:01:00 +02:00
|
|
|
requiresAdmin: boolean;
|
2019-06-18 10:40:12 +02:00
|
|
|
isGeneral: boolean;
|
2019-04-24 11:26:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const GENERAL_ROUTES: RouteInfo[] = [
|
2020-06-26 11:08:51 +02:00
|
|
|
{ path: '/home', title: 'SIDE-BAR.DASHBOARD', icon: 'home' }
|
2019-04-24 11:26:53 +02:00
|
|
|
];
|
|
|
|
export const DMP_ROUTES: RouteInfo[] = [
|
2020-06-26 11:08:51 +02:00
|
|
|
{ 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' },
|
2020-06-26 11:08:51 +02:00
|
|
|
// { path: '/plans/new', title: 'SIDE-BAR.ADD-EXPERT', icon: 'playlist_add' }
|
2019-06-18 10:40:12 +02:00
|
|
|
];
|
|
|
|
export const DATASETS_ROUTES: RouteInfo[] = [
|
2020-06-26 11:08:51 +02:00
|
|
|
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'library_books' },
|
2023-12-01 18:18:41 +01:00
|
|
|
{ path: '/explore-descriptions', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'dns' },
|
2019-04-24 11:26:53 +02:00
|
|
|
];
|
2019-06-18 10:40:12 +02:00
|
|
|
|
|
|
|
export const PUBLIC_ROUTES: RouteInfo[] = [
|
2020-06-26 11:08:51 +02:00
|
|
|
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'library_books' },
|
2023-12-01 18:18:41 +01:00
|
|
|
{ path: '/explore-descriptions', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'dns' }
|
2019-07-29 16:08:49 +02:00
|
|
|
];
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
// export const GRANTS_ROUTES: RouteInfo[] = [
|
|
|
|
// { path: '/grants', title: 'SIDE-BAR.MY-GRANTS', icon: 'work_outline' }
|
2019-06-18 10:40:12 +02:00
|
|
|
// ];
|
2019-10-04 09:53:35 +02:00
|
|
|
|
2019-05-20 09:32:01 +02:00
|
|
|
export const ADMIN_ROUTES: RouteInfo[] = [
|
2023-10-20 17:01:09 +02:00
|
|
|
{ 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' },
|
2024-02-26 18:40:31 +01:00
|
|
|
{ path: '/prefilling-sources', title: 'SIDE-BAR.PREFILLING-SOURCES', icon: 'add_link' },
|
2023-11-29 14:26:40 +01:00
|
|
|
{ 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'},
|
2024-01-11 16:59:27 +01:00
|
|
|
{ path: '/notifications', title: 'SIDE-BAR.NOTIFICATIONS', icon: 'build'},
|
2023-12-14 14:02:13 +01:00
|
|
|
{ path: '/index-managment', title: 'SIDE-BAR.MAINTENANCE', icon: 'build'}
|
2019-05-20 09:32:01 +02:00
|
|
|
];
|
2020-06-26 11:08:51 +02:00
|
|
|
|
2021-04-06 18:03:00 +02:00
|
|
|
export const DATASET_TEMPLATE_ROUTES: RouteInfo[] = [
|
2023-11-29 14:26:40 +01:00
|
|
|
{ path: '/description-templates', title: 'SIDE-BAR.DESCRIPTION-TEMPLATES', icon: 'description' }
|
2021-04-06 18:03:00 +02:00
|
|
|
];
|
|
|
|
|
2020-06-26 11:08:51 +02:00
|
|
|
export const INFO_ROUTES: RouteInfo[] = [
|
2020-09-10 13:16:29 +02:00
|
|
|
{ path: '/co-branding', title: 'SIDE-BAR.CO-BRANDING', icon: 'toll' },
|
2020-08-28 15:13:33 +02:00
|
|
|
{ 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' }
|
2020-06-26 11:08:51 +02:00
|
|
|
];
|
|
|
|
|
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;
|
2019-05-20 09:32:01 +02:00
|
|
|
adminItems: GroupMenuItem;
|
2021-04-06 18:03:00 +02:00
|
|
|
datasetTemplateItems: GroupMenuItem;
|
2019-05-08 14:48:57 +02:00
|
|
|
// historyItems: GroupMenuItem;
|
2019-06-18 10:40:12 +02:00
|
|
|
datasetItems: GroupMenuItem;
|
2019-08-01 09:54:40 +02:00
|
|
|
grantItems: GroupMenuItem;
|
2019-05-08 14:48:57 +02:00
|
|
|
publicItems: GroupMenuItem;
|
2020-06-26 11:08:51 +02:00
|
|
|
infoItems: GroupMenuItem;
|
2019-05-08 14:48:57 +02:00
|
|
|
groupMenuItems: GroupMenuItem[] = [];
|
2019-06-06 10:53:30 +02:00
|
|
|
private toggleButton: any;
|
2020-02-18 15:47:58 +01:00
|
|
|
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,
|
2019-06-06 10:53:30 +02:00
|
|
|
private dialog: MatDialog,
|
|
|
|
public router: Router,
|
2020-12-14 18:28:13 +01:00
|
|
|
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() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('Sidebar');
|
2020-02-18 15:47:58 +01:00
|
|
|
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,
|
2019-05-21 09:01:00 +02:00
|
|
|
requiresAuthentication: false,
|
|
|
|
requiresAdmin: false,
|
2019-06-18 10:40:12 +02:00
|
|
|
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,
|
2019-05-21 09:01:00 +02:00
|
|
|
requiresAuthentication: true,
|
2019-06-18 10:40:12 +02:00
|
|
|
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
|
|
|
|
2019-06-18 10:40:12 +02:00
|
|
|
this.datasetItems = {
|
|
|
|
title: 'SIDE-BAR.DATASETS',
|
|
|
|
routes: DATASETS_ROUTES,
|
|
|
|
requiresAuthentication: true,
|
|
|
|
requiresAdmin: false,
|
|
|
|
isGeneral: false
|
|
|
|
}
|
|
|
|
this.groupMenuItems.push(this.datasetItems);
|
|
|
|
|
2019-10-04 09:53:35 +02:00
|
|
|
// ----------- 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);
|
2019-06-18 10:40:12 +02:00
|
|
|
|
2019-05-20 09:32:01 +02:00
|
|
|
this.adminItems = {
|
|
|
|
title: 'SIDE-BAR.ADMIN',
|
|
|
|
routes: ADMIN_ROUTES,
|
2019-05-21 09:01:00 +02:00
|
|
|
requiresAuthentication: true,
|
2019-06-18 10:40:12 +02:00
|
|
|
requiresAdmin: true,
|
|
|
|
isGeneral: false
|
2019-05-20 09:32:01 +02:00
|
|
|
}
|
|
|
|
this.groupMenuItems.push(this.adminItems);
|
|
|
|
|
2021-04-06 18:03:00 +02:00
|
|
|
this.datasetTemplateItems = {
|
|
|
|
title: 'SIDE-BAR.ADMIN',
|
|
|
|
routes: DATASET_TEMPLATE_ROUTES,
|
|
|
|
requiresAuthentication: true,
|
2023-12-12 16:51:40 +01:00
|
|
|
requiresSpecialPermission: AppRole.DescriptionTemplateEditor,
|
2021-04-06 18:03:00 +02:00
|
|
|
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,
|
2019-05-21 09:01:00 +02:00
|
|
|
requiresAuthentication: false,
|
2019-06-18 10:40:12 +02:00
|
|
|
requiresAdmin: false,
|
|
|
|
isGeneral: false
|
2019-05-08 14:48:57 +02:00
|
|
|
}
|
|
|
|
this.groupMenuItems.push(this.publicItems);
|
2019-06-18 10:40:12 +02:00
|
|
|
|
2020-06-26 11:08:51 +02:00
|
|
|
this.infoItems = {
|
|
|
|
title: "",
|
|
|
|
routes: INFO_ROUTES,
|
|
|
|
requiresAuthentication: false,
|
|
|
|
requiresAdmin: false,
|
|
|
|
isGeneral: false
|
|
|
|
}
|
|
|
|
this.groupMenuItems.push(this.infoItems);
|
|
|
|
|
2020-02-18 15:47:58 +01:00
|
|
|
this.router.events.subscribe((event) => this.currentRoute = this.router.url);
|
|
|
|
|
2019-06-18 10:40:12 +02:00
|
|
|
// this.historyItems = {
|
|
|
|
// title: 'SIDE-BAR.HISTORY',
|
|
|
|
// routes: HISTORY_ROUTES
|
|
|
|
// }
|
|
|
|
// this.groupMenuItems.push(this.historyItems);
|
2019-04-24 11:26:53 +02:00
|
|
|
}
|
|
|
|
|
2019-04-30 16:14:24 +02:00
|
|
|
public principalHasAvatar(): boolean {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.getUserProfileAvatarUrl() != null && this.authentication.getUserProfileAvatarUrl().length > 0;
|
2019-04-30 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalAvatar(): string {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.getUserProfileAvatarUrl();
|
2019-04-30 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:28:20 +01:00
|
|
|
public getDefaultAvatar(): string {
|
|
|
|
return 'assets/images/profile-placeholder.png';
|
|
|
|
}
|
|
|
|
|
2020-02-18 15:47:58 +01:00
|
|
|
public applyFallbackAvatar(ev: Event) {
|
|
|
|
(ev.target as HTMLImageElement).src = this.getDefaultAvatar();
|
|
|
|
}
|
|
|
|
|
2019-04-30 16:14:24 +02:00
|
|
|
public isAuthenticated(): boolean {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.currentAccountIsAuthenticated();
|
2019-04-30 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
2019-05-21 09:01:00 +02:00
|
|
|
public isAdmin(): boolean {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.hasRole(AppRole.Admin);
|
2019-05-21 09:01:00 +02:00
|
|
|
}
|
|
|
|
|
2023-10-11 16:53:12 +02:00
|
|
|
public hasPermission(role: AppRole): boolean {
|
|
|
|
return this.authentication.hasRole(role);
|
2021-04-06 18:03:00 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 10:53:30 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-21 09:01:00 +02:00
|
|
|
showItem(value: GroupMenuItem) {
|
2019-06-18 10:40:12 +02:00
|
|
|
if (this.isAuthenticated()) {
|
|
|
|
if (value.requiresAdmin) {
|
|
|
|
return this.isAdmin();
|
|
|
|
}
|
2021-04-06 18:03:00 +02:00
|
|
|
else if (value.requiresSpecialPermission !== undefined) {
|
|
|
|
return this.hasPermission(value.requiresSpecialPermission);
|
|
|
|
}
|
2019-06-18 10:40:12 +02:00
|
|
|
else {
|
|
|
|
return value.isGeneral || value.requiresAuthentication;
|
|
|
|
}
|
2019-05-21 09:01:00 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-06-18 10:40:12 +02:00
|
|
|
return !value.requiresAuthentication;
|
2019-05-21 09:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 16:14:24 +02:00
|
|
|
openProfile() {
|
|
|
|
const dialogRef = this.dialog.open(UserDialogComponent, {
|
|
|
|
hasBackdrop: true,
|
|
|
|
autoFocus: false,
|
|
|
|
closeOnNavigation: true,
|
|
|
|
disableClose: false,
|
2020-08-26 15:15:57 +02:00
|
|
|
position: { top: '64px', right: '1em' },
|
|
|
|
panelClass: 'custom-userbox'
|
2019-04-30 16:14:24 +02:00
|
|
|
});
|
|
|
|
}
|
2020-02-18 15:47:58 +01:00
|
|
|
|
|
|
|
public onInvalidUrl(): boolean {
|
|
|
|
return this.currentRoute === '/language-editor' || this.currentRoute === '/profile';
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:16:29 +02:00
|
|
|
public openLanguageDialog() {
|
2020-02-18 15:47:58 +01:00
|
|
|
if (this.dialog.openDialogs.length > 0) {
|
|
|
|
this.dialog.closeAll();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const dialogRef = this.dialog.open(LanguageDialogComponent, {
|
|
|
|
disableClose: true,
|
|
|
|
data: {
|
|
|
|
isDialog: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-08-28 15:13:33 +02:00
|
|
|
|
2020-09-11 10:27:29 +02:00
|
|
|
public openFeedback(groupMenuRoute: RouteInfo) {
|
|
|
|
window.open(groupMenuRoute.url, '_blank');
|
2020-08-28 15:13:33 +02:00
|
|
|
}
|
2020-09-10 13:16:29 +02:00
|
|
|
|
2019-04-24 11:26:53 +02:00
|
|
|
}
|