Added role switching capabilities
This commit is contained in:
@@ -1,6 +1,23 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class ="viewer">
|
<div class ="viewer">
|
||||||
<div class="container" fxLayout="row wrap" fxLayoutGap="30px">Total Flow Rate {{ totalFlowRate }}</div>
|
<div class="container" fxLayout="row wrap" fxLayoutGap="30px">
|
||||||
|
Total Flow Rate {{ totalFlowRate }}
|
||||||
|
|
||||||
|
<div class="flex-spacer"></div>
|
||||||
|
|
||||||
|
<mat-menu #appMenu="matMenu">
|
||||||
|
<ng-container *ngFor="let item of groups; let i = index">
|
||||||
|
<button mat-menu-item (click)="setRole(i)"> {{ item }}</button>
|
||||||
|
</ng-container>
|
||||||
|
</mat-menu>
|
||||||
|
|
||||||
|
<button mat-icon-button [matMenuTriggerFor]="appMenu">
|
||||||
|
<mat-icon>more_vert</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<mat-divider ></mat-divider>
|
<mat-divider ></mat-divider>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
|
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
width: 250px;
|
width: 250px;
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
|
//display: flex;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
.flex-spacer {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,15 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
Auth.currentAuthenticatedUser().then(data => {
|
Auth.currentAuthenticatedUser().then(data => {
|
||||||
this.connectWS(data.signInUserSession.accessToken.jwtToken, data.signInUserSession.idToken.payload['cognito:preferred_role'] );
|
// console.log(data);
|
||||||
this.subscribeWS();
|
this.roles = data.signInUserSession.idToken.payload['cognito:roles'];
|
||||||
this.socket$.next({action: 'getDashboardData', policy: data.signInUserSession.idToken.payload['cognito:preferred_role']});
|
this.groups = data.signInUserSession.idToken.payload['cognito:groups'];
|
||||||
|
this.groups.forEach( (element, index, array) => {
|
||||||
|
array[index] = element.replace(/_/g, ' ');
|
||||||
|
});
|
||||||
|
this.currentRole = data.signInUserSession.idToken.payload['cognito:roles'][0];
|
||||||
|
this.token = data.signInUserSession.accessToken.jwtToken;
|
||||||
|
this.connect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +42,10 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
private socket$: WebSocketSubject<any>;
|
private socket$: WebSocketSubject<any>;
|
||||||
private currentMessage = {location: '', company: '', volumeflow: '', field: ''};
|
private currentMessage = {location: '', company: '', volumeflow: '', field: ''};
|
||||||
private totalFlowRate = 0;
|
private totalFlowRate = 0;
|
||||||
|
private roles: string[];
|
||||||
|
private groups: string[];
|
||||||
|
private currentRole: string;
|
||||||
|
private token: string;
|
||||||
gaugeType = 'arch';
|
gaugeType = 'arch';
|
||||||
gaugeCap = 'round';
|
gaugeCap = 'round';
|
||||||
gaugeValue = this.currentMessage.volumeflow;
|
gaugeValue = this.currentMessage.volumeflow;
|
||||||
@@ -67,9 +77,16 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
this.socket$.complete();
|
this.socket$.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this.connectWS(this.token, this.currentRole);
|
||||||
|
this.subscribeWS();
|
||||||
|
this.socket$.next({action: 'getDashboardData', policy: this.currentRole});
|
||||||
|
}
|
||||||
|
|
||||||
connectWS(token: string, role: string) {
|
connectWS(token: string, role: string) {
|
||||||
this.socket$ = new WebSocketSubject('wss://3fseaywb8b.execute-api.us-east-1.amazonaws.com/prototype?token=' + token +
|
this.socket$ = new WebSocketSubject('wss://3fseaywb8b.execute-api.us-east-1.amazonaws.com/prototype?token=' + token +
|
||||||
'&role=' + role);
|
'&role=' + role);
|
||||||
|
// console.log(this.socket$);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeWS() {
|
subscribeWS() {
|
||||||
@@ -82,7 +99,7 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
this.updateList(message);
|
this.updateList(message);
|
||||||
}
|
}
|
||||||
this.totalFlowRate = this.totalFlowRates(0);
|
this.totalFlowRate = this.totalFlowRates();
|
||||||
this.dataSource.data = this.serverMessages;
|
this.dataSource.data = this.serverMessages;
|
||||||
// console.log(this.serverMessages);
|
// console.log(this.serverMessages);
|
||||||
},
|
},
|
||||||
@@ -107,13 +124,20 @@ export class HomeComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
totalFlowRates(temp: number) {
|
totalFlowRates() {
|
||||||
temp = 0;
|
let temp = 0;
|
||||||
this.serverMessages.forEach(element => {
|
this.serverMessages.forEach(element => {
|
||||||
temp += element.volumeflow;
|
temp += element.volumeflow;
|
||||||
});
|
});
|
||||||
return Number(temp.toFixed(2));
|
return Number(temp.toFixed(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setRole(index: number) {
|
||||||
|
this.currentRole = this.roles[index];
|
||||||
|
this.socket$.complete();
|
||||||
|
this.serverMessages = [];
|
||||||
|
this.connect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user