diff --git a/package-lock.json b/package-lock.json index fa72323..307bf9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -999,6 +999,14 @@ "tslib": "^1.9.0" } }, + "@angular/flex-layout": { + "version": "8.0.0-beta.27", + "resolved": "https://registry.npmjs.org/@angular/flex-layout/-/flex-layout-8.0.0-beta.27.tgz", + "integrity": "sha512-qmpvQPesU4ZQ56IscwgmVRpK2UnyV+gwvXUql7TMv0QV215hLcHczjGsrKkLfW2By5E7XEyDat9br72uVXcPMw==", + "requires": { + "tslib": "^1.7.1" + } + }, "@angular/forms": { "version": "8.2.10", "resolved": "https://registry.npmjs.org/@angular/forms/-/forms-8.2.10.tgz", @@ -4994,9 +5002,9 @@ "dev": true }, "https-proxy-agent": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.2.tgz", - "integrity": "sha512-c8Ndjc9Bkpfx/vCJueCPy0jlP4ccCCSNDp8xwCZzPjKJUm+B+u9WX2x98Qx4n1PiMNTWo3D7KK5ifNV/yJyRzg==", + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.3.tgz", + "integrity": "sha512-Ytgnz23gm2DVftnzqRRz2dOXZbGd2uiajSw/95bPp6v53zPRspQjLm/AfBgqbJ2qfeRXWIOMVLpp86+/5yX39Q==", "dev": true, "requires": { "agent-base": "^4.3.0", diff --git a/package.json b/package.json index edbdcdd..6aae505 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,11 @@ "private": true, "dependencies": { "@angular/animations": "~8.2.0", - "@angular/cdk": "~8.2.3", + "@angular/cdk": "^8.2.3", "@angular/common": "~8.2.0", "@angular/compiler": "~8.2.0", "@angular/core": "~8.2.0", + "@angular/flex-layout": "^8.0.0-beta.27", "@angular/forms": "~8.2.0", "@angular/material": "^8.2.3", "@angular/platform-browser": "~8.2.0", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ef0c201..ae161a6 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; - +import { FlexLayoutModule } from '@angular/flex-layout'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @@ -41,7 +41,8 @@ import { NgxGaugeModule} from 'ngx-gauge'; ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }), ReactiveFormsModule, FormsModule, - NgxGaugeModule + NgxGaugeModule, + FlexLayoutModule ], providers: [], bootstrap: [AppComponent], diff --git a/src/app/auth/profile/avatar/avatar.component.ts b/src/app/auth/profile/avatar/avatar.component.ts index 56b08f3..dd3a507 100644 --- a/src/app/auth/profile/avatar/avatar.component.ts +++ b/src/app/auth/profile/avatar/avatar.component.ts @@ -83,7 +83,7 @@ export class AvatarComponent { this.compressor.compress(file).subscribe( () => { const { name, size, type } = file; - // console.log('compressed size: ', size); + // console.log('compressed size: ', size, name, type); const fileName = file.name.split('.'); const fileExt = fileName[fileName.length - 1]; this.s3ImagePath = `${this.s3ImagePath}/picture.${fileExt}`; @@ -114,11 +114,13 @@ export class AvatarComponent { }) .catch( error => { this.completeFileUpload(error); + console.log('error uploading image'); }); } completeFileUpload(error?: any) { if (error) { + console.log('error completeing upload'); return this._setError(error); } this.uploading = false; diff --git a/src/app/auth/profile/profile.component.html b/src/app/auth/profile/profile.component.html index d91b81a..da50caf 100644 --- a/src/app/auth/profile/profile.component.html +++ b/src/app/auth/profile/profile.component.html @@ -19,7 +19,7 @@ diff --git a/src/app/auth/profile/profile.component.ts b/src/app/auth/profile/profile.component.ts index 1e61000..687f609 100644 --- a/src/app/auth/profile/profile.component.ts +++ b/src/app/auth/profile/profile.component.ts @@ -68,6 +68,10 @@ export class ProfileComponent implements OnInit { .then(() => this.router.navigate(['auth/signin'])); } + onAvatarUploadStart() { + // this.loading.show(); + // console.log(this.loading); + } onAvatarUploadComplete(data: any) { this.avatar = data.key; this.loading.hide(); diff --git a/src/app/auth/sign-in/sign-in.component.html b/src/app/auth/sign-in/sign-in.component.html index 78ee610..385d36c 100644 --- a/src/app/auth/sign-in/sign-in.component.html +++ b/src/app/auth/sign-in/sign-in.component.html @@ -16,8 +16,8 @@ -

or

+

Don't have an account? Sign up

diff --git a/src/app/auth/sign-in/sign-in.component.ts b/src/app/auth/sign-in/sign-in.component.ts index 2405aed..3c5e46b 100644 --- a/src/app/auth/sign-in/sign-in.component.ts +++ b/src/app/auth/sign-in/sign-in.component.ts @@ -68,7 +68,7 @@ export class SignInComponent { }); } - async signInWithFacebook() { + /* async signInWithFacebook() { const socialResult = await this.auth.socialSignIn(AuthService.FACEBOOK); console.log('fb Result:', socialResult); } @@ -76,5 +76,5 @@ export class SignInComponent { async signInWithGoogle() { const socialResult = await this.auth.socialSignIn(AuthService.GOOGLE); console.log('google Result:', socialResult); - } + } */ } diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 3dce148..2f0afbb 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,23 +1,66 @@
-
-
-

Location: {{ currentMessage.location.S }}

-

Company: {{ currentMessage.company.S }}

-

Field: {{ currentMessage.field.S }}

- +
+
Total Flow Rate {{ totalFlowRate }}
+ +
+ + + + + {{ message.location }} + + + {{ message.company }} + + + {{ message.field }} + + + Flow Rate: {{ message.volume_flow }} + + + + + + Current + A + + + Intake Pressure + PSI + + +
- - -
- \ No newline at end of file + + + \ No newline at end of file diff --git a/src/app/home/home.component.scss b/src/app/home/home.component.scss index e69de29..440bb57 100644 --- a/src/app/home/home.component.scss +++ b/src/app/home/home.component.scss @@ -0,0 +1,6 @@ +.message { + width: 250px; +} +.container { + padding: 10px; +} \ No newline at end of file diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 72db94b..e28d171 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,7 +1,15 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { WebSocketSubject } from 'rxjs/webSocket'; import Auth from '@aws-amplify/auth'; +export class MyJSON { + location: ''; + company: ''; + volume_flow: 0; + field: ''; +} + + @Component({ selector: 'app-home', @@ -9,16 +17,15 @@ import Auth from '@aws-amplify/auth'; styleUrls: ['./home.component.scss'] }) -export class HomeComponent implements OnInit { - - public serverMessages = new Array(); +export class HomeComponent implements OnInit, OnDestroy { + public serverMessages = new Array(); private socket$: WebSocketSubject; - private currentMessage = {location: {S: ''}, company: {S: ''}, volume_flow: {N: ''}, field: {S: ''}}; - private token: string; + private currentMessage = {location: '', company: '', volume_flow: '', field: ''}; + private totalFlowRate = 0; gaugeType = 'arch'; gaugeCap = 'round'; - gaugeValue = this.currentMessage.volume_flow.N; + gaugeValue = this.currentMessage.volume_flow; gaugeLabel = 'Volume Flow'; gaugeAppendText = 'gpm'; gaugeThick = 10; @@ -31,29 +38,64 @@ export class HomeComponent implements OnInit { }; constructor() { - Auth.currentSession().then(data => { - console.log(data.getAccessToken().getJwtToken()); - this.token = data.getAccessToken().getJwtToken(); - this.connectWS(this.token); - // this.subscribeWS(); + Auth.currentAuthenticatedUser().then(data => { + this.connectWS(data.signInUserSession.accessToken.jwtToken, data.signInUserSession.idToken.payload['cognito:preferred_role'] ); + this.subscribeWS(); + this.socket$.next({action: 'getDashboardData', policy: data.signInUserSession.idToken.payload['cognito:preferred_role']}); }); } ngOnInit() { } - connectWS(token: string) { - this.socket$ = new WebSocketSubject('wss://3fseaywb8b.execute-api.us-east-1.amazonaws.com/prototype?token=' + token); + ngOnDestroy() { + this.socket$.complete(); + } + + connectWS(token: string, role: string) { + this.socket$ = new WebSocketSubject('wss://3fseaywb8b.execute-api.us-east-1.amazonaws.com/prototype?token=' + token + + '&role=' + role); } subscribeWS() { this.socket$ .subscribe( - (message) => {this.currentMessage = message; - this.gaugeValue = parseFloat(this.currentMessage.volume_flow.N).toFixed(2); - }, // this.serverMessages.push(message), + (message) => { + console.log(message); + if (message instanceof Array) { + message.forEach(element => { + this.updateList(element); + }); + } else { + this.updateList(message); + } + this.totalFlowRate = this.totalFlowRates(0); + }, (err) => console.error(err), () => console.warn('Completed!') ); } + + updateList(obj) { + const index = this.serverMessages.findIndex((e) => e.location === obj.location); + obj.volume_flow = parseFloat(obj.volume_flow).toFixed(2); + obj.current = parseFloat(obj.current).toFixed(2); + obj.intake_pressure = parseFloat(obj.intake_pressure).toFixed(2); + if (index === -1) { + this.serverMessages.push(obj); + + } else { + this.serverMessages[index] = obj; + } + } + + totalFlowRates(temp: number) { + temp = 0; + this.serverMessages.forEach(element => { + temp += Number(element.volume_flow); + }); + return temp; + } } + + diff --git a/src/app/loader/loader.service.ts b/src/app/loader/loader.service.ts index 9bf2d84..ca5caf6 100644 --- a/src/app/loader/loader.service.ts +++ b/src/app/loader/loader.service.ts @@ -16,7 +16,7 @@ export class LoaderService { this.dialogRef = this.dialog.open(LoaderComponent, { width: '80%', data: { message }, - closeOnNavigation: false + closeOnNavigation: true }); }); } diff --git a/src/app/material/material.module.ts b/src/app/material/material.module.ts index aac6f42..b34a62b 100644 --- a/src/app/material/material.module.ts +++ b/src/app/material/material.module.ts @@ -1,6 +1,7 @@ import { NgModule } from '@angular/core'; import { CdkTableModule } from '@angular/cdk/table'; import { CdkTreeModule } from '@angular/cdk/tree'; +import { DragDropModule } from '@angular/cdk/drag-drop'; import { MatAutocompleteModule, MatBadgeModule, @@ -42,6 +43,7 @@ import { exports: [ CdkTableModule, CdkTreeModule, + DragDropModule, MatAutocompleteModule, MatBadgeModule, MatBottomSheetModule,