Skip to content

Commit c56b1fd

Browse files
pr changes
1 parent a1ec2d0 commit c56b1fd

File tree

3 files changed

+30
-37
lines changed

3 files changed

+30
-37
lines changed

src/app/applications/iot-devices/iot-device-copy/iot-device-copy.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
22

3-
import { IotDeviceEditComponent } from "./iot-device-edit.component";
3+
import { IotDeviceEditComponent } from "../iot-device-edit/iot-device-edit.component";
44

55
describe("IotDeviceEditComponent", () => {
66
let component: IotDeviceEditComponent;

src/app/applications/iot-devices/iot-device-detail/iot-device-detail.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ export class IoTDeviceDetailComponent implements OnInit, OnDestroy {
105105
"IOTDEVICE-TABLE-ROW.RESET-API-KEY",
106106
"IOTDEVICE.GENERIC_HTTP.RESET-API-KEY",
107107
"GEN.CANCEL",
108+
"GEN.BACK"
108109
])
109110
.subscribe(translations => {
110-
this.backButton.label = translations["NAV.APPLICATIONS"];
111+
this.backButton.label = translations["GEN.BACK"];
111112
this.dropdownButton.label = translations["IOTDEVICE-TABLE-ROW.SHOW-OPTIONS"];
112113
this.titleService.setTitle(translations["TITLE.IOTDEVICE"]);
113114

src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
181181
this.iotDevice.mqttInternalBrokerSettings.caCertificate = undefined;
182182
this.iotDevice.mqttInternalBrokerSettings.deviceCertificate = undefined;
183183
this.iotDevice.mqttInternalBrokerSettings.deviceCertificateKey = undefined;
184-
this.iotDevice.mqttInternalBrokerSettings.mqttPort = undefined;
185-
this.iotDevice.mqttInternalBrokerSettings.mqttURL = undefined;
186184
this.iotDevice.mqttInternalBrokerSettings.mqttpassword = undefined;
187185
this.iotDevice.mqttInternalBrokerSettings.mqtttopicname = undefined;
188186
this.iotDevice.mqttInternalBrokerSettings.mqttusername = undefined;
@@ -334,40 +332,34 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
334332
this.iotDevice.lorawanSettings.devEUI = this.iotDevice.lorawanSettings.devEUI.replace(/[^0-9A-Fa-f]/g, "");
335333
}
336334

337-
this.iotDeviceService.createIoTDevice(this.iotDevice).subscribe({
338-
next: (createdDevice: IotDevice) => {
339-
if (!this.copyPayloadAndDatatarget) {
340-
this.navigateToDeviceDetails(createdDevice);
341-
return;
342-
}
335+
//First create the device
336+
this.iotDeviceService.createIoTDevice(this.iotDevice).subscribe((createdDevice: IotDevice) => {
337+
if (!this.copyPayloadAndDatatarget) {
338+
this.navigateToDeviceDetails(createdDevice);
339+
return;
340+
}
343341

344-
this.datatargetPayloadService.getByIoTDevice(this.deviceId).subscribe({
345-
next: (result: PayloadDeviceDatatargetGetManyResponse) => {
346-
const appendObservables = result.data.map(element =>
347-
this.datatargetPayloadService.appendCopiedIoTDevice(element.id, { deviceId: createdDevice.id })
348-
);
349-
350-
if (appendObservables.length === 0) {
351-
this.navigateToDeviceDetails(createdDevice);
352-
return;
353-
}
354-
355-
forkJoin(appendObservables).subscribe({
356-
next: () => this.navigateToDeviceDetails(createdDevice),
357-
error: (error: HttpErrorResponse) => {
358-
this.formFailedSubmitHandleError(error);
359-
},
360-
});
361-
},
362-
error: (error: HttpErrorResponse) => {
363-
this.formFailedSubmitHandleError(error);
364-
},
365-
});
366-
},
367-
error: (error: HttpErrorResponse) => {
368-
this.formFailedSubmitHandleError(error);
369-
},
370-
});
342+
//If it's the copy device flow, then get all datatargets from the device that we want to copy.
343+
this.datatargetPayloadService
344+
.getByIoTDevice(this.deviceId)
345+
.subscribe((result: PayloadDeviceDatatargetGetManyResponse) => {
346+
//For each of these datatargets, append the copied device to that datatarget. First we make the observables
347+
const appendToDatatargetObservables = result.data.map(element =>
348+
this.datatargetPayloadService.appendCopiedIoTDevice(element.id, { deviceId: createdDevice.id })
349+
);
350+
351+
if (appendToDatatargetObservables.length === 0) {
352+
this.navigateToDeviceDetails(createdDevice);
353+
return;
354+
}
355+
356+
//Forkjoin is running all observables in parallel and when all are done it returns.
357+
forkJoin(appendToDatatargetObservables).subscribe(
358+
() => this.navigateToDeviceDetails(createdDevice),
359+
this.formFailedSubmitHandleError
360+
);
361+
}, this.formFailedSubmitHandleError);
362+
}, this.formFailedSubmitHandleError);
371363
}
372364

373365
formFailedSubmitHandleError(error: HttpErrorResponse) {

0 commit comments

Comments
 (0)