Skip to content
Permalink
Browse files

Merge pull request #1 from SeniorDesignGroup5/development

Development
  • Loading branch information
eal13009 committed May 1, 2019
2 parents b3e10c8 + bcb206d commit 06ac7bc75c819a7dc57d5ed90a1753cb66b019e0

Large diffs are not rendered by default.

@@ -1,4 +1,5 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
selector: 'app-root',
@@ -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']);
}
}
}
@@ -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');
}

}
@@ -14,7 +14,11 @@ a#genLink {
} */

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

mat-card:hover {
cursor: pointer;
}
@@ -10,4 +10,7 @@
}
.clearfix {
overflow: auto;
}
a:hover {
cursor: pointer;
}
@@ -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>
@@ -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>
@@ -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(() => {
@@ -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);
@@ -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('#');
}
}
@@ -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;
}

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

@@ -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];

0 comments on commit 06ac7bc

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