@@ -181,8 +181,6 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
181
181
this . iotDevice . mqttInternalBrokerSettings . caCertificate = undefined ;
182
182
this . iotDevice . mqttInternalBrokerSettings . deviceCertificate = undefined ;
183
183
this . iotDevice . mqttInternalBrokerSettings . deviceCertificateKey = undefined ;
184
- this . iotDevice . mqttInternalBrokerSettings . mqttPort = undefined ;
185
- this . iotDevice . mqttInternalBrokerSettings . mqttURL = undefined ;
186
184
this . iotDevice . mqttInternalBrokerSettings . mqttpassword = undefined ;
187
185
this . iotDevice . mqttInternalBrokerSettings . mqtttopicname = undefined ;
188
186
this . iotDevice . mqttInternalBrokerSettings . mqttusername = undefined ;
@@ -334,40 +332,34 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
334
332
this . iotDevice . lorawanSettings . devEUI = this . iotDevice . lorawanSettings . devEUI . replace ( / [ ^ 0 - 9 A - F a - f ] / g, "" ) ;
335
333
}
336
334
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
+ }
343
341
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 ) ;
371
363
}
372
364
373
365
formFailedSubmitHandleError ( error : HttpErrorResponse ) {
0 commit comments