major refactoring
added universal added api
This commit is contained in:
parent
2bea201bb3
commit
a4542f7abd
52 changed files with 2851 additions and 313 deletions
52
src/app/status/status.component.ts
Normal file
52
src/app/status/status.component.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core';
|
||||
import {ApiService} from "../_service/api.service";
|
||||
import {Group} from "../_data/data";
|
||||
import {interval, Subject} from "rxjs";
|
||||
import {flatMap, startWith, takeUntil} from "rxjs/operators";
|
||||
import {DOCUMENT, isPlatformBrowser} from "@angular/common";
|
||||
|
||||
// import {DOCUMENT} from "@angular/common";
|
||||
|
||||
@Component({
|
||||
selector: 'app-status',
|
||||
templateUrl: './status.component.html',
|
||||
styleUrls: ['./status.component.scss']
|
||||
})
|
||||
export class StatusComponent implements OnInit, OnDestroy {
|
||||
readonly stateClasses = {
|
||||
"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'
|
||||
};
|
||||
|
||||
destroyed$ = new Subject();
|
||||
groups: Group[];
|
||||
lastUpdated: Date;
|
||||
|
||||
constructor(private api: ApiService, @Inject(PLATFORM_ID) private platformId: Object,
|
||||
@Inject(DOCUMENT) private document: Document) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
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`;
|
||||
}
|
||||
this.groups = response.groups;
|
||||
this.lastUpdated = new Date();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroyed$.next();
|
||||
this.destroyed$.complete();
|
||||
}
|
||||
}
|
Reference in a new issue