53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
|
import { Component, Inject, NgZone, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
|
||
|
import { PolicyAddFormComponent } from "../policy-add-form/policy-add-form.component";
|
||
|
import { PolicyTableComponent } from "../policy-table/policy-table.component";
|
||
|
import { Policy, PolicyScope } from '../shared/models/policy';
|
||
|
import { DatePipe, isPlatformBrowser } from '@angular/common';
|
||
|
import { OAuthService } from 'angular-oauth2-oidc';
|
||
|
import { Subscription } from 'rxjs';
|
||
|
import { HermesClientService } from '../hermes-client.service';
|
||
|
import { Router, RouterModule } from '@angular/router';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'policy',
|
||
|
standalone: true,
|
||
|
imports: [RouterModule, PolicyAddFormComponent, PolicyTableComponent],
|
||
|
templateUrl: './policy.component.html',
|
||
|
styleUrl: './policy.component.scss'
|
||
|
})
|
||
|
export class PolicyComponent implements OnInit, OnDestroy {
|
||
|
private isBrowser: boolean;
|
||
|
private ngZone: NgZone;
|
||
|
private subscription: Subscription | undefined;
|
||
|
items: Policy[];
|
||
|
pipe = new DatePipe('en-US')
|
||
|
|
||
|
|
||
|
constructor(private client: HermesClientService, private oauthService: OAuthService, private router: Router, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
|
||
|
this.ngZone = ngZone;
|
||
|
this.isBrowser = isPlatformBrowser(this.platformId)
|
||
|
|
||
|
this.items = []
|
||
|
}
|
||
|
|
||
|
get policies() {
|
||
|
return this.items;
|
||
|
}
|
||
|
|
||
|
ngOnInit(): void {
|
||
|
if (!this.isBrowser)
|
||
|
return;
|
||
|
|
||
|
if (!this.client.logged_in) {
|
||
|
this.router.navigate(["/tts-login"]);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
this.subscription = this.client.connect();
|
||
|
}
|
||
|
|
||
|
ngOnDestroy() {
|
||
|
if (this.subscription)
|
||
|
this.subscription.unsubscribe()
|
||
|
}
|
||
|
}
|