@@ -17,6 +17,7 @@ import { ServiceProfileService } from '../../services/service-profile.service';
1717import { DeviceProfile } from 'src/app/profiles/device-profiles/device-profile.model' ;
1818import { DeviceProfileService } from '../../services/device-profile.service' ;
1919import { SharedVariableService } from '@app/shared-variable/shared-variable.service' ;
20+ import { ActivationType } from '@shared/enums/activation-type' ;
2021
2122@Component ( {
2223 selector : 'app-form-body-iot-devices' ,
@@ -100,10 +101,14 @@ export class FormBodyIotDevicesComponent implements OnInit, OnDestroy {
100101 }
101102
102103 onChangeDeviceProfile ( deviceProfileId : string ) {
104+ this . getDeviceProfile ( deviceProfileId ) ;
105+ }
106+
107+ getDeviceProfile ( deviceProfileId : string ) {
103108 this . deviceProfileSubscription = this . deviceProfileService . getOne ( deviceProfileId )
104- . subscribe ( ( response ) => {
105- this . OTAA = response . deviceProfile . supportsJoin ;
106- } ) ;
109+ . subscribe ( ( response ) => {
110+ this . OTAA = response . deviceProfile . supportsJoin ;
111+ } ) ;
107112 }
108113
109114 getServiceProfiles ( ) {
@@ -121,18 +126,31 @@ export class FormBodyIotDevicesComponent implements OnInit, OnDestroy {
121126 }
122127
123128 onSubmit ( ) : void {
124- this . cleanModelBasedOnType ( ) ;
129+ this . adjustModelBasedOnType ( ) ;
125130 if ( this . id ) {
126131 this . updateIoTDevice ( this . id ) ;
127132 } else {
128133 this . postIoTDevice ( ) ;
129134 }
130135 }
131136
132- private cleanModelBasedOnType ( ) {
137+ setActivationType ( ) {
138+ if ( this . OTAA ) {
139+ this . iotDevice . lorawanSettings . activationType = ActivationType . OTAA ;
140+ } else {
141+ this . iotDevice . lorawanSettings . activationType = ActivationType . ABP ;
142+ }
143+ }
144+
145+ private adjustModelBasedOnType ( ) {
133146 switch ( this . iotDevice . type ) {
134147 case DeviceType . GENERICHTTP : {
135148 this . iotDevice . lorawanSettings = null ;
149+ break ;
150+ }
151+ case DeviceType . LORAWAN : {
152+ this . setActivationType ( ) ;
153+ break ;
136154 }
137155 }
138156 }
@@ -172,21 +190,26 @@ export class FormBodyIotDevicesComponent implements OnInit, OnDestroy {
172190 handleError ( error : HttpErrorResponse ) {
173191 this . errorFields = [ ] ;
174192 this . errorMessages = [ ] ;
175- error . error . message . forEach ( ( err ) => {
176- if ( err . property === 'lorawanSettings' ) {
177- err . children . forEach ( element => {
178- this . errorFields . push ( element . property ) ;
193+ if ( typeof error . error . message === 'string' ) {
194+ this . errorMessages . push ( error . error . message ) ;
195+ } else {
196+ error . error . message . forEach ( ( err ) => {
197+ if ( err . property === 'lorawanSettings' ) {
198+ err . children . forEach ( element => {
199+ this . errorFields . push ( element . property ) ;
200+ this . errorMessages = this . errorMessages . concat (
201+ Object . values ( element . constraints )
202+ ) ;
203+ } ) ;
204+ } else {
205+ this . errorFields . push ( err . property ) ;
179206 this . errorMessages = this . errorMessages . concat (
180- Object . values ( element . constraints )
207+ Object . values ( err . constraints )
181208 ) ;
182- } ) ;
183- } else {
184- this . errorFields . push ( err . property ) ;
185- this . errorMessages = this . errorMessages . concat (
186- Object . values ( err . constraints )
187- ) ;
188- }
189- } ) ;
209+ }
210+ } ) ;
211+ }
212+
190213 }
191214
192215 onCoordinateKey ( event : any ) {
0 commit comments