Added Login, TTS Login, Policies
This commit is contained in:
@ -1,15 +1,13 @@
|
||||
import { CommonModule, DatePipe, isPlatformBrowser } from '@angular/common';
|
||||
import { Component, OnInit, Inject, PLATFORM_ID, NgZone, OnDestroy } from '@angular/core';
|
||||
import { Router, RouterModule, RouterOutlet, Routes } from '@angular/router';
|
||||
import { Router, RouterOutlet } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms'
|
||||
import { HermesClientService } from './hermes-client.service';
|
||||
import { AuthGuard } from './shared/auth/auth.guard'
|
||||
import { Subscription } from 'rxjs';
|
||||
import { Policy, PolicyScope } from './shared/models/policy';
|
||||
import { PolicyComponent } from "./policy/policy.component";
|
||||
import { NavigationComponent } from "./navigation/navigation.component";
|
||||
import EventService from './shared/services/EventService';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ApiAuthenticationService } from './shared/services/api/api-authentication.service';
|
||||
|
||||
@Component({
|
||||
@ -23,13 +21,14 @@ import { ApiAuthenticationService } from './shared/services/api/api-authenticati
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
private isBrowser: boolean;
|
||||
private ngZone: NgZone;
|
||||
private subscription: Subscription | undefined;
|
||||
private subscriptions: Subscription[];
|
||||
pipe = new DatePipe('en-US')
|
||||
|
||||
|
||||
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private http: HttpClient, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
|
||||
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private router: Router, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
|
||||
this.ngZone = ngZone;
|
||||
this.isBrowser = isPlatformBrowser(this.platformId)
|
||||
this.isBrowser = isPlatformBrowser(this.platformId);
|
||||
this.subscriptions = [];
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@ -38,13 +37,30 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.auth.update();
|
||||
|
||||
const rand = Math.random() * 100000 | 0;
|
||||
this.client.subscribe(4, (data) => console.log("Request ack received", rand, data));
|
||||
|
||||
this.addSubscription(this.events.listen('logoff', (message) => {
|
||||
localStorage.removeItem('jwt');
|
||||
if (!document.location.href.includes('/login')) {
|
||||
this.router.navigate(['/login?warning=' + message]);
|
||||
}
|
||||
}));
|
||||
|
||||
this.addSubscription(this.events.listen('login', (_) => {
|
||||
if (document.location.href.includes('/login')) {
|
||||
this.router.navigate(['/tts-login']);
|
||||
}
|
||||
}));
|
||||
|
||||
this.client.connect();
|
||||
this.ngZone.runOutsideAngular(() => setInterval(() => this.client.heartbeat(), 15000));
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
for (let s of this.subscriptions) {
|
||||
s.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
private addSubscription(s: Subscription) {
|
||||
this.subscriptions.push(s);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user