-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: add status component for each edge (#1162)
* with right restrictions (at least admin)
- Loading branch information
Showing
12 changed files
with
384 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<ion-header> | ||
<ion-toolbar class="ion-justify-content-center" color="primary"> | ||
<ion-title translate>General.systemState</ion-title> | ||
<ion-buttons slot="end"> | ||
<ion-button (click)="modalCtrl.dismiss()"> | ||
<ion-icon name="close"></ion-icon> | ||
</ion-button> | ||
</ion-buttons> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ng-container *ngIf="edge && components"> | ||
<ng-container *ngIf="edge.currentData | async as currentData"> | ||
<ion-content> | ||
<ion-card-content> | ||
<ng-container *ngIf="currentData.summary.system as sum"> | ||
<ion-item lines="full"> | ||
<ion-icon color="primary" name="analytics-outline"></ion-icon> | ||
<ion-label class="ion-padding-start" translate> | ||
General.totalState | ||
</ion-label> | ||
<ng-container [ngSwitch]="sum.state"> | ||
<ion-icon *ngSwitchCase="0" color="success" name="checkmark-circle-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="1" color="success" name="information-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="2" color="warning" name="alert-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="3" color="danger" name="alert-outline"></ion-icon> | ||
</ng-container> | ||
</ion-item> | ||
</ng-container> | ||
<ion-list> | ||
<ng-container *ngFor="let category of components"> | ||
<ion-item-group> | ||
<ion-item lines="inset"> | ||
<ion-icon name="{{ category.category.icon }}"></ion-icon> | ||
<ion-label class="ion-padding-start"> | ||
{{ category.category.title }} | ||
</ion-label> | ||
</ion-item> | ||
</ion-item-group> | ||
<ion-item lines="none" *ngFor="let item of category.components"> | ||
<ion-label class="ion-text-wrap"> | ||
<ion-text color="primary"> | ||
<h3>{{ item.alias }} | ||
<span *ngIf="item.id != item.alias"> ({{ item.id }})</span> | ||
<small *ngIf="!item.isEnabled"> (<span | ||
translate>General.componentInactive</span>) </small> | ||
</h3> | ||
</ion-text> | ||
<ng-container *ngIf="config.factories[item.factoryId] as factory"> | ||
<p>{{ factory.name }}</p> | ||
</ng-container> | ||
<ng-container *ngIf="item['showProperties']"> | ||
<ng-container *ngFor="let address of subscribedInfoChannels"> | ||
<ng-container | ||
*ngIf="address.componentId == item.id && address.channelId != 'State'"> | ||
<ng-container *ngIf="currentData.channel[address.toString()] == 1"> | ||
<ion-label *ngIf="item.channels[address.channelId]['text'].length != 0"> | ||
<ng-container | ||
[ngSwitch]="item.channels[address.channelId]['level']"> | ||
<ion-text *ngSwitchCase="'INFO'" color="success" translate> | ||
General.info | ||
</ion-text> | ||
<ion-text *ngSwitchCase="'WARNING'" color="warning" translate> | ||
General.warning | ||
</ion-text> | ||
<ion-text *ngSwitchCase="'FAULT'" color="danger" translate> | ||
General.fault | ||
</ion-text> | ||
</ng-container> | ||
{{ item.channels[address.channelId]['text'] }} | ||
</ion-label> | ||
<ion-label *ngIf="item.channels[address.channelId]['text'].length == 0"> | ||
<ng-container | ||
[ngSwitch]="item.channels[address.channelId]['level']"> | ||
<ion-text *ngSwitchCase="'INFO'" color="success" translate> | ||
General.info | ||
</ion-text> | ||
<ion-text *ngSwitchCase="'WARNING'" color="warning" translate> | ||
General.warning | ||
</ion-text> | ||
<ion-text *ngSwitchCase="'FAULT'" color="danger" translate> | ||
General.fault | ||
</ion-text> | ||
</ng-container> | ||
{{ address.channelId.toString() }} | ||
</ion-label> | ||
</ng-container> | ||
</ng-container> | ||
</ng-container> | ||
</ng-container> | ||
</ion-label> | ||
<ion-icon style="cursor: pointer" | ||
*ngIf="currentData.channel[item.id+'/State'] != null && currentData.channel[item.id+'/State'] > 0 && !item['showProperties']" | ||
name="arrow-down-circle-outline" color="primary" | ||
(click)="item['showProperties'] = !item['showProperties']; subscribeInfoChannels(item)"> | ||
</ion-icon> | ||
|
||
<ion-icon style="cursor: pointer" *ngIf="item['showProperties'] == true" | ||
name="arrow-up-circle-outline" color="primary" | ||
(click)="item['showProperties'] = !item['showProperties']; unsubscribeInfoChannels(item)"> | ||
</ion-icon> | ||
|
||
<ng-container [ngSwitch]="currentData.channel[item.id+'/State']"> | ||
<ion-icon *ngSwitchCase="0" color="success" name="checkmark-circle-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="1" color="success" name="information-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="2" color="warning" name="alert-outline"></ion-icon> | ||
<ion-icon *ngSwitchCase="3" color="danger" name="alert-outline"></ion-icon> | ||
</ng-container> | ||
</ion-item> | ||
</ng-container> | ||
</ion-list> | ||
</ion-card-content> | ||
</ion-content> | ||
</ng-container> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Component } from '@angular/core'; | ||
import { Edge, Service, Websocket, ChannelAddress } from '../../../shared/shared'; | ||
import { ModalController } from '@ionic/angular'; | ||
import { environment } from 'src/environments'; | ||
import { CategorizedComponents, EdgeConfig } from '../../edge/edgeconfig'; | ||
import { Subject } from 'rxjs'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: StatusSingleComponent.SELECTOR, | ||
templateUrl: './status.component.html' | ||
}) | ||
export class StatusSingleComponent { | ||
|
||
private stopOnDestroy: Subject<void> = new Subject<void>(); | ||
|
||
public edge: Edge; | ||
public config: EdgeConfig; | ||
public components: CategorizedComponents[]; | ||
public subscribedInfoChannels: ChannelAddress[] = []; | ||
public onInfoChannels: ChannelAddress[] = []; | ||
public env = environment; | ||
|
||
|
||
private static readonly SELECTOR = "statussingle"; | ||
|
||
|
||
constructor( | ||
private route: ActivatedRoute, | ||
public modalCtrl: ModalController, | ||
public service: Service, | ||
private websocket: Websocket, | ||
) { } | ||
|
||
ngOnInit() { | ||
this.service.getConfig().then(config => { | ||
this.config = config; | ||
let categorizedComponentIds: string[] = [] | ||
this.components = config.listActiveComponents(categorizedComponentIds); | ||
this.components.forEach(categorizedComponent => { | ||
categorizedComponent.components.forEach(component => { | ||
// sets all arrow buttons to standard position (folded) | ||
component['showProperties'] = false; | ||
this.subscribedInfoChannels.push( | ||
new ChannelAddress(component.id, 'State') | ||
) | ||
}) | ||
}) | ||
//need to subscribe on currentedge because component is opened by app.component | ||
this.service.currentEdge.pipe(takeUntil(this.stopOnDestroy)).subscribe(edge => { | ||
this.edge = edge; | ||
edge.subscribeChannels(this.websocket, StatusSingleComponent.SELECTOR, this.subscribedInfoChannels); | ||
}) | ||
}) | ||
} | ||
|
||
public subscribeInfoChannels(component: EdgeConfig.Component) { | ||
Object.keys(component.channels).forEach(channel => { | ||
if (component.channels[channel]['level']) { | ||
this.subscribedInfoChannels.push(new ChannelAddress(component.id, channel)) | ||
this.onInfoChannels.push(new ChannelAddress(component.id, channel)) | ||
} | ||
}); | ||
if (this.edge) { | ||
this.edge.subscribeChannels(this.websocket, StatusSingleComponent.SELECTOR, this.subscribedInfoChannels); | ||
} | ||
} | ||
|
||
public unsubscribeInfoChannels(component: EdgeConfig.Component) { | ||
//removes unsubscribed elements from subscribedInfoChannels array | ||
this.onInfoChannels.forEach(onInfoChannel => { | ||
this.subscribedInfoChannels.forEach((subChannel, index) => { | ||
if (onInfoChannel.channelId == subChannel.channelId && component.id == subChannel.componentId) { | ||
this.subscribedInfoChannels.splice(index, 1); | ||
} | ||
}); | ||
}) | ||
//clear onInfoChannels Array | ||
this.onInfoChannels = this.onInfoChannels.filter((channel) => channel.componentId != component.id) | ||
if (this.edge) { | ||
this.edge.subscribeChannels(this.websocket, StatusSingleComponent.SELECTOR, this.subscribedInfoChannels); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.stopOnDestroy.next(); | ||
this.stopOnDestroy.complete(); | ||
} | ||
} |
Oops, something went wrong.