2019-06-18 10:40:12 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-09-23 10:17:03 +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';
|
|
|
|
import { UserDialogComponent } from '../misc/navigation/user-dialog/user-dialog.component';
|
2019-05-21 09:01:00 +02:00
|
|
|
import { Principal } from '../../core/model/auth/Principal';
|
|
|
|
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';
|
2019-06-18 10:40:12 +02:00
|
|
|
import { Route } from '@angular/compiler/src/core';
|
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;
|
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;
|
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[] = [
|
2019-06-18 10:40:12 +02:00
|
|
|
{ path: '/home', title: 'SIDE-BAR.DASHBOARD', icon: 'dashboard' },
|
|
|
|
{ path: '/about', title: 'SIDE-BAR.ABOUT', icon: 'info_outline' }
|
2019-04-24 11:26:53 +02:00
|
|
|
];
|
|
|
|
export const DMP_ROUTES: RouteInfo[] = [
|
2019-05-08 17:24:30 +02:00
|
|
|
{ path: '/plans', title: 'SIDE-BAR.MY-DMPS', icon: 'view_agenda' },
|
2019-06-18 10:40:12 +02:00
|
|
|
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'public' },
|
|
|
|
{ path: '/quick-wizard', title: 'SIDE-BAR.QUICK-WIZARD', icon: 'play_circle_outline' },
|
|
|
|
{ path: '/plans/new', title: 'SIDE-BAR.ADD-EXPERT', icon: 'playlist_add' }
|
|
|
|
];
|
|
|
|
export const DATASETS_ROUTES: RouteInfo[] = [
|
2019-05-08 17:24:30 +02:00
|
|
|
{ path: '/datasets', title: 'SIDE-BAR.MY-DATASET-DESC', icon: 'library_books' },
|
2019-07-29 16:08:49 +02:00
|
|
|
{ path: '/explore', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'public' },
|
|
|
|
{ path: '/datasetcreatewizard', title: 'SIDE-BAR.QUICK-WIZARD-DATASET', icon: "play_circle_outline" },
|
2019-04-24 11:26:53 +02:00
|
|
|
];
|
2019-06-18 10:40:12 +02:00
|
|
|
|
|
|
|
export const PUBLIC_ROUTES: RouteInfo[] = [
|
|
|
|
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'public' },
|
2019-07-29 16:08:49 +02:00
|
|
|
{ path: '/explore', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'public' }
|
|
|
|
];
|
|
|
|
|
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[] = [
|
2019-05-21 09:01:00 +02:00
|
|
|
{ path: '/dmp-profiles', title: 'SIDE-BAR.DMP-TEMPLATES', icon: 'library_books' },
|
|
|
|
{ path: '/dataset-profiles', title: 'SIDE-BAR.DATASET-TEMPLATES', icon: 'library_books' },
|
2020-01-27 17:38:24 +01:00
|
|
|
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' },
|
2020-02-03 16:35:34 +01:00
|
|
|
{ path: '/language-editor', title: 'SIDE-BAR.LANGUAGE-EDITOR', icon: 'language'}
|
2019-05-20 09:32:01 +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;
|
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;
|
|
|
|
groupMenuItems: GroupMenuItem[] = [];
|
2019-06-06 10:53:30 +02:00
|
|
|
private toggleButton: any;
|
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,
|
|
|
|
private location: Location) {
|
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.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);
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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 {
|
2019-11-22 17:28:20 +01:00
|
|
|
return this.authentication.current().avatarUrl != null && this.authentication.current().avatarUrl.length > 0;
|
2019-04-30 16:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getPrincipalAvatar(): string {
|
|
|
|
return this.authentication.current().avatarUrl;
|
|
|
|
}
|
|
|
|
|
2019-11-22 17:28:20 +01:00
|
|
|
public getDefaultAvatar(): string {
|
|
|
|
return 'assets/images/profile-placeholder.png';
|
|
|
|
}
|
|
|
|
|
2019-04-30 16:14:24 +02:00
|
|
|
public isAuthenticated(): boolean {
|
2019-05-21 09:01:00 +02:00
|
|
|
const myBollean = this.isAdmin();
|
2019-04-30 16:14:24 +02:00
|
|
|
return !(!this.authentication.current());
|
|
|
|
}
|
|
|
|
|
2019-05-21 09:01:00 +02:00
|
|
|
public isAdmin(): boolean {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) {
|
|
|
|
if (principal.authorities.find(role => role === AppRole.Admin)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
this.authentication.logout();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
position: { top: '64px', right: '1em' }
|
|
|
|
});
|
|
|
|
}
|
2019-04-24 11:26:53 +02:00
|
|
|
}
|