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
  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
  fragment: string;
11
  markAsActive: boolean;
12
  items: MenuItem[] = [];
13
  icon: string;
14
  open: boolean;
15
  customClass: string = null;
16

    
17
  constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params, icon=null, fragment = null, customClass = null) {
18
    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
    this.markAsActive = true;
27
    this.items = [];
28
    this.icon = icon;
29
    this.fragment = fragment;
30
    this.customClass = customClass;
31
  }
32

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

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

    
53

    
54
}
55

    
56
export class RootMenuItem {
57
  rootItem: MenuItem;
58
  items: MenuItem[] = [];
59

    
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
}
77

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