Project

General

Profile

1 50586 argiro.kok
export class MenuItem {
2 55405 k.triantaf
  id: string = ""; // for root menu in order to close the dropdown when clicked
3
  title: string = "";
4
  url: string = ""; // external url
5
  route: string = ""; // internal  url - using angular routing and components
6
  needsAuthorization: boolean = false; // needs admin rights - mainly for user menu at this point
7
  entitiesRequired: string[] = []; // openaire entities used in page "publication, dataset, organization, software, project, datasource"
8
  routeRequired: string[] = []; // the routes that if aren't enable the menu item doesn't make sense
9
  params: any = {};
10 59388 k.triantaf
  fragment: string;
11 57935 argiro.kok
  markAsActive: boolean;
12
  items: MenuItem[] = [];
13
  icon: string;
14
  open: boolean;
15 59728 k.triantaf
  customClass: string = null;
16 50586 argiro.kok
17 59728 k.triantaf
  constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params, icon=null, fragment = null, customClass = null) {
18 55405 k.triantaf
    this.id = id;
19
    this.title = title;
20
    this.url = url;
21
    this.route = route;
22
    this.needsAuthorization = needsAuthorization;
23
    this.entitiesRequired = entitiesRequired;
24
    this.routeRequired = routeRequired;
25
    this.params = params;
26 56199 argiro.kok
    this.markAsActive = true;
27 57935 argiro.kok
    this.items = [];
28 58836 argiro.kok
    this.icon = icon;
29 59388 k.triantaf
    this.fragment = fragment;
30 59728 k.triantaf
    this.customClass = customClass;
31 50586 argiro.kok
  }
32 57935 argiro.kok
33
  public setMarkAsActive(showActive: boolean) {
34 56199 argiro.kok
    this.markAsActive = showActive;
35
  }
36 55405 k.triantaf
37 57935 argiro.kok
  public static isTheActiveMenu(menu: MenuItem, currentRoute: string): boolean {
38
    if (!menu.markAsActive) {
39
      return false;
40
    }
41 59788 argiro.kok
    if (menu.route.length > 0 && (currentRoute == menu.route  || currentRoute.indexOf(menu.route) != -1)) {
42 57935 argiro.kok
      return true;
43
    } else if (menu.items.length > 0) {
44
      for (let menuItem of menu.items) {
45 59288 argiro.kok
        if (menuItem.route == currentRoute  || currentRoute.indexOf(menuItem.route) != -1) {
46 57935 argiro.kok
          return true;
47
        }
48
      }
49
    }
50
    return false;
51
  }
52
53
54 55405 k.triantaf
}
55
56
export class RootMenuItem {
57
  rootItem: MenuItem;
58
  items: MenuItem[] = [];
59 57935 argiro.kok
60
  public static isTheActiveRootMenu(menu: RootMenuItem, currentRoute: string): boolean {
61
    if (!menu.rootItem.markAsActive) {
62
      return false;
63
    }
64
    if (currentRoute == menu.rootItem.route) {
65
      return true;
66
    } else if (menu.items.length > 0) {
67
      for (let menuItem of menu.items) {
68
        let isActive = MenuItem.isTheActiveMenu(menuItem, currentRoute);
69
        if (isActive) {
70
          return true;
71
        }
72
      }
73
      return false;
74
    }
75
  }
76 55405 k.triantaf
}
77
78
export class SideMenuItem {
79
  rootItem: MenuItem;
80
  items: RootMenuItem[] = [];
81
  ukIcon: string = '';
82
}