2022-04-07 00:09:49 +02:00
|
|
|
export interface Icon {
|
|
|
|
name?: string,
|
|
|
|
svg?: string,
|
|
|
|
class?: string
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
export class MenuItem {
|
2022-01-05 15:41:49 +01:00
|
|
|
_id: string = ""; // for root menu in order to close the dropdown when clicked
|
2019-04-22 12:32:25 +02:00
|
|
|
title: string = "";
|
2022-01-11 11:05:40 +01:00
|
|
|
type: string = "internal";
|
2019-04-22 12:32:25 +02:00
|
|
|
url: string = ""; // external url
|
|
|
|
route: string = ""; // internal url - using angular routing and components
|
2021-01-22 19:09:44 +01:00
|
|
|
routeActive: string = ""; // route to check if it is active
|
2019-04-22 12:32:25 +02:00
|
|
|
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 = {};
|
2020-09-15 15:53:18 +02:00
|
|
|
fragment: string;
|
2019-12-23 13:52:26 +01:00
|
|
|
items: MenuItem[] = [];
|
2022-04-07 00:09:49 +02:00
|
|
|
icon: Icon;
|
2019-12-23 13:52:26 +01:00
|
|
|
open: boolean;
|
2020-10-31 16:44:19 +01:00
|
|
|
customClass: string = null;
|
2022-03-02 11:26:28 +01:00
|
|
|
isFeatured: boolean;
|
2022-06-29 12:56:19 +02:00
|
|
|
target: string = "_blank";
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2022-06-29 12:56:19 +02:00
|
|
|
constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[],
|
|
|
|
routeRequired: string[], params, icon: Icon = null, fragment = null, customClass = null, routeActive = null,
|
2022-09-20 17:00:19 +02:00
|
|
|
target: string = "_blank", type: string = "internal", isFeatured: boolean = false, items: MenuItem[] = []) {
|
2022-01-05 15:41:49 +01:00
|
|
|
this._id = id;
|
2019-04-22 12:32:25 +02:00
|
|
|
this.title = title;
|
|
|
|
this.url = url;
|
|
|
|
this.route = route;
|
2021-01-22 19:09:44 +01:00
|
|
|
this.routeActive = routeActive;
|
2019-04-22 12:32:25 +02:00
|
|
|
this.needsAuthorization = needsAuthorization;
|
|
|
|
this.entitiesRequired = entitiesRequired;
|
|
|
|
this.routeRequired = routeRequired;
|
|
|
|
this.params = params;
|
2022-09-20 17:00:19 +02:00
|
|
|
this.items = items;
|
2020-06-04 13:21:32 +02:00
|
|
|
this.icon = icon;
|
2020-09-15 15:53:18 +02:00
|
|
|
this.fragment = fragment;
|
2020-10-31 16:44:19 +01:00
|
|
|
this.customClass = customClass;
|
2022-06-29 12:56:19 +02:00
|
|
|
this.target = target;
|
|
|
|
this.type = type;
|
|
|
|
this.isFeatured = isFeatured;
|
2019-06-25 15:26:24 +02:00
|
|
|
}
|
2019-12-23 13:52:26 +01:00
|
|
|
|
2022-03-28 10:40:21 +02:00
|
|
|
public static isTheActiveMenu(menu: MenuItem, currentRoute: any, activeMenuItem: string=""): boolean {
|
|
|
|
if(menu.route && menu.route.length > 0 && MenuItem.isTheActiveMenuItem(menu, currentRoute, activeMenuItem)) {
|
2019-12-23 13:52:26 +01:00
|
|
|
return true;
|
2022-03-28 10:40:21 +02:00
|
|
|
} else if(menu.items.length > 0) {
|
|
|
|
for(let menuItem of menu.items) {
|
|
|
|
if(MenuItem.isTheActiveMenuItem(menuItem, currentRoute, activeMenuItem)) {
|
2019-12-23 13:52:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2022-03-28 10:40:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static isTheActiveMenuItem(menu: MenuItem, currentRoute: any, activeMenuItem: string) {
|
|
|
|
return (
|
|
|
|
((menu.route == currentRoute.route || menu.route == (currentRoute.route + "/")) && currentRoute.fragment == menu.fragment))
|
2022-06-26 22:30:54 +02:00
|
|
|
|| (menu.routeActive && (currentRoute.route.startsWith(menu.routeActive)))
|
2022-03-28 10:40:21 +02:00
|
|
|
|| (menu._id && menu._id === activeMenuItem);
|
2019-12-23 13:52:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-22 12:32:25 +02:00
|
|
|
}
|
2022-07-15 12:28:55 +02:00
|
|
|
export class MenuItemExtended extends MenuItem {
|
|
|
|
isOpen: boolean = false;
|
|
|
|
parentItemId: string;
|
|
|
|
}
|
2019-04-22 12:32:25 +02:00
|
|
|
|
2022-07-15 12:36:55 +02:00
|
|
|
export class Menu {
|
|
|
|
portalPid: string;
|
|
|
|
isFeaturedMenuEnabled: boolean;
|
|
|
|
isMenuEnabled: boolean;
|
|
|
|
featuredMenuItems: MenuItemExtended[] = [];
|
|
|
|
menuItems: MenuItemExtended[] = [];
|
|
|
|
}
|
|
|
|
|
2022-09-20 17:00:19 +02:00
|
|
|
export class SideMenuItem extends MenuItem {
|
2019-04-22 12:32:25 +02:00
|
|
|
ukIcon: string = '';
|
|
|
|
}
|