mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-29 09:35:40 -05:00
Add some initial web UI
This commit is contained in:
35
Display/src/app/app-routing.module.ts
Normal file
35
Display/src/app/app-routing.module.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { WeatherComponent } from './weather/weather.component';
|
||||
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||
import { LaundryComponent } from './laundry/laundry.component';
|
||||
import { WeatherChartsComponent } from './weather-charts/weather-charts.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: DashboardComponent
|
||||
},
|
||||
{
|
||||
path: 'dashboard',
|
||||
component: DashboardComponent
|
||||
},
|
||||
{
|
||||
path: 'weather',
|
||||
component: WeatherComponent
|
||||
},
|
||||
{
|
||||
path: 'weather/charts',
|
||||
component: WeatherChartsComponent
|
||||
},
|
||||
{
|
||||
path: 'laundry',
|
||||
component: LaundryComponent
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forRoot(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class AppRoutingModule { }
|
||||
28
Display/src/app/app.component.html
Normal file
28
Display/src/app/app.component.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<mat-toolbar color="primary">
|
||||
<mat-toolbar-row>
|
||||
<button mat-icon-button>
|
||||
<mat-icon (click)="sidenav.toggle()">menu</mat-icon>
|
||||
</button>
|
||||
<h1>Home Status</h1>
|
||||
<span class="menu-spacer"></span>
|
||||
<div>
|
||||
<a mat-button [routerLink]="'/dashboard'">Dashboard</a>
|
||||
<a mat-button [routerLink]="'/weather'">Weather</a>
|
||||
<a mat-button [routerLink]="'/laundry'">Laundry</a>
|
||||
</div>
|
||||
</mat-toolbar-row>
|
||||
</mat-toolbar>
|
||||
|
||||
<mat-sidenav-container>
|
||||
<mat-sidenav #sidenav mode="side" opened>
|
||||
<mat-nav-list>
|
||||
<a mat-list-item [routerLink]="'/weather'">Current</a>
|
||||
<a mat-list-item [routerLink]="'/weather/charts'">Charts</a>
|
||||
</mat-nav-list>
|
||||
</mat-sidenav>
|
||||
<mat-sidenav-content>
|
||||
<div style="height: 88vh;">
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
</mat-sidenav-content>
|
||||
</mat-sidenav-container>
|
||||
3
Display/src/app/app.component.scss
Normal file
3
Display/src/app/app.component.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
.menu-spacer {
|
||||
margin-right: 14px;
|
||||
}
|
||||
35
Display/src/app/app.component.spec.ts
Normal file
35
Display/src/app/app.component.spec.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule
|
||||
],
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create the app', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
});
|
||||
|
||||
it(`should have as title 'Display'`, () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app.title).toEqual('Display');
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.debugElement.nativeElement;
|
||||
expect(compiled.querySelector('.content span').textContent).toContain('Display app is running!');
|
||||
});
|
||||
});
|
||||
10
Display/src/app/app.component.ts
Normal file
10
Display/src/app/app.component.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.scss']
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'Home Status';
|
||||
}
|
||||
34
Display/src/app/app.module.ts
Normal file
34
Display/src/app/app.module.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { MatToolbarModule, MatIconModule, MatSidenavModule, MatListModule, MatButtonModule } from '@angular/material';
|
||||
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { AppComponent } from './app.component';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { WeatherComponent } from './weather/weather.component';
|
||||
import { LaundryComponent } from './laundry/laundry.component';
|
||||
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||
import { WeatherChartsComponent } from './weather-charts/weather-charts.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent,
|
||||
WeatherComponent,
|
||||
LaundryComponent,
|
||||
DashboardComponent,
|
||||
WeatherChartsComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
AppRoutingModule,
|
||||
BrowserAnimationsModule,
|
||||
MatToolbarModule,
|
||||
MatSidenavModule,
|
||||
MatListModule,
|
||||
MatButtonModule,
|
||||
MatIconModule
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
1
Display/src/app/dashboard/dashboard.component.html
Normal file
1
Display/src/app/dashboard/dashboard.component.html
Normal file
@@ -0,0 +1 @@
|
||||
<p>dashboard works!</p>
|
||||
0
Display/src/app/dashboard/dashboard.component.scss
Normal file
0
Display/src/app/dashboard/dashboard.component.scss
Normal file
25
Display/src/app/dashboard/dashboard.component.spec.ts
Normal file
25
Display/src/app/dashboard/dashboard.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DashboardComponent } from './dashboard.component';
|
||||
|
||||
describe('DashboardComponent', () => {
|
||||
let component: DashboardComponent;
|
||||
let fixture: ComponentFixture<DashboardComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ DashboardComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DashboardComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
15
Display/src/app/dashboard/dashboard.component.ts
Normal file
15
Display/src/app/dashboard/dashboard.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrls: ['./dashboard.component.scss']
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
1
Display/src/app/laundry/laundry.component.html
Normal file
1
Display/src/app/laundry/laundry.component.html
Normal file
@@ -0,0 +1 @@
|
||||
<p>laundry works!</p>
|
||||
0
Display/src/app/laundry/laundry.component.scss
Normal file
0
Display/src/app/laundry/laundry.component.scss
Normal file
25
Display/src/app/laundry/laundry.component.spec.ts
Normal file
25
Display/src/app/laundry/laundry.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LaundryComponent } from './laundry.component';
|
||||
|
||||
describe('LaundryComponent', () => {
|
||||
let component: LaundryComponent;
|
||||
let fixture: ComponentFixture<LaundryComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ LaundryComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(LaundryComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
15
Display/src/app/laundry/laundry.component.ts
Normal file
15
Display/src/app/laundry/laundry.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-laundry',
|
||||
templateUrl: './laundry.component.html',
|
||||
styleUrls: ['./laundry.component.scss']
|
||||
})
|
||||
export class LaundryComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<p>weather-charts works!</p>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WeatherChartsComponent } from './weather-charts.component';
|
||||
|
||||
describe('WeatherChartsComponent', () => {
|
||||
let component: WeatherChartsComponent;
|
||||
let fixture: ComponentFixture<WeatherChartsComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ WeatherChartsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(WeatherChartsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
15
Display/src/app/weather-charts/weather-charts.component.ts
Normal file
15
Display/src/app/weather-charts/weather-charts.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-weather-charts',
|
||||
templateUrl: './weather-charts.component.html',
|
||||
styleUrls: ['./weather-charts.component.scss']
|
||||
})
|
||||
export class WeatherChartsComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
7
Display/src/app/weather-reading.spec.ts
Normal file
7
Display/src/app/weather-reading.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { WeatherReading } from './weather-reading';
|
||||
|
||||
describe('WeatherReading', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new WeatherReading()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
19
Display/src/app/weather-reading.ts
Normal file
19
Display/src/app/weather-reading.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export class WeatherReading {
|
||||
Type: string;
|
||||
Message: null;
|
||||
Timestamp: Date;
|
||||
WindDirection: string;
|
||||
WindSpeed: number;
|
||||
Humidity: number;
|
||||
HumidityTemperature: number;
|
||||
Rain: number;
|
||||
Pressure: number;
|
||||
PressureTemperature: number;
|
||||
BatteryLevel: number;
|
||||
LightLevel: number;
|
||||
Latitude: number;
|
||||
Longitude: number;
|
||||
Altitude: number;
|
||||
SatelliteCount: number;
|
||||
GpsTimestamp: Date;
|
||||
}
|
||||
12
Display/src/app/weather.service.spec.ts
Normal file
12
Display/src/app/weather.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WeatherService } from './weather.service';
|
||||
|
||||
describe('WeatherService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: WeatherService = TestBed.get(WeatherService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
28
Display/src/app/weather.service.ts
Normal file
28
Display/src/app/weather.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, of, BehaviorSubject } from 'rxjs';
|
||||
import { HubConnectionBuilder, HubConnection } from '@aspnet/signalr';
|
||||
import { WeatherReading } from './weather-reading';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class WeatherService {
|
||||
private connection: HubConnection;
|
||||
private latestReading: BehaviorSubject<WeatherReading> = new BehaviorSubject<WeatherReading>(null);
|
||||
|
||||
constructor() {
|
||||
this.connection = new HubConnectionBuilder()
|
||||
.withUrl('http://172.23.10.3:80/api/hub/weather')
|
||||
.build();
|
||||
|
||||
this.connection.on('LatestReading', (message: string) => {
|
||||
this.latestReading.next(JSON.parse(message));
|
||||
});
|
||||
|
||||
this.connection.start();
|
||||
}
|
||||
|
||||
getLatestReading(): Observable<WeatherReading> {
|
||||
return this.latestReading.asObservable();
|
||||
}
|
||||
}
|
||||
58
Display/src/app/weather/weather.component.html
Normal file
58
Display/src/app/weather/weather.component.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<div class="weather-current">
|
||||
<div *ngIf="latestReading === null">
|
||||
Loading...
|
||||
</div>
|
||||
|
||||
<div *ngIf="latestReading !== null">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Temperature
|
||||
</td>
|
||||
<td>
|
||||
{{ latestReading.HumidityTemperature.toFixed(2) }}°F
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Humidity
|
||||
</td>
|
||||
<td>
|
||||
{{ latestReading.Humidity.toFixed(2) }}%
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Pressure
|
||||
</td>
|
||||
<td>
|
||||
{{ (latestReading.Pressure / 100).toFixed(2) }} mbar
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Wind
|
||||
</td>
|
||||
<td>
|
||||
{{ latestReading.WindSpeed.toFixed(2) }} {{ latestReading.WindDirection }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Rain
|
||||
</td>
|
||||
<td>
|
||||
{{ latestReading.Rain.toFixed(2) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="weather-current-header">
|
||||
Light
|
||||
</td>
|
||||
<td>
|
||||
{{ latestReading.LightLevel.toFixed(2) }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
10
Display/src/app/weather/weather.component.scss
Normal file
10
Display/src/app/weather/weather.component.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
.weather-current {
|
||||
margin: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.weather-current-header {
|
||||
font-weight: 500;
|
||||
text-align: right;
|
||||
padding-right: 10px;
|
||||
}
|
||||
25
Display/src/app/weather/weather.component.spec.ts
Normal file
25
Display/src/app/weather/weather.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { WeatherComponent } from './weather.component';
|
||||
|
||||
describe('WeatherComponent', () => {
|
||||
let component: WeatherComponent;
|
||||
let fixture: ComponentFixture<WeatherComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ WeatherComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(WeatherComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
18
Display/src/app/weather/weather.component.ts
Normal file
18
Display/src/app/weather/weather.component.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { WeatherService } from '../weather.service';
|
||||
import { WeatherReading } from '../weather-reading';
|
||||
|
||||
@Component({
|
||||
selector: 'app-weather',
|
||||
templateUrl: './weather.component.html',
|
||||
styleUrls: ['./weather.component.scss']
|
||||
})
|
||||
export class WeatherComponent implements OnInit {
|
||||
public latestReading: WeatherReading;
|
||||
|
||||
constructor(private weatherService: WeatherService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.weatherService.getLatestReading().subscribe(r => this.latestReading = r);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user