major refactoring
added universal added api
This commit is contained in:
parent
2bea201bb3
commit
a4542f7abd
52 changed files with 2851 additions and 313 deletions
24
src/app/status/status.component.html
Normal file
24
src/app/status/status.component.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
<mat-accordion [multi]="true">
|
||||
<mat-expansion-panel *ngFor="let group of groups" [expanded]="true">
|
||||
<mat-expansion-panel-header>
|
||||
<mat-panel-title><i [class]="stateClasses[group.state]"></i> {{group.name}}</mat-panel-title>
|
||||
<!-- <mat-panel-description>-->
|
||||
<!-- <span class="text-capitalize">{{getGroupState(group.services)}}</span>-->
|
||||
<!-- </mat-panel-description>-->
|
||||
</mat-expansion-panel-header>
|
||||
|
||||
<mat-list>
|
||||
<a *ngFor="let service of group.services; last as last" mat-list-item [href]="service.url" target="_blank">
|
||||
<div matLine class="d-flex">
|
||||
<i [class]="stateClasses[service.state]"></i>
|
||||
<span>{{service.name}}</span>
|
||||
<span class="flex-grow-1"></span>
|
||||
<span class="text-capitalize {{service.state}}">{{service.state}}</span>
|
||||
</div>
|
||||
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
|
||||
</a>
|
||||
</mat-list>
|
||||
</mat-expansion-panel>
|
||||
</mat-accordion>
|
||||
|
||||
<div class="text-right mt-3"><small>Last updated {{lastUpdated | date:'HH:mm:ss'}}</small></div>
|
22
src/app/status/status.component.scss
Normal file
22
src/app/status/status.component.scss
Normal file
|
@ -0,0 +1,22 @@
|
|||
.operational {
|
||||
color: #7ed321;
|
||||
}
|
||||
|
||||
.outage {
|
||||
color: #ff6f6f;
|
||||
}
|
||||
|
||||
.maintenance {
|
||||
color: #f7ca18;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
mat-panel-title {
|
||||
.fa, .fas, .far, .fal, .fad, .fab {
|
||||
line-height: inherit;
|
||||
}
|
||||
}
|
25
src/app/status/status.component.spec.ts
Normal file
25
src/app/status/status.component.spec.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { StatusComponent } from './status.component';
|
||||
|
||||
describe('StatusComponent', () => {
|
||||
let component: StatusComponent;
|
||||
let fixture: ComponentFixture<StatusComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ StatusComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(StatusComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
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