From 8bdf409d076d445c682e93c7d22a093e825983cb Mon Sep 17 00:00:00 2001 From: Jesse Lucas Date: Tue, 17 Mar 2020 09:46:32 -0400 Subject: [PATCH] start of db status service --- .../device-chart/device-chart.component.ts | 2 +- .../donut-chart/donut-chart.component.ts | 2 -- .../folder-chart/folder-chart.component.ts | 4 +++ src/app/db-status.service.spec.ts | 16 ++++++++++ src/app/db-status.service.ts | 31 +++++++++++++++++++ src/app/system-config.service.ts | 7 ++--- 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 src/app/db-status.service.spec.ts create mode 100644 src/app/db-status.service.ts diff --git a/src/app/chart/device-chart/device-chart.component.ts b/src/app/chart/device-chart/device-chart.component.ts index 1899b7217..cf8bccac1 100644 --- a/src/app/chart/device-chart/device-chart.component.ts +++ b/src/app/chart/device-chart/device-chart.component.ts @@ -15,7 +15,7 @@ export class DeviceChartComponent implements OnInit { constructor(private systemConfigService: SystemConfigService) { } ngOnInit(): void { - this.systemConfigService.getFolders().subscribe( + this.systemConfigService.getDevices().subscribe( data => { this.data = [0, 230, 32, 40]; } diff --git a/src/app/chart/donut-chart/donut-chart.component.ts b/src/app/chart/donut-chart/donut-chart.component.ts index f2cbfadd0..19fa01147 100644 --- a/src/app/chart/donut-chart/donut-chart.component.ts +++ b/src/app/chart/donut-chart/donut-chart.component.ts @@ -14,7 +14,6 @@ export class DonutChartComponent { val.forEach((v) => { this.addData(v) }); - console.log("set the data?", val) } }; @@ -34,7 +33,6 @@ export class DonutChartComponent { ngAfterViewInit(): void { - console.log("is the data set?", this.data, this.elementID); this.canvas = document.getElementById(this.elementID); this.ctx = this.canvas.getContext('2d'); this.chart = new Chart(this.ctx, { diff --git a/src/app/chart/folder-chart/folder-chart.component.ts b/src/app/chart/folder-chart/folder-chart.component.ts index 8f5d90807..cc1aedffa 100644 --- a/src/app/chart/folder-chart/folder-chart.component.ts +++ b/src/app/chart/folder-chart/folder-chart.component.ts @@ -16,11 +16,15 @@ export class FolderChartComponent implements OnInit { constructor(private systemConfigService: SystemConfigService) { } ngOnInit(): void { + // Find total number of folders this.systemConfigService.getFolders().subscribe( data => { this.data = [0, 1, 32, 40]; } ); + + // Sequentially look up each folder to get status + // dbStatusService } /* ngAfterViewInit() { diff --git a/src/app/db-status.service.spec.ts b/src/app/db-status.service.spec.ts new file mode 100644 index 000000000..d5d0a16c6 --- /dev/null +++ b/src/app/db-status.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { DbStatusService } from './db-status.service'; + +describe('DbStatusService', () => { + let service: DbStatusService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(DbStatusService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/db-status.service.ts b/src/app/db-status.service.ts new file mode 100644 index 000000000..5e8e05769 --- /dev/null +++ b/src/app/db-status.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { CookieService } from './cookie.service'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { environment } from '../environments/environment' +import { apiURL } from './api-utils' + +@Injectable({ + providedIn: 'root' +}) +export class DbStatusService { + private httpOptions: any; + private dbStatusUrl = environment.production ? apiURL + 'rest/db/status' : 'api/dbStatus'; + + constructor(private http: HttpClient, private cookieService: CookieService) { + this.httpOptions = { headers: new HttpHeaders(this.cookieService.getCSRFHeader()) }; + } + + getFolderStatus(id: string): Observable { + return this.http + .get(this.dbStatusUrl, this.httpOptions) + .pipe(map(res => { + // TODO update folder in system-config service + return res; + }) + ); + } +} diff --git a/src/app/system-config.service.ts b/src/app/system-config.service.ts index 1869184a2..c4bdd7f64 100644 --- a/src/app/system-config.service.ts +++ b/src/app/system-config.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; -import { Observable, Subject, of } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { map } from 'rxjs/operators'; import { Folder } from './folder'; @@ -14,14 +14,13 @@ import { apiURL } from './api-utils' providedIn: 'root' }) export class SystemConfigService { - private systemConfig: any; private folders: Folder[]; private devices: Device[]; private foldersSubject: Subject = new Subject(); private devicesSubject: Subject = new Subject(); private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config'; - private httpOptions; + private httpOptions: any; private checkInterval: number = 100; @@ -33,8 +32,6 @@ export class SystemConfigService { return this.http .get(this.systemConfigUrl, this.httpOptions) .pipe(map(res => { - this.systemConfig = res; - this.folders = res['folders']; this.devices = res['devices']; this.foldersSubject.next(this.folders);