Skip to content
Permalink
Browse files

fixes for dev merge

  • Loading branch information
rrc12004 committed Apr 15, 2019
2 parents 214efed + b9cac43 commit 5ca36ea8a5c80d7d3e39d8f9420dd23785f0707b
@@ -130,4 +130,4 @@
} }
}, },
"defaultProject": "frontend" "defaultProject": "frontend"
} }
@@ -41,15 +41,15 @@ import { VisualizeOneComponent } from './visualize-one/visualize-one.component';
GaugesModule, GaugesModule,
RouterModule.forRoot([ RouterModule.forRoot([


{path: 'dashboard', component: FrontpageComponent}, {path: 'dashboard', component: FrontpageComponent},
{path: '', component: AuthenticationComponent}, {path: '', component: AuthenticationComponent},
{path: 'generator-search', component: GeneratorSearchComponent}, {path: 'generator-search', component: GeneratorSearchComponent},
{path: 'statistics', component: StatisticsComponent}, {path: 'statistics', component: StatisticsComponent},
{path: 'warnings', component: WarningsComponent}, {path: 'warnings', component: WarningsComponent},
{path: 'history', component: HistoryComponent}, {path: 'history', component: HistoryComponent},
{path: 'sign_up', component: SignUpComponent}, {path: 'sign_up', component: SignUpComponent},
{path: 'visualize-all', component: VisualizeAllComponent}, {path: 'visualize-all', component: VisualizeAllComponent},
{path: 'visualize-one', component: VisualizeOneComponent}, {path: 'visualize-one', component: VisualizeOneComponent},


]), ]),


@@ -48,7 +48,7 @@ export class AuthenticationComponent implements OnInit {


} }


ngOnInit() { ngOnInit() {
localStorage.removeItem('gen_id'); localStorage.removeItem('gen_id');
localStorage.removeItem('org_id'); localStorage.removeItem('org_id');
localStorage.removeItem('gen_name'); localStorage.removeItem('gen_name');
@@ -0,0 +1,19 @@
export interface GeneratorObject {
gen_id: number;
gen_name: string;
org_id: number;
zip: number;
state: GeneratorState | null;
}

export interface GeneratorState {
online: boolean;
status: string;
status_code: number;
fault_count: number | null;
fault_codes: Array<string>;
status_count: number;
status_codes: Array<string>;
ip: string;
}

@@ -11,4 +11,9 @@ a#genLink {
margin: 10px; margin: 10px;
display: inline-block; display: inline-block;
text-decoration: none; text-decoration: none;
} */ } */

mat-card.generator-card {
width: calc(100% - 70px);
height: calc(100% - 70px);
}
@@ -1,23 +1,32 @@
<div class="container "> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-12 mx-auto mt-4"> <div class="col-md-12 mx-auto mt-4">
<h4 class="text-center mb-3">Your Generators</h4> <h4 class="text-center mb-3">Your Generators</h4>

<mat-spinner *ngIf="loading$"></mat-spinner>
<form id="visToolbar"> <mat-grid-list cols="3" rowHeight="1:1">
<div class="text-center mb3"> <mat-grid-tile *ngFor="let generator of generators$">
<br> <mat-card mat-ripple class="generator-card" (click)="goToGenerator(generator)">
<a> <mat-card-header>
<a class="text-center"*ngFor="let generator of generators$"> <mat-card-title>{{ generator.gen_name }}</mat-card-title>
<a class="btn btn-primary" style="color:white" (click)="goToGenerator(generator.gen_id, generator.org_id, generator.gen_name)">{{ generator.gen_name }}</a> <mat-card-subtitle>{{ generator.state.status }}</mat-card-subtitle>
<p id="genInfo"> </mat-card-header>
zipcode: {{ generator.zip }} <br> <mat-list *ngIf="generator.state.online">
(insert statistics preview here) <mat-list-item>
</p> <mat-icon matListIcon>error</mat-icon>
<br> <p matLine>
</a> <span> Active Faults: {{ generator.state.fault_count }} </span>
</a> </p>
</div> </mat-list-item>
</form> <mat-list-item>
<mat-icon matListIcon>settings_ethernet</mat-icon>
<p matLine>
<span> IP Address: {{ generator.state.ip }} </span>
</p>
</mat-list-item>
</mat-list>
</mat-card>
</mat-grid-tile>
</mat-grid-list>
</div> </div>
</div> </div>
</div> </div>
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { GeneratorService } from '../services/generator.service'; import { GeneratorService } from '../services/generator.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { GeneratorObject } from '../generator-object';
import {LoginService} from '../services/login.service';


@Component({ @Component({
selector: 'app-generator-search', selector: 'app-generator-search',
@@ -10,35 +12,39 @@ import { Router } from '@angular/router';


export class GeneratorSearchComponent implements OnInit { export class GeneratorSearchComponent implements OnInit {


constructor(public data: GeneratorService, private router: Router) { } constructor(public data: GeneratorService, private router: Router, private login: LoginService) { }


public generators$: Object; public generators$: Array<GeneratorObject>;
public loading$: boolean;


goToGenerator(gen_id, org_id, gen_name) { goToGenerator(gen: GeneratorObject) {
this.router.navigateByUrl('/statistics'); this.router.navigateByUrl('/statistics');
// console.log(gen_id); // console.log(gen_id);
// console.log(org_id); // console.log(org_id);
localStorage.setItem('gen_id', gen_id); localStorage.setItem('gen_id', gen.gen_id.toString());
localStorage.setItem('org_id', org_id); localStorage.setItem('org_id', gen.org_id.toString());
localStorage.setItem('gen_name', gen_name); localStorage.setItem('gen_name', gen.gen_name);
} }


ngOnInit() { async ngOnInit() {
this.loading$ = true;
localStorage.removeItem('gen_id'); localStorage.removeItem('gen_id');
localStorage.removeItem('org_id'); localStorage.removeItem('org_id');
localStorage.removeItem('gen_name'); localStorage.removeItem('gen_name');
localStorage.removeItem('data_type'); localStorage.removeItem('data_type');
localStorage.removeItem('fault_type'); localStorage.removeItem('fault_type');
const jsonToken = localStorage.getItem('auth_token'); const auth_token: string = await this.login.getToken();
try { this.generators$ = await this.data.getGenerators(auth_token);
this.data.getGenerators(jsonToken).subscribe((data) => { this.loading$ = false;
/*try {
this.data.getGenerators(jsonToken).subscribe((data: Array<GeneratorObject>) => {
// console.log(data); // console.log(data);
this.generators$ = data; this.generators$ = data;
return this.generators$; return this.generators$;
}); });
} catch (err) { } catch (err) {
return err; return err;
} }*/
// this.generators$ = this.getGeneratorName(); // this.generators$ = this.getGeneratorName();
} }


@@ -1,5 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import {LoginService} from '../services/login.service';


@Component({ @Component({
selector: 'app-header', selector: 'app-header',
@@ -8,37 +9,32 @@ import { Router } from '@angular/router';
}) })
export class HeaderComponent implements OnInit { export class HeaderComponent implements OnInit {


constructor(private router: Router) { } constructor(private router: Router, private login: LoginService) { }


resetAndClear() { resetAndClear() {
this.router.navigateByUrl('#'); this.router.navigateByUrl('#');
localStorage.clear(); localStorage.clear();
} }


resetGenerator() { resetGenerator() {
if (localStorage.getItem('auth_token') != null) { this.resetAndRedirect('/generator-search');
this.router.navigateByUrl('/generator-search');
localStorage.removeItem('gen_id');
localStorage.removeItem('org_id');
localStorage.removeItem('gen_name');
localStorage.removeItem('data_type');
} else {
console.log('You need to log in');
this.router.navigateByUrl('#');
}
} }


resetGenAndVisualize() { resetGenAndVisualize() {
if (localStorage.getItem('auth_token') != null) { this.resetAndRedirect('/visualize-all');
this.router.navigateByUrl('/visualize-all'); }

resetAndRedirect(url: string) {
this.login.getToken().then(() => {
this.router.navigateByUrl(url);
localStorage.removeItem('gen_id'); localStorage.removeItem('gen_id');
localStorage.removeItem('org_id'); localStorage.removeItem('org_id');
localStorage.removeItem('gen_name'); localStorage.removeItem('gen_name');
localStorage.removeItem('data_type'); localStorage.removeItem('data_type');
} else { }, () => {
console.log('You need to log in'); console.log('You need to log in');
this.router.navigateByUrl('#'); this.router.navigateByUrl('#');
} });
} }


ngOnInit() { ngOnInit() {
@@ -4,7 +4,15 @@ import { NgModule } from '@angular/core';
import { MatDatepickerModule, import { MatDatepickerModule,
MatNativeDateModule, MatNativeDateModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule } from '@angular/material'; MatInputModule,
MatCardModule,
MatButtonModule,
MatGridListModule,
MatRippleModule,
MatProgressSpinnerModule,
MatIconModule,
MatListModule,
} from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';


@NgModule({ @NgModule({
@@ -20,9 +28,16 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
MatFormFieldModule, MatFormFieldModule,
MatNativeDateModule, MatNativeDateModule,
MatInputModule, MatInputModule,
BrowserAnimationsModule BrowserAnimationsModule,
MatCardModule,
MatButtonModule,
MatGridListModule,
MatRippleModule,
MatProgressSpinnerModule,
MatIconModule,
MatListModule,
], ],
providers: [ MatDatepickerModule ], providers: [ MatDatepickerModule ],
}) })


export class MaterialModule {} export class MaterialModule {}
@@ -1,18 +1,50 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import {HttpClient, HttpResponse} from '@angular/common/http';
import {GeneratorObject, GeneratorState} from '../generator-object';
import {LoginService} from './login.service';


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


constructor(private http: HttpClient) { } constructor(private http: HttpClient, private login: LoginService) { }


getGenerators(token) { getGenerators(token: string): Promise<Array<GeneratorObject>> {
return this.http.get('http://sd5-backend.engr.uconn.edu/user/generators', { return new Promise<Array<GeneratorObject>>((resolve, reject) => {
headers: { this.http.get('http://sd5-backend.engr.uconn.edu/user/generators', {
Authorization: 'Bearer ' + token headers: {
} Authorization: 'Bearer ' + token
}
}).subscribe(async (raw_generators: Array<GeneratorObject>) => {
const generators: Array<GeneratorObject> = [];
for (const generator of raw_generators) {
await this.getGeneratorState(generator.gen_id, token).then((state: GeneratorState) => {
generator.state = state;
generators.push(generator);
}, (error) => {
reject(error);
});
}
resolve(generators);
}, (error) => {
reject(error);
});
}); });
} }

getGeneratorState(gen_id: number, token: string): Promise<GeneratorState> {
return new Promise<GeneratorState>((resolve, reject) => {
this.http.get('http://sd5-backend.engr.uconn.edu/generator/' + gen_id + '/state', {
headers: {
Authorization: 'Bearer ' + token
}
}).subscribe((state: GeneratorState) => {
resolve(state);
}, (error) => {
reject(error);
});
});
}

} }
@@ -3,7 +3,6 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw'; import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
import { ReplaySubject } from 'rxjs';


@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -30,4 +29,23 @@ 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', {
headers: {
Authorization: 'Bearer ' + token
},
observe: 'response'
}).subscribe((response) => {
if (response.status === 200) {
resolve(token);
} else {
reject('Invalid Token');
}
});
});
}
} }
@@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core';
import {MetricsService} from '../services/metrics.service'; import {MetricsService} from '../services/metrics.service';
import {HttpClient, HttpHeaders} from '@angular/common/http'; import {HttpClient, HttpHeaders} from '@angular/common/http';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import {LoginService} from '../services/login.service';


@Component({ @Component({
selector: 'app-statistics', selector: 'app-statistics',
@@ -11,7 +12,7 @@ import { Router } from '@angular/router';
export class StatisticsComponent implements OnInit { export class StatisticsComponent implements OnInit {




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






@@ -98,11 +99,11 @@ export class StatisticsComponent implements OnInit {
} }




ngOnInit() { async ngOnInit() {


localStorage.removeItem('data_type'); localStorage.removeItem('data_type');
localStorage.removeItem('fault_type'); localStorage.removeItem('fault_type');
const jsonToken = localStorage.getItem('auth_token'); const jsonToken = await this.login.getToken();






0 comments on commit 5ca36ea

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