Project

General

Profile

1
export class MenuItem {
2
  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
  routeActive: string = ""; // route to check if it is active
7
  needsAuthorization: boolean = false; // needs admin rights - mainly for user menu at this point
8
  entitiesRequired: string[] = []; // openaire entities used in page "publication, dataset, organization, software, project, datasource"
9
  routeRequired: string[] = []; // the routes that if aren't enable the menu item doesn't make sense
10
  params: any = {};
11
  fragment: string;
12
  markAsActive: boolean;
13
  items: MenuItem[] = [];
14
  icon: string;
15
  open: boolean;
16
  customClass: string = null;
17

    
18
  constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params, icon=null, fragment = null, customClass = null, routeActive = null) {
19
    this.id = id;
20
    this.title = title;
21
    this.url = url;
22
    this.route = route;
23
    this.routeActive = routeActive;
24
    this.needsAuthorization = needsAuthorization;
25
    this.entitiesRequired = entitiesRequired;
26
    this.routeRequired = routeRequired;
27
    this.params = params;
28
    this.markAsActive = true;
29
    this.items = [];
30
    this.icon = icon;
31
    this.fragment = fragment;
32
    this.customClass = customClass;
33
  }
34

    
35
  public setMarkAsActive(showActive: boolean) {
36
    this.markAsActive = showActive;
37
  }
38

    
39
  public static isTheActiveMenu(menu: MenuItem, currentRoute: string): boolean {
40
    if (!menu.markAsActive) {
41
      return false;
42
    }
43
    if (menu.route.length > 0 && ((menu.routeActive && currentRoute.includes(menu.routeActive)) || currentRoute == menu.route)) {
44
      return true;
45
    } else if (menu.items.length > 0) {
46
      for (let menuItem of menu.items) {
47
        if (menuItem.route == currentRoute  || currentRoute.indexOf(menuItem.route) != -1) {
48
          return true;
49
        }
50
      }
51
    }
52
    return false;
53
  }
54

    
55

    
56
}
57

    
58
export class RootMenuItem {
59
  rootItem: MenuItem;
60
  items: MenuItem[] = [];
61

    
62
  public static isTheActiveRootMenu(menu: RootMenuItem, currentRoute: string): boolean {
63
    if (!menu.rootItem.markAsActive) {
64
      return false;
65
    }
66
    if (currentRoute == menu.rootItem.route) {
67
      return true;
68
    } else if (menu.items.length > 0) {
69
      for (let menuItem of menu.items) {
70
        let isActive = MenuItem.isTheActiveMenu(menuItem, currentRoute);
71
        if (isActive) {
72
          return true;
73
        }
74
      }
75
      return false;
76
    }
77
  }
78
}
79

    
80
export class SideMenuItem {
81
  rootItem: MenuItem;
82
  items: RootMenuItem[] = [];
83
  ukIcon: string = '';
84
}
(4-4/7)