-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/iot - 1522 test datatarget #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb6a042
UX for test-connection
AugustHA-Iterator 0ea1a9d
Merge branch 'stage' into feature/IoT-1522_TestDatatarget
AugustHA-Iterator 8793ebb
Fetch latest datapackage from selected device
fcv-iteratorIt a976afb
Enabled data target testing
fcv-iteratorIt 230eae3
Merge branch 'stage' into feature/IoT-1522_TestDatatarget
fcv-iteratorIt cdc7f14
Most merge fix
fcv-iteratorIt 52770e9
PR fixes
fcv-iteratorIt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
...lications/datatarget/datatarget-test-connection/datatarget-test-connection.component.html
This file contains hidden or 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,84 @@ | ||
| <div class="container-fluid"> | ||
| <div class="row"> | ||
| <div class="col-md-6 d-flex align-items-stretch"> | ||
| <div class="jumbotron jumbotron--full-width"> | ||
| <h3>{{ "DATATARGET.TEST_CONNECTION.TEST-CONNECTION" | translate }}</h3> | ||
| <div *ngIf="dataTarget.type === DataTargetType.MQTT"> | ||
| <button (click)="pingDataTarget()" | ||
| class="mt-3 btn btn-primary"> | ||
| {{ "DATATARGET.TEST_CONNECTION.TEST-CONNECTION" | translate }} | ||
| </button> | ||
| <p class="mt-2">{{ "DATATARGET.TEST_CONNECTION.SEND-PING-TO-DATATARGET" | translate }}</p> | ||
| <mat-divider></mat-divider> | ||
| </div> | ||
| <p class="mt-3 font-weight-bold">{{ "DATATARGET.TEST_CONNECTION.SEND-LATEST-PACKAGE" | translate }}</p> | ||
| <mat-select | ||
| (selectionChange)="getLastPackage($event)" | ||
| [placeholder]="'DATATARGET.TEST_CONNECTION.CHOOSE-IOT-DEVICE' | translate" | ||
| class="mt-3 form-control" | ||
| > | ||
| <mat-option *ngFor="let iotDevice of iotDevices" [value]="iotDevice.id"> | ||
| {{ iotDevice.name }} | ||
| </mat-option> | ||
| </mat-select> | ||
| <mat-select | ||
| [(value)]="payloadDecoderId" | ||
| [placeholder]="'DATATARGET.TEST_CONNECTION.CHOOSE-PAYLOAD-DECODER' | translate" | ||
| class="mt-3 form-control"> | ||
| <mat-option [value]="0"> | ||
| {{ "QUESTION.DATATARGET.NO-PAYLOAD-DECODER-SELECTED" | translate }} | ||
| </mat-option> | ||
| <mat-option *ngFor="let payloadDecoder of payloadDecoders" [value]="payloadDecoder.id"> | ||
| {{ payloadDecoder.name }} | ||
| </mat-option> | ||
| </mat-select> | ||
| <button (click)="pingDataTarget(payloadData)" [disabled]="!payloadData" | ||
| class="mt-3 btn btn-primary">{{ "DATATARGET.TEST_CONNECTION.SEND-DATA-PACKAGE" | translate }} | ||
| </button> | ||
| <p class="mt-2" style="white-space: pre-wrap"> | ||
| {{ "DATATARGET.TEST_CONNECTION.SEND-DATA-PACKAGE-DESCRIPTION" | translate }} | ||
| {{ dataTarget.type === DataTargetType.MQTT ? ("DATATARGET.TEST_CONNECTION.MQTT-DISCLAIMER"| translate) : "" }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <div class="col-md-6 d-flex align-items-stretch min-height-400"> | ||
| <div class="jumbotron jumbotron--full-width"> | ||
| <h3>{{ "DATATARGET.TEST_CONNECTION.CHOSEN-DATA-PACKAGE" | translate }}</h3> | ||
| <ngx-monaco-editor | ||
| [(ngModel)]="payloadData" | ||
| [ngModelOptions]="{ standalone: true }" | ||
| [options]="editorJsonOutpuOptions" | ||
| class="height-85" | ||
| > | ||
| </ngx-monaco-editor> | ||
| </div> | ||
| </div> | ||
| <div class="col-md-6 d-flex align-items-stretch min-height-400"> | ||
| <div class="jumbotron jumbotron--full-width"> | ||
| <h3>{{ "DATATARGET.TEST_CONNECTION.SENT-DECODED-REQUEST" | translate }}</h3> | ||
| <ngx-monaco-editor | ||
| [(ngModel)]="decodedData" | ||
| [ngModelOptions]="{ standalone: true }" | ||
| [options]="editorJsonOutpuOptions" | ||
| class="height-85" | ||
| > | ||
| </ngx-monaco-editor> | ||
| </div> | ||
| </div> | ||
| <div class="col-md-6 d-flex align-items-stretch min-height-400"> | ||
| <div class="jumbotron jumbotron--full-width"> | ||
| <h3>{{ "DATATARGET.TEST_CONNECTION.RECEIVED-RESPONSE" | translate }}</h3> | ||
| <ngx-monaco-editor | ||
| [(ngModel)]="testResponse" | ||
| [ngModelOptions]="{ standalone: true }" | ||
| [options]="editorJsonOutpuOptions" | ||
| class="height-85" | ||
| > | ||
| </ngx-monaco-editor> | ||
| </div> | ||
| </div> | ||
| <div *ngIf="loading"> | ||
| <app-loading-spinner></app-loading-spinner> | ||
| </div> | ||
| </div> | ||
| </div> |
7 changes: 7 additions & 0 deletions
7
...lications/datatarget/datatarget-test-connection/datatarget-test-connection.component.scss
This file contains hidden or 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,7 @@ | ||
| .height-85 { | ||
| height: 85%; | ||
| } | ||
|
|
||
| .min-height-400 { | ||
| min-height: 400px; | ||
| } |
129 changes: 129 additions & 0 deletions
129
...pplications/datatarget/datatarget-test-connection/datatarget-test-connection.component.ts
This file contains hidden or 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,129 @@ | ||
| import { Component, OnDestroy, OnInit } from "@angular/core"; | ||
| import { IoTDeviceService } from "@applications/iot-devices/iot-device.service"; | ||
| import { ApplicationService } from "@applications/application.service"; | ||
| import { Application } from "@applications/application.model"; | ||
| import { IotDevice } from "@applications/iot-devices/iot-device.model"; | ||
| import { ActivatedRoute } from "@angular/router"; | ||
| import { MatSelectChange } from "@angular/material/select"; | ||
| import { DatatargetService } from "@applications/datatarget/datatarget.service"; | ||
| import { Datatarget } from "@applications/datatarget/datatarget.model"; | ||
| import { DataTargetType } from "@shared/enums/datatarget-type"; | ||
| import { PayloadDecoderMinimal } from "@payload-decoder/payload-decoder.model"; | ||
| import { PayloadDecoderService } from "@payload-decoder/payload-decoder.service"; | ||
| import { PayloadDeviceDatatargetService } from "@payload-decoder/payload-device-datatarget.service"; | ||
|
|
||
| @Component({ | ||
| selector: "app-datatarget-test-connection", | ||
| templateUrl: "./datatarget-test-connection.component.html", | ||
| styleUrl: "./datatarget-test-connection.component.scss", | ||
| }) | ||
| export class DatatargetTestConnectionComponent implements OnInit, OnDestroy { | ||
| editorJsonOutpuOptions = { | ||
| theme: "vs", | ||
| language: "json", | ||
| autoIndent: true, | ||
| roundedSelection: true, | ||
| minimap: { enabled: false }, | ||
| readOnly: true, | ||
| }; | ||
|
|
||
| public iotDevices: IotDevice[]; | ||
| public payloadDecoders: PayloadDecoderMinimal[]; | ||
| public payloadData = ""; | ||
| public testResponse = ""; | ||
| public decodedData = ""; | ||
| public dataTarget: Datatarget; | ||
| public payloadDecoderId: number; | ||
| public loading = false; | ||
| protected readonly DataTargetType = DataTargetType; | ||
| private applicationId: number; | ||
| private dataTargetId: number; | ||
| private iotDeviceId: number; | ||
| private subscriptions = []; | ||
|
|
||
| constructor( | ||
| private deviceService: IoTDeviceService, | ||
| private dataTargetService: DatatargetService, | ||
| private route: ActivatedRoute, | ||
| private payloadDecoderService: PayloadDecoderService, | ||
| private payloadDeviceDataTargetService: PayloadDeviceDatatargetService, | ||
| public applicationService: ApplicationService | ||
| ) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.applicationId = +this.route.parent.snapshot.paramMap.get("id"); | ||
| this.dataTargetId = +this.route.parent.snapshot.paramMap.get("datatargetId"); | ||
| this.getDevices(); | ||
| this.getDatatarget(); | ||
| this.getPayloadDecoders(); | ||
| } | ||
|
|
||
| ngOnDestroy() { | ||
| this.subscriptions.forEach(s => s?.unsubscribe()); | ||
| } | ||
|
|
||
| getDevices() { | ||
| const deviceSubscription = this.applicationService | ||
| .getApplication(this.applicationId) | ||
| .subscribe((application: Application) => { | ||
| this.iotDevices = application.iotDevices.sort((a, b) => a.name.localeCompare(b.name, "en", { numeric: true })); | ||
| }); | ||
|
|
||
| this.subscriptions.push(deviceSubscription); | ||
| } | ||
|
|
||
| getLastPackage(event: MatSelectChange) { | ||
| this.iotDeviceId = event.value; | ||
| const deviceSub = this.deviceService.getIoTDevice(event.value).subscribe((device: IotDevice) => { | ||
| if (device.latestReceivedMessage) { | ||
| this.payloadData = JSON.stringify(device.latestReceivedMessage.rawData, null, 2); | ||
| } | ||
| }); | ||
|
|
||
| const connectionSub = this.payloadDeviceDataTargetService.getByDataTarget(this.dataTargetId).subscribe(c => { | ||
| const connection = c.data.find(x => x.iotDevices.some(d => d.id === event.value)); | ||
| this.payloadDecoderId = connection.payloadDecoder.id; | ||
| }); | ||
|
|
||
| this.subscriptions.push(deviceSub, connectionSub); | ||
| } | ||
|
|
||
| pingDataTarget(dataPackage?: string) { | ||
| this.loading = true; | ||
| this.dataTargetService | ||
| .testDataTarget({ | ||
| dataTargetId: this.dataTargetId, | ||
| iotDeviceId: this.iotDeviceId, | ||
| payloadDecoderId: this.payloadDecoderId, | ||
| dataPackage: dataPackage, | ||
| }) | ||
| .subscribe( | ||
| response => { | ||
| this.testResponse = response?.result ? JSON.stringify(response.result, null, 2) : ""; | ||
| this.decodedData = response?.decodedPayload ? JSON.stringify(response.decodedPayload, null, 2) : ""; | ||
| }, | ||
| error => { | ||
| console.log(error); | ||
fcv-iteratorIt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| () => { | ||
| this.loading = false; | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| private getDatatarget() { | ||
| const dataTargetSubscription = this.dataTargetService.get(this.dataTargetId).subscribe((datatarget: Datatarget) => { | ||
| this.dataTarget = datatarget; | ||
| }); | ||
|
|
||
| this.subscriptions.push(dataTargetSubscription); | ||
| } | ||
|
|
||
| private getPayloadDecoders() { | ||
| const sub = this.payloadDecoderService.getMinimal().subscribe(result => { | ||
| this.payloadDecoders = result.data; | ||
| }); | ||
|
|
||
| this.subscriptions.push(sub); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.