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