/
navbar.component.ts
112 lines (97 loc) · 3.98 KB
/
navbar.component.ts
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Router} from "@angular/router";
import {AuthService} from "../../services/auth.service";
import {DomainService} from "../../services/domain.service";
import {Subscription} from "rxjs";
import {NavbarService} from "./navbar.service";
import {SnackbarService} from "../../services/snackbar.service";
import * as _ from 'lodash';
import {SidenavService} from "../sidenav/sidenav.service";
import {EnvironmentService} from "../../services/environment.service";
import {MatSelectChange} from "@angular/material/select";
@Component({
selector: 'gv-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.scss']
})
export class NavbarComponent implements OnInit, OnDestroy {
private domainSubscription: Subscription;
private environmentSubscription: Subscription;
private sidenavSubscription: Subscription;
reducedMode = false;
domains: any[];
currentDomain: any = {};
navLinks: any[];
currentEnvironment;
constructor(private authService: AuthService,
private domainService: DomainService,
private navbarService: NavbarService,
private snackbarService: SnackbarService,
private sidenavService: SidenavService,
private environmentService: EnvironmentService,
public router: Router) {
}
ngOnInit() {
this.initNavLinks();
this.environmentSubscription = this.environmentService.currentEnvironmentObs$.subscribe(environment => {
this.currentEnvironment = environment;
this.initNavLinks();
});
this.domainSubscription = this.navbarService.currentDomainObs$.subscribe(data => {
this.currentDomain = data;
});
this.sidenavSubscription = this.sidenavService.resizeSidenavObservable.subscribe(reducedMode => this.reducedMode = reducedMode);
}
ngOnDestroy(): void {
this.environmentSubscription.unsubscribe();
this.domainSubscription.unsubscribe();
this.sidenavSubscription.unsubscribe();
}
get user() {
return this.authService.user() != null ? this.authService.user() : null;
}
listDomains() {
if(this.hasCurrentEnvironment()) {
this.domainService.findByEnvironment(0,5).subscribe(response => this.domains = response.data);
} else {
this.domains = [];
}
}
displayBreadcrumb(): boolean {
return !this.router.url.startsWith('/domains/new') &&
!this.router.url.startsWith('/login') &&
!this.router.url.startsWith('/logout') &&
!this.router.url.startsWith('/404');
}
private initNavLinks() {
this.navLinks = [];
if (this.hasCurrentEnvironment() && this.canDisplay(['domain_list'])) {
this.navLinks.push({'href': '/environments/' + this.currentEnvironment.hrids[0] + '/domains', 'label': 'All domains', 'icon': 'developer_board'});
}
if (this.hasCurrentEnvironment() && this.canDisplay(['domain_create'])) {
this.navLinks.push({'href': '/environments/' + this.currentEnvironment.hrids[0] + '/domains/new', 'label': 'Create domain', 'icon': 'add'});
}
this.navLinks.push({'href': '/logout', 'label': 'Sign out', 'icon': 'exit_to_app'});
}
hasCurrentEnvironment(): boolean {
return this.currentEnvironment && this.currentEnvironment !== EnvironmentService.NO_ENVIRONMENT;
}
private canDisplay(permissions): boolean {
return this.authService.hasPermissions(permissions);
}
}