Newer
Older
import {Router} from "@angular/router";
import { NavigationEnd } from '@angular/router';
import {AuthService} from "./shared/auth/auth.service";
import {EventEmitterService} from "./shared/event.emitter.service";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'frontend';
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
isAdmin: boolean = false;
isLoggedIn: boolean = false;
url: string = '';
constructor(private router: Router, private authService: AuthService,
private eventEmitterService: EventEmitterService) {
// @ts-ignore
router.events.subscribe((event:Event) => {
if(event instanceof NavigationEnd ){
// @ts-ignore
this.url = event.url;
if(this.url === '/station'){
this.title = 'Stations';
} else if (this.url === '/station/client'){
this.title = 'Clients';
} else if (this.url === '/station/host'){
this.title = 'Hosts';
} else if (this.url === '/station/sensor'){
this.title = 'Sensors';
} else if (this.url === '/admin'){
this.title = 'Admin Page';
}
}
});
this.isAdmin = this.authService.isAdmin();
this.isLoggedIn = this.authService.isLoggedIn();
if (this.eventEmitterService.subVar == undefined) {
this.eventEmitterService.subVar = this.eventEmitterService.
invokeAppComponentFunction.subscribe((name:string) => {
this.checkLoggedInUser();
});
}
}
logout() {
localStorage.removeItem('token');
localStorage.removeItem('role');
this.isAdmin = false;
this.isLoggedIn = false;
this.router.navigate(['/login']);
}
private checkLoggedInUser() {
this.isAdmin = this.authService.isAdmin();
this.isLoggedIn = this.authService.isLoggedIn();
}
navigate(i: number) {
if(i === 0){
this.router.navigate(['/station']);
} else if (i === 1){
this.router.navigate(['/station/host']);
} else if (i === 2){
this.router.navigate(['/station/client']);
} else if (i === 3){
this.router.navigate(['/station/sensor']);
} else if (i === 4){
this.router.navigate(['/admin']);
} else if (i === 5){
this.router.navigate(['/']);