-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathnavbar.component.js
63 lines (57 loc) · 1.95 KB
/
navbar.component.js
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
import { Component } from '@angular/core';
<%_ if (filters.auth) { -%>
<%_ if (filters.uirouter) { -%>
import { StateService } from 'ui-router-ng2';<% } %>
<%_ if (filters.ngroute) { -%>
import { Router } from '@angular/router';<% } %>
import { AuthService } from '../auth/auth.service';<% } %>
import template from './navbar.html';
@Component({
selector: 'navbar',
template,
})
export class NavbarComponent {
isCollapsed = true;
menu = [{
title: 'Home',
<% if(filters.uirouter) { %>'state': 'main'<% } else { %>'link': '/home'<% } %>,
}];
<%_ if(filters.ngroute) { -%>
Router;<% } %>
<%_ if(filters.auth) { -%>
isAdmin;
isLoggedIn;
currentUser = {};
AuthService;
static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } else { %>, Router<% } %>];
constructor(<%= private() %>authService: AuthService<% if(filters.uirouter) { %>, <%= private() %>stateService: StateService<% } else { %>, <%= private() %>router: Router<% } %>) {
this.AuthService = authService;
<%_ if(filters.uirouter) { -%>
this.StateService = stateService;<% } %>
<%_ if(filters.ngroute) { -%>
this.Router = router;<% } %>
this.reset();
this.AuthService.currentUserChanged.subscribe(user => {
this.currentUser = user;
this.reset();
});
}
reset() {
this.AuthService.isLoggedIn().then(is => {
this.isLoggedIn = is;
});
this.AuthService.isAdmin().then(is => {
this.isAdmin = is;
});
this.AuthService.getCurrentUser().then(user => {
this.currentUser = user;
});
}
logout() {
return this.AuthService.logout().then(() => {<% if(filters.uirouter) { %>
this.StateService.go('login');<% } %><% if(filters.ngroute) { %>
this.Router.navigateByUrl('/home');<% } %>
this.reset();
});
}<% } -%>
}