From 2ee6cb2b4a7ba610862e0d39b13eb757cd95ac8d Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Tue, 15 Oct 2019 18:10:55 -0400 Subject: [PATCH] Add power display widget --- Display/src/app/app.module.ts | 4 ++- .../dashboard/dashboard.component.html | 10 +++++++ .../dashboard/dashboard.component.ts | 17 ++++++----- .../app/components/power/power.component.html | 25 +++++++++++++++++ .../app/components/power/power.component.scss | 10 +++++++ .../components/power/power.component.spec.ts | 25 +++++++++++++++++ .../app/components/power/power.component.ts | 17 +++++++++++ Display/src/app/models/power/power-status.ts | 4 +++ .../src/app/services/power/power.service.ts | 28 +++++++++++++++++++ 9 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 Display/src/app/components/power/power.component.html create mode 100644 Display/src/app/components/power/power.component.scss create mode 100644 Display/src/app/components/power/power.component.spec.ts create mode 100644 Display/src/app/components/power/power.component.ts create mode 100644 Display/src/app/models/power/power-status.ts create mode 100644 Display/src/app/services/power/power.service.ts diff --git a/Display/src/app/app.module.ts b/Display/src/app/app.module.ts index 800fd69..1a21456 100644 --- a/Display/src/app/app.module.ts +++ b/Display/src/app/app.module.ts @@ -22,6 +22,7 @@ import { DashboardComponent } from './components/dashboard/dashboard.component'; import { WeatherChartsComponent } from './components/weather/charts/weather-charts.component'; import { WeatherCurrentComponent } from './components/weather/current/weather-current.component'; import { AlmanacComponent } from './components/weather/almanac/almanac.component'; +import { PowerComponent } from './components/power/power.component'; const config: SocketIoConfig = { url: '/', options: {} }; @@ -33,7 +34,8 @@ const config: SocketIoConfig = { url: '/', options: {} }; DashboardComponent, WeatherChartsComponent, WeatherCurrentComponent, - AlmanacComponent + AlmanacComponent, + PowerComponent ], imports: [ BrowserModule, diff --git a/Display/src/app/components/dashboard/dashboard.component.html b/Display/src/app/components/dashboard/dashboard.component.html index dda3c6a..4873d2e 100644 --- a/Display/src/app/components/dashboard/dashboard.component.html +++ b/Display/src/app/components/dashboard/dashboard.component.html @@ -40,5 +40,15 @@ + +
+
+ Power +
+
+ +
+
+
diff --git a/Display/src/app/components/dashboard/dashboard.component.ts b/Display/src/app/components/dashboard/dashboard.component.ts index 5853ab9..6e3d4a2 100644 --- a/Display/src/app/components/dashboard/dashboard.component.ts +++ b/Display/src/app/components/dashboard/dashboard.component.ts @@ -13,11 +13,12 @@ export class DashboardComponent implements OnInit { public locked = true; private defaultLayout: DashboardLayout = { - version: 3, + version: 1, layout: [ - { cols: 3, rows: 2, y: 0, x: 0 }, - { cols: 2, rows: 2, y: 0, x: 3 }, - { cols: 3, rows: 2, y: 0, x: 5 } + { cols: 5, rows: 4, y: 0, x: 0 }, + { cols: 3, rows: 2, y: 0, x: 5 }, + { cols: 5, rows: 4, y: 0, x: 8 }, + { cols: 3, rows: 2, y: 2, x: 5 } ] }; @@ -34,9 +35,11 @@ export class DashboardComponent implements OnInit { enabled: !this.locked }, gridType: 'fixed', - fixedColWidth: 105, - fixedRowHeight: 105, - displayGrid: 'none' + fixedColWidth: 55, + fixedRowHeight: 55, + displayGrid: 'none', + minCols: 50, + minRows: 50 }; this.loadOptions(); diff --git a/Display/src/app/components/power/power.component.html b/Display/src/app/components/power/power.component.html new file mode 100644 index 0000000..7279f65 --- /dev/null +++ b/Display/src/app/components/power/power.component.html @@ -0,0 +1,25 @@ +
+
+ Loading... +
+
+ + + + + + + + + +
+ Generation + + {{ latestStatus.Generation < 0 ? 0 : latestStatus.Generation }} +
+ Consumption + + {{ latestStatus.Consumption < 0 ? 0 : latestStatus.Consumption }} +
+
+
diff --git a/Display/src/app/components/power/power.component.scss b/Display/src/app/components/power/power.component.scss new file mode 100644 index 0000000..c5f92da --- /dev/null +++ b/Display/src/app/components/power/power.component.scss @@ -0,0 +1,10 @@ +.power-current { + font-size: 14px; + padding: 10px; +} + +.power-current-header { + font-weight: 500; + text-align: right; + padding-right: 10px; +} diff --git a/Display/src/app/components/power/power.component.spec.ts b/Display/src/app/components/power/power.component.spec.ts new file mode 100644 index 0000000..1eb5da3 --- /dev/null +++ b/Display/src/app/components/power/power.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PowerComponent } from './power.component'; + +describe('PowerComponent', () => { + let component: PowerComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [PowerComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(PowerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/Display/src/app/components/power/power.component.ts b/Display/src/app/components/power/power.component.ts new file mode 100644 index 0000000..c21fd0b --- /dev/null +++ b/Display/src/app/components/power/power.component.ts @@ -0,0 +1,17 @@ +import { Component, OnInit } from '@angular/core'; +import { PowerService } from '../../services/power/power.service'; +import { PowerStatus } from '../../models/power/power-status'; + +@Component({ + selector: 'app-power', + templateUrl: './power.component.html', + styleUrls: ['./power.component.scss'] +}) +export class PowerComponent implements OnInit { + public latestStatus: PowerStatus; + constructor(private powerService: PowerService) { } + + ngOnInit() { + this.powerService.getLatestStatus().subscribe(s => this.latestStatus = s); + } +} diff --git a/Display/src/app/models/power/power-status.ts b/Display/src/app/models/power/power-status.ts new file mode 100644 index 0000000..605af87 --- /dev/null +++ b/Display/src/app/models/power/power-status.ts @@ -0,0 +1,4 @@ +export class PowerStatus { + generation = 0; + consumption = 0; +} diff --git a/Display/src/app/services/power/power.service.ts b/Display/src/app/services/power/power.service.ts new file mode 100644 index 0000000..1e10069 --- /dev/null +++ b/Display/src/app/services/power/power.service.ts @@ -0,0 +1,28 @@ +import { Injectable } from '@angular/core'; +import { Observable, BehaviorSubject } from 'rxjs'; +import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr'; +import { PowerStatus } from 'src/app/models/power/power-status'; + +@Injectable({ + providedIn: 'root' +}) +export class PowerService { + private connection: HubConnection; + private latestStatus: BehaviorSubject = new BehaviorSubject(null); + + constructor() { + this.connection = new HubConnectionBuilder() + .withUrl('/api/hub/power') + .build(); + + this.connection.on('LatestSample', (message: string) => { + this.latestStatus.next(JSON.parse(message)); + }); + + this.connection.start(); + } + + getLatestStatus(): Observable { + return this.latestStatus.asObservable(); + } +}