Skip to content

Development #1

Merged
merged 11 commits into from May 1, 2019
118 changes: 30 additions & 88 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/app/app.component.ts
@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
selector: 'app-root',
Expand All @@ -7,4 +8,10 @@ import { Component } from '@angular/core';
})
export class AppComponent {
title = 'frontend';

constructor(router: Router) {
if (localStorage.getItem('auth_token') !== null && router.url == '/') {
router.navigate(['/generator-search']);
}
}
}
1 change: 1 addition & 0 deletions src/app/authentication/authentication.component.ts
Expand Up @@ -54,6 +54,7 @@ export class AuthenticationComponent implements OnInit {
localStorage.removeItem('gen_name');
localStorage.removeItem('data_type');
localStorage.removeItem('fault_type');
// localStorage.removeItem('auth_token');
}

}
6 changes: 5 additions & 1 deletion src/app/generator-search/generator-search.component.css
Expand Up @@ -14,7 +14,11 @@ a#genLink {
} */

mat-card.generator-card {
width: 300px;
width: 400px;
height: 300px;
margin: 5px;
}

mat-card:hover {
cursor: pointer;
}
3 changes: 3 additions & 0 deletions src/app/header/header.component.css
Expand Up @@ -10,4 +10,7 @@
}
.clearfix {
overflow: auto;
}
a:hover {
cursor: pointer;
}
6 changes: 3 additions & 3 deletions src/app/header/header.component.html
Expand Up @@ -9,11 +9,11 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav mr-auto">
<li class="nav-item">
<li class="nav-item" >
<a class="nav-image" id="dash-image" (click)="resetGenerator()"><img src="assets/images/home.png"
class=" d-block img-fluid py-3 pl-3" alt="Dashboard Image" height="42" width="42"></a>
</li>
<li class="nav-item">
<li class="nav-item" *ngIf="isLoggedIn()">
<a class="nav-image" id="visualize-image" (click)="resetGenAndVisualize()"><img src="assets/images/graph.jpg"
class=" d-block img-fluid py-3 pl-3" alt="Visualization Image" height="42" width="42"></a>
</li>
Expand All @@ -22,7 +22,7 @@
<form class="form-inline my-2 my-lg-0">
<a class="nav-left-image" id="logout-image" (click)="resetAndClear()"><img
src="assets/images/logout.png" class=" d-block img-fluid py-3 pl-3" alt="Logout Image"
height="42" width="42"></a>
height="42" width="42" *ngIf="isLoggedIn()"></a>
</form>

</div>
Expand Down
3 changes: 3 additions & 0 deletions src/app/header/header.component.ts
Expand Up @@ -23,6 +23,9 @@ export class HeaderComponent implements OnInit {
resetGenAndVisualize() {
this.resetAndRedirect('/visualize-all');
}
isLoggedIn(): boolean {
return (localStorage.getItem('auth_token') !== null);
}

resetAndRedirect(url: string) {
this.login.getToken().then(() => {
Expand Down
20 changes: 15 additions & 5 deletions src/app/services/login.service.ts
Expand Up @@ -3,13 +3,14 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import {Router} from '@angular/router';

@Injectable({
providedIn: 'root'
})
export class LoginService {

constructor(private http: HttpClient) { }
constructor(private http: HttpClient, private router: Router) { }

authorizeUser(loginInfo): Observable<Object> {
return this.http.post('http://sd5-backend.engr.uconn.edu/auth', loginInfo);
Expand All @@ -33,19 +34,28 @@ export class LoginService {
getToken(): Promise<string> {
return new Promise<string>((resolve, reject) => {
const token = localStorage.getItem('auth_token');
if (!token) { reject('No Token'); }
this.http.get('http://sd5-backend.engr.uconn.edu/auth/verify', {
if (!token) { this.resetToken(); reject('No Token'); }
this.http.get('http://sd5-backend.engr.uconn.edu/verify', {
headers: {
Authorization: 'Bearer ' + token
},
observe: 'response'
}).subscribe((response) => {
if (response.status === 200) {
if (response.ok) {
resolve(token);
} else {
reject('Invalid Token');
this.resetToken();
reject('Bad Token!');
}
}, () => {
this.resetToken();
reject('Bad Token!');
});
});
}

resetToken() {
localStorage.removeItem('auth_token');
this.router.navigateByUrl('#');
}
}
12 changes: 12 additions & 0 deletions src/app/statistics/statistics.component.css
Expand Up @@ -48,4 +48,16 @@ h6
height: 100%;
height: 46px;
}
radial-gauge:hover {
cursor: pointer;
}
linear-gauge:hover {
cursor: pointer;
}
button
{
width: 150px;
background-color: orange;
color: white;
}

2 changes: 1 addition & 1 deletion src/app/statistics/statistics.component.html
@@ -1,6 +1,6 @@
<div class="container">
<div class="row mt-3">
<button (click)="goToGraphGen()" class="btn btn-primary btn-block m-1">Graph</button>
<button mat-raised-button (click)="goToGraphGen()" class = "mx-auto">Graph</button>
</div>

<ng-template #timedOut>
Expand Down
25 changes: 19 additions & 6 deletions src/app/statistics/statistics.component.ts
Expand Up @@ -27,7 +27,8 @@ export class StatisticsComponent implements OnInit {
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$;
public datatimer$;
public statetimer$;

getMajorTicks(metric: GeneratorMetric) {
const total = (metric.max - metric.min);
Expand Down Expand Up @@ -65,9 +66,6 @@ export class StatisticsComponent implements OnInit {
loadData() {
const gen_id = parseInt(localStorage.getItem('gen_id'), 10);
this.login.getToken().then((jsonToken) => {
this.data2.getGeneratorState(gen_id, jsonToken).then((state) => {
this.generator_state = state;
});
this.data2.getGeneratorStatistics(gen_id, jsonToken).then((statistics) => {
this.generator_statistics = statistics;
});
Expand All @@ -76,17 +74,32 @@ export class StatisticsComponent implements OnInit {
});
}

loadState() {
const gen_id = parseInt(localStorage.getItem('gen_id'), 10);
this.login.getToken().then((jsonToken) => {
this.data2.getGeneratorState(gen_id, jsonToken).then((state) => {
this.generator_state = state;
});
}, (error) => {
// todo go to logout
});
}

reloadLoop() {

}

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

Expand Down
3 changes: 2 additions & 1 deletion src/app/visualize-one/visualize-one.component.ts
Expand Up @@ -218,7 +218,8 @@ export class VisualizeOneComponent implements OnInit {
if (this.chart !== null) {
this.chart.destroy();
}
this.chart = this.graphData.createChart(labels, data, [localStorage.getItem('gen_name')]);
this.genName$ = localStorage.getItem('gen_name');
this.chart = this.graphData.createChart(labels, data, [this.genName$]);
this.unit$ = this.data.getUnits(dataVal);
this.startTime$ = startArray[1] + '/' + startArray[2] + '/' + startArray[0];
this.endTime$ = endArray[1] + '/' + endArray[2] + '/' + endArray[0];
Expand Down