Skip to content

Commit 8c2ee5a

Browse files
author
Jeppe Elkjær Jørgensen
committed
IOT-264 fix otaakey
1 parent 8a89263 commit 8c2ee5a

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

src/app/shared/form/form-body-iot-devices/form-body-iot-devices.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ <h3>{{'QUESTION.OTAA' | translate}}</h3>
151151
<p>{{'QUESTION.OTAA-ABP-CONFIG-HELP' | translate}}</p>
152152
<div class="form-group mt-5">
153153
<label class="form-label" for="OTAAapplicationKey">{{'QUESTION.OTAAAPPLICATIONKEY' | translate}}*</label>
154-
<input type="text" id="OTAAapplicationKey" name="OTAAapplicationKey" maxLength="16"
154+
<input type="text" id="OTAAapplicationKey" name="OTAAapplicationKey" maxLength="32"
155155
[placeholder]="'QUESTION.OTAAAPPLICATIONKEY-PLACEHOLDER' | translate" class="form-control"
156156
[(ngModel)]="iotDevice.lorawanSettings.OTAAapplicationKey"
157157
[ngClass]="{'is-invalid' : formFailedSubmit && errorFields.includes('OTAAapplicationKey'), 'is-valid' : formFailedSubmit && !errorFields.includes('OTAAapplicationKey')}">

src/app/shared/form/form-body-iot-devices/form-body-iot-devices.component.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ServiceProfileService } from '../../services/service-profile.service';
1717
import { DeviceProfile } from 'src/app/profiles/device-profiles/device-profile.model';
1818
import { DeviceProfileService } from '../../services/device-profile.service';
1919
import { 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

Comments
 (0)