2018-02-05 14:14:59 +01:00
|
|
|
export class MenuItem {
|
2019-04-22 12:32:25 +02:00
|
|
|
id: string = ""; // for root menu in order to close the dropdown when clicked
|
|
|
|
title: string = "";
|
|
|
|
url: string = ""; // external url
|
|
|
|
route: string = ""; // internal url - using angular routing and components
|
|
|
|
needsAuthorization: boolean = false; // needs admin rights - mainly for user menu at this point
|
|
|
|
entitiesRequired: string[] = []; // openaire entities used in page "publication, dataset, organization, software, project, datasource"
|
|
|
|
routeRequired: string[] = []; // the routes that if aren't enable the menu item doesn't make sense
|
|
|
|
params: any = {};
|
2019-12-23 13:52:26 +01:00
|
|
|
markAsActive: boolean;
|
|
|
|
items: MenuItem[] = [];
|
|
|
|
icon: string;
|
|
|
|
open: boolean;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2020-06-04 13:21:32 +02:00
|
|
|
constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params, icon=null) {
|
2019-04-22 12:32:25 +02:00
|
|
|
this.id = id;
|
|
|
|
this.title = title;
|
|
|
|
this.url = url;
|
|
|
|
this.route = route;
|
|
|
|
this.needsAuthorization = needsAuthorization;
|
|
|
|
this.entitiesRequired = entitiesRequired;
|
|
|
|
this.routeRequired = routeRequired;
|
|
|
|
this.params = params;
|
2019-06-25 15:26:24 +02:00
|
|
|
this.markAsActive = true;
|
2019-12-23 13:52:26 +01:00
|
|
|
this.items = [];
|
2020-06-04 13:21:32 +02:00
|
|
|
this.icon = icon;
|
2019-06-25 15:26:24 +02:00
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
|
|
|
|
public setMarkAsActive(showActive: boolean) {
|
2019-06-25 15:26:24 +02:00
|
|
|
this.markAsActive = showActive;
|
2018-02-05 14:14:59 +01:00
|
|
|
}
|
2019-04-22 12:32:25 +02:00
|
|
|
|
2019-12-23 13:52:26 +01:00
|
|
|
public static isTheActiveMenu(menu: MenuItem, currentRoute: string): boolean {
|
|
|
|
if (!menu.markAsActive) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-17 13:03:39 +02:00
|
|
|
if (currentRoute == menu.route || currentRoute.indexOf(menu.route) != -1) {
|
2019-12-23 13:52:26 +01:00
|
|
|
return true;
|
|
|
|
} else if (menu.items.length > 0) {
|
|
|
|
for (let menuItem of menu.items) {
|
2020-08-17 13:03:39 +02:00
|
|
|
if (menuItem.route == currentRoute || currentRoute.indexOf(menuItem.route) != -1) {
|
2019-12-23 13:52:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 12:32:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class RootMenuItem {
|
|
|
|
rootItem: MenuItem;
|
|
|
|
items: MenuItem[] = [];
|
2019-12-23 13:52:26 +01:00
|
|
|
|
|
|
|
public static isTheActiveRootMenu(menu: RootMenuItem, currentRoute: string): boolean {
|
|
|
|
if (!menu.rootItem.markAsActive) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (currentRoute == menu.rootItem.route) {
|
|
|
|
return true;
|
|
|
|
} else if (menu.items.length > 0) {
|
|
|
|
for (let menuItem of menu.items) {
|
|
|
|
let isActive = MenuItem.isTheActiveMenu(menuItem, currentRoute);
|
|
|
|
if (isActive) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 12:32:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class SideMenuItem {
|
|
|
|
rootItem: MenuItem;
|
|
|
|
items: RootMenuItem[] = [];
|
|
|
|
ukIcon: string = '';
|
|
|
|
}
|