Skip to content
Permalink
Browse files

Fixing some minor UI problems, linting for production, added refresh …

…timer on statistics page to fire every minute.
  • Loading branch information
Evan Langlais
Evan Langlais committed Apr 17, 2019
1 parent 494bed8 commit b3e10c8efe3f432db02d94a7ac2df976aa80e861
@@ -1,7 +1,8 @@
<div class="container">
<div class="row justify-content-center">
<!--<div class="col-md-12 mx-auto mt-4">-->
<h4 class="text-center mb-3">Your Generators</h4>
</div>
<div class="row justify-content-center">
<mat-spinner *ngIf="loading$"></mat-spinner>
</div>
<div style="display: flex; flex-wrap: wrap; margin: 6em 2em; justify-content: space-evenly">
@@ -1,43 +1,36 @@
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
HttpResponse,
HttpErrorResponse
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest,
HttpResponse,
HttpErrorResponse
} from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { retry, catchError } from 'rxjs/operators';
import { Component, Input} from '@angular/core';

import {Observable, throwError} from 'rxjs';
import {retry, catchError} from 'rxjs/operators';
import {Component, Input} from '@angular/core';


export class HttpErrorInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
retry(1),
catchError((error: HttpErrorResponse) => {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {
// client-side error
errorMessage = `Error: ${error.error.message}`;
}
else if (error.message == "Http failure response for http://sd5-backend.engr.uconn.edu/auth: 404 Not Found")
{
//console.log(error.message);

window.alert("Invalid Credentials");
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request)
.pipe(
retry(1),
catchError((error: HttpErrorResponse) => {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {
// client-side error
errorMessage = `Error: ${error.error.message}`;
} else if (error.message === 'Http failure response for http://sd5-backend.engr.uconn.edu/auth: 404 Not Found') {
window.alert('Invalid Credentials');

} else {
// server-side error
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}

}
else {
// server-side error
//console.log("poop");
errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
}

return throwError(errorMessage);
})
)
}
}
return throwError(errorMessage);
})
);
}
}
@@ -15,7 +15,7 @@ export class MetricsService {

getRecentMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/recent/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -25,7 +25,7 @@ export class MetricsService {

getHourMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/hour/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -35,7 +35,7 @@ export class MetricsService {

getDayMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/day/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -45,7 +45,7 @@ export class MetricsService {

getWeekMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/week/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -54,7 +54,7 @@ export class MetricsService {
}
getMonthMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/month/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -64,7 +64,7 @@ export class MetricsService {

getYearMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/year/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
@@ -74,12 +74,11 @@ export class MetricsService {

getDevMetrics(token) {

let gen_id = localStorage.getItem('gen_id');
const gen_id = localStorage.getItem('gen_id');
return this.http.get('http://sd5-backend.engr.uconn.edu/data/query/exp/dev/' + gen_id, {
headers: {
Authorization: 'Bearer ' + token
}

});
}

@@ -5,6 +5,7 @@ import { Router } from '@angular/router';
import {LoginService} from '../services/login.service';
import { GeneratorState, GeneratorMetric} from '../generator-object';
import { GeneratorService } from '../services/generator.service';
import { timer } from 'rxjs/observable/timer';

@Component({
selector: 'app-statistics',
@@ -14,16 +15,19 @@ import { GeneratorService } from '../services/generator.service';
export class StatisticsComponent implements OnInit {


constructor(public data: MetricsService, public data2: GeneratorService, private http: HttpClient, private router: Router, private login: LoginService) {
constructor(public data: MetricsService, public data2: GeneratorService, private http: HttpClient,
private router: Router, private login: LoginService) {

}

public metric: any;

public generator_state: GeneratorState;
public generator_statistics: Map<string, GeneratorMetric>;
public radial_metrics = ['l1.current', 'l2.current', 'l3.current', 'engine.rpm', 'fuel.pressure', 'l1.l0.voltage', 'l2.l0.voltage', 'l3.l0.voltage', 'total.kw'];
public radial_metrics = ['l1.current', 'l2.current', 'l3.current', 'engine.rpm', 'fuel.pressure',
'l1.l0.voltage', 'l2.l0.voltage', 'l3.l0.voltage', 'total.kw'];
public slide_metrics = ['coolant.temp', 'fuel.temp', 'oil.temp', 'oil.pressure'];
public timer$;

getMajorTicks(metric: GeneratorMetric) {
const total = (metric.max - metric.min);
@@ -57,9 +61,8 @@ export class StatisticsComponent implements OnInit {
this.router.navigateByUrl('/visualize-one');
localStorage.setItem('data_type', dataType);
}
ngOnInit() {
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');

loadData() {
const gen_id = parseInt(localStorage.getItem('gen_id'), 10);
this.login.getToken().then((jsonToken) => {
this.data2.getGeneratorState(gen_id, jsonToken).then((state) => {
@@ -73,4 +76,18 @@ export class StatisticsComponent implements OnInit {
});
}

reloadLoop() {

}

ngOnInit() {
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');
this.timer$ = timer(0, 60000);
this.timer$.subscribe(() => {
this.loadData();
});
// this.loadData();
}

}

0 comments on commit b3e10c8

Please sign in to comment.
You can’t perform that action at this time.