Add some initial web UI

This commit is contained in:
2019-09-10 19:39:06 -04:00
parent 807d6cb5b5
commit a32e65de1c
51 changed files with 14219 additions and 0 deletions

View 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 { }

View 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>

View File

@@ -0,0 +1,3 @@
.menu-spacer {
margin-right: 14px;
}

View 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!');
});
});

View 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';
}

View 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 { }

View File

@@ -0,0 +1 @@
<p>dashboard works!</p>

View 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();
});
});

View 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() {
}
}

View File

@@ -0,0 +1 @@
<p>laundry works!</p>

View 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();
});
});

View 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() {
}
}

View File

@@ -0,0 +1 @@
<p>weather-charts works!</p>

View File

@@ -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();
});
});

View 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() {
}
}

View File

@@ -0,0 +1,7 @@
import { WeatherReading } from './weather-reading';
describe('WeatherReading', () => {
it('should create an instance', () => {
expect(new WeatherReading()).toBeTruthy();
});
});

View 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;
}

View 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();
});
});

View 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();
}
}

View 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>

View File

@@ -0,0 +1,10 @@
.weather-current {
margin: 10px;
font-size: 14px;
}
.weather-current-header {
font-weight: 500;
text-align: right;
padding-right: 10px;
}

View 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();
});
});

View 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);
}
}