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

    
15
  constructor(id: string, title: string, url: string, route: string, needsAuthorization: boolean, entitiesRequired: string[], routeRequired: string[], params, icon=null) {
16
    this.id = id;
17
    this.title = title;
18
    this.url = url;
19
    this.route = route;
20
    this.needsAuthorization = needsAuthorization;
21
    this.entitiesRequired = entitiesRequired;
22
    this.routeRequired = routeRequired;
23
    this.params = params;
24
    this.markAsActive = true;
25
    this.items = [];
26
    this.icon = icon;
27
  }
28

    
29
  public setMarkAsActive(showActive: boolean) {
30
    this.markAsActive = showActive;
31
  }
32

    
33
  public static isTheActiveMenu(menu: MenuItem, currentRoute: string): boolean {
34
    if (!menu.markAsActive) {
35
      return false;
36
    }
37
    if (currentRoute == menu.route) {
38
      return true;
39
    } else if (menu.items.length > 0) {
40
      for (let menuItem of menu.items) {
41
        if (menuItem.route == currentRoute) {
42
          return true;
43
        }
44
      }
45
    }
46
    return false;
47
  }
48

    
49

    
50
}
51

    
52
export class RootMenuItem {
53
  rootItem: MenuItem;
54
  items: MenuItem[] = [];
55

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

    
74
export class SideMenuItem {
75
  rootItem: MenuItem;
76
  items: RootMenuItem[] = [];
77
  ukIcon: string = '';
78
}
(4-4/9)