2020-05-06 15:25:35 +00:00
|
|
|
import {Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core';
|
2021-01-10 15:06:18 +00:00
|
|
|
import {ApiService} from '../_service/api.service';
|
|
|
|
import {Group} from '../_data/data';
|
|
|
|
import {interval, Subject} from 'rxjs';
|
|
|
|
import {takeUntil} from 'rxjs/operators';
|
|
|
|
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
|
|
|
|
import {StorageService} from '../_service/storage.service';
|
2020-05-04 23:33:14 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-status',
|
|
|
|
templateUrl: './status.component.html',
|
|
|
|
styleUrls: ['./status.component.scss']
|
|
|
|
})
|
|
|
|
export class StatusComponent implements OnInit, OnDestroy {
|
|
|
|
readonly stateClasses = {
|
2021-01-10 15:06:18 +00:00
|
|
|
'operational': 'fas fa-fw fa-heart operational mr-2',
|
|
|
|
'outage': 'fas fa-fw fa-heart-broken outage mr-2',
|
|
|
|
'maintenance': 'fas fa-fw fa-heartbeat maintenance mr-2'
|
2020-05-04 23:33:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
destroyed$ = new Subject();
|
|
|
|
groups: Group[];
|
|
|
|
lastUpdated: Date;
|
2021-01-10 15:06:18 +00:00
|
|
|
expandedCache: { [id: string]: boolean };
|
2020-05-04 23:33:14 +00:00
|
|
|
|
2021-01-10 15:06:18 +00:00
|
|
|
constructor(private api: ApiService, private storage: StorageService,
|
|
|
|
@Inject(PLATFORM_ID) private platformId: Object,
|
2020-05-06 15:25:35 +00:00
|
|
|
@Inject(DOCUMENT) private document: Document) {
|
2021-01-10 15:06:18 +00:00
|
|
|
let cache = this.storage.getValue('expanded');
|
|
|
|
if (typeof cache !== 'object') {
|
|
|
|
cache = null;
|
|
|
|
}
|
|
|
|
this.expandedCache = cache || {};
|
2020-05-04 23:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-05-06 15:25:35 +00:00
|
|
|
this.update();
|
|
|
|
if (isPlatformBrowser(this.platformId)) {
|
|
|
|
interval(30000).pipe(takeUntil(this.destroyed$)).subscribe(() => this.update());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private update() {
|
|
|
|
this.api.getServiceStates().subscribe(response => {
|
|
|
|
if (isPlatformBrowser(this.platformId)) {
|
|
|
|
const favicon: HTMLLinkElement = document.getElementById('favicon') as HTMLLinkElement;
|
|
|
|
favicon.href = `favicon-${response.state}.ico`;
|
|
|
|
}
|
2020-05-04 23:33:14 +00:00
|
|
|
this.groups = response.groups;
|
|
|
|
this.lastUpdated = new Date();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.destroyed$.next();
|
|
|
|
this.destroyed$.complete();
|
|
|
|
}
|
2021-01-10 15:06:18 +00:00
|
|
|
|
|
|
|
saveExpandedCache() {
|
|
|
|
this.storage.setValue('expanded', this.expandedCache);
|
|
|
|
}
|
2020-05-04 23:33:14 +00:00
|
|
|
}
|