left-menu.component.ts
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {Component, OnInit} from '@angular/core';
import {MenuGroup} from '../models/menu-group.model';
import {MENU} from "../defines/menu";
import {ActivatedRoute, UrlSegment} from "@angular/router";
@Component({
selector: 'left-menu',
templateUrl: './left-menu.component.html',
styleUrls: ['./left-menu.component.scss']
})
export class LeftMenuComponent implements OnInit {
menu: MenuGroup[];
styleClass: string;
searchPath(path : string, menu : MenuGroup[]): boolean {
menu.forEach(group => {
group.items.forEach(item => {
if(path.startsWith(item.path)) {
return true;
}
});
});
return false;
}
constructor(private route: ActivatedRoute) {
this.route.url.subscribe(segments => {
let path : string = segments.map(segment => segment.path).join("/");
if(this.searchPath(path, MENU.USER)) {
this.activateUser();
return;
}
if(this.searchPath(path, MENU.INFO)) {
this.activateInfo();
return;
}
if(this.searchPath(path, MENU.ADMIN)) {
this.activateAdmin();
return;
}
});
}
ngOnInit() {
}
activateInfo() {
this.menu = MENU.INFO;
this.styleClass = "infoMenu";
}
activateUser() {
this.menu = MENU.USER;
this.styleClass = "userMenu";
}
activateAdmin() {
this.menu = MENU.ADMIN;
this.styleClass = "adminMenu";
}
}