Browse Source

UI: Refactoring CoAP power mode setting

pull/4958/head
Vladyslav_Prykhodko 5 years ago
committed by Andrew Shvayka
parent
commit
872800c864
  1. 38
      ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts
  2. 8
      ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts
  3. 8
      ui-ngx/src/app/shared/models/device.models.ts

38
ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts

@ -104,9 +104,9 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
}),
clientSettings: this.fb.group({
powerMode: [PowerMode.DRX, Validators.required],
edrxCycle: [{disabled: true, value: 0}],
psmActivityTimer: [{disabled: true, value: 0}],
pagingTransmissionWindow: [{disabled: true, value: 0}]
edrxCycle: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
psmActivityTimer: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
pagingTransmissionWindow: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]]
})}
);
this.coapTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe(
@ -120,23 +120,14 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
if (powerMode === PowerMode.E_DRX) {
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle')
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow')
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
this.clearValidatorsPSKMode();
this.disablePSKMode();
} else if (powerMode === PowerMode.PSM) {
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer')
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
this.clearValidatorsEdrxMode();
this.disableEdrxMode();
} else {
this.clearValidatorsEdrxMode();
this.clearValidatorsPSKMode();
this.disableEdrxMode();
this.disablePSKMode();
}
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').updateValueAndValidity({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').updateValueAndValidity({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').updateValueAndValidity({emitEvent: false});
});
this.coapTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
@ -189,7 +180,15 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
writeValue(value: CoapDeviceProfileTransportConfiguration | null): void {
if (isDefinedAndNotNull(value)) {
if (!value.clientSettings) {
value.clientSettings = {
powerMode: PowerMode.DRX
};
}
this.coapTransportConfigurationFormGroup.patchValue(value, {emitEvent: false});
if (!this.disabled) {
this.coapTransportConfigurationFormGroup.get('clientSettings.powerMode').updateValueAndValidity({onlySelf: true});
}
this.updateCoapDeviceTypeBasedControls(value.coapDeviceTypeConfiguration?.coapDeviceType);
}
}
@ -203,18 +202,15 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
this.propagateChange(configuration);
}
private clearValidatorsPSKMode() {
private disablePSKMode() {
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').reset(0, {emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').clearValidators();
}
private clearValidatorsEdrxMode() {
private disableEdrxMode() {
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').reset(0, {emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').clearValidators();
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').reset(0, {emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').clearValidators();
}
}

8
ui-ngx/src/app/modules/home/pages/device/data/coap-device-transport-configuration.component.ts

@ -112,6 +112,7 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
this.coapDeviceTransportForm.disable({emitEvent: false});
} else {
this.coapDeviceTransportForm.enable({emitEvent: false});
this.coapDeviceTransportForm.get('powerMode').updateValueAndValidity({onlySelf: true});
}
}
@ -119,12 +120,7 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
if (isDefinedAndNotNull(value)) {
this.coapDeviceTransportForm.patchValue(value, {emitEvent: false});
} else {
this.coapDeviceTransportForm.patchValue({
powerMode: null,
edrxCycle: 0,
psmActivityTimer: 0,
pagingTransmissionWindow: 0
}, {emitEvent: false});
this.coapDeviceTransportForm.get('powerMode').patchValue(null, {emitEvent: false});
}
if (!this.disabled) {
this.coapDeviceTransportForm.get('powerMode').updateValueAndValidity({onlySelf: true});

8
ui-ngx/src/app/shared/models/device.models.ts

@ -244,6 +244,13 @@ export interface MqttDeviceProfileTransportConfiguration {
[key: string]: any;
}
export interface CoapClientSetting {
powerMode?: PowerMode | null;
edrxCycle?: number;
pagingTransmissionWindow?: number;
psmActivityTimer?: number;
}
export interface CoapDeviceProfileTransportConfiguration {
coapDeviceTypeConfiguration?: {
coapDeviceType?: CoapTransportDeviceType;
@ -252,6 +259,7 @@ export interface CoapDeviceProfileTransportConfiguration {
[key: string]: any;
};
};
clientSettings?: CoapClientSetting;
}
export interface Lwm2mDeviceProfileTransportConfiguration {

Loading…
Cancel
Save