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

100 lines
2.9 KiB
TypeScript
Raw Normal View History

2019-05-08 14:48:57 +02:00
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material';
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';
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-04-24 11:26:53 +02:00
}
export const GENERAL_ROUTES: RouteInfo[] = [
2019-05-08 17:24:30 +02:00
{ path: '/home', title: 'SIDE-BAR.DASHBOARD', icon: 'dashboard' }
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' },
{ path: '/datasets', title: 'SIDE-BAR.MY-DATASET-DESC', icon: 'library_books' },
{ path: '/projects', title: 'SIDE-BAR.MY-PROJECTS', icon: 'work_outline' }
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
// ];
export const PUBLIC_ROUTES: RouteInfo[] = [
2019-05-08 17:24:30 +02:00
{ path: '/explore', title: 'SIDE-BAR.PUBLIC-DESC', icon: 'public', },
{ path: '/explore-plans', title: 'SIDE-BAR.PUBLIC-DMPS', icon: 'public', }
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;
// historyItems: GroupMenuItem;
publicItems: GroupMenuItem;
groupMenuItems: GroupMenuItem[] = [];
2019-04-24 11:26:53 +02:00
2019-05-08 14:48:57 +02:00
constructor(public translate: TranslateService, private authentication: AuthService, private dialog: MatDialog) { }
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-10 15:20:53 +02:00
requiresAuthentication: false
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
2019-05-08 14:48:57 +02:00
}
this.groupMenuItems.push(this.dmpItems);
2019-04-24 11:26:53 +02:00
2019-05-08 14:48:57 +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-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
2019-05-08 14:48:57 +02:00
}
this.groupMenuItems.push(this.publicItems);
2019-04-24 11:26:53 +02:00
}
public principalHasAvatar(): boolean {
return this.authentication.current().avatarUrl != null;
}
public getPrincipalAvatar(): string {
return this.authentication.current().avatarUrl;
}
public isAuthenticated(): boolean {
return !(!this.authentication.current());
}
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
}