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({ clientSettings: this.fb.group({
powerMode: [PowerMode.DRX, Validators.required], powerMode: [PowerMode.DRX, Validators.required],
edrxCycle: [{disabled: true, value: 0}], edrxCycle: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
psmActivityTimer: [{disabled: true, value: 0}], psmActivityTimer: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]],
pagingTransmissionWindow: [{disabled: true, value: 0}] pagingTransmissionWindow: [{disabled: true, value: 0}, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]]
})} })}
); );
this.coapTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe( this.coapTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe(
@ -120,23 +120,14 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
if (powerMode === PowerMode.E_DRX) { if (powerMode === PowerMode.E_DRX) {
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').enable({emitEvent: false}); this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').enable({emitEvent: false}); this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle') this.disablePSKMode();
.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();
} else if (powerMode === PowerMode.PSM) { } else if (powerMode === PowerMode.PSM) {
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').enable({emitEvent: false}); this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').enable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer') this.disableEdrxMode();
.setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
this.clearValidatorsEdrxMode();
} else { } else {
this.clearValidatorsEdrxMode(); this.disableEdrxMode();
this.clearValidatorsPSKMode(); 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( this.coapTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
@ -189,7 +180,15 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
writeValue(value: CoapDeviceProfileTransportConfiguration | null): void { writeValue(value: CoapDeviceProfileTransportConfiguration | null): void {
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
if (!value.clientSettings) {
value.clientSettings = {
powerMode: PowerMode.DRX
};
}
this.coapTransportConfigurationFormGroup.patchValue(value, {emitEvent: false}); this.coapTransportConfigurationFormGroup.patchValue(value, {emitEvent: false});
if (!this.disabled) {
this.coapTransportConfigurationFormGroup.get('clientSettings.powerMode').updateValueAndValidity({onlySelf: true});
}
this.updateCoapDeviceTypeBasedControls(value.coapDeviceTypeConfiguration?.coapDeviceType); this.updateCoapDeviceTypeBasedControls(value.coapDeviceTypeConfiguration?.coapDeviceType);
} }
} }
@ -203,18 +202,15 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
this.propagateChange(configuration); this.propagateChange(configuration);
} }
private clearValidatorsPSKMode() { private disablePSKMode() {
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').disable({emitEvent: false}); this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.psmActivityTimer').reset(0, {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').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.edrxCycle').reset(0, {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').disable({emitEvent: false});
this.coapTransportConfigurationFormGroup.get('clientSettings.pagingTransmissionWindow').reset(0, {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}); this.coapDeviceTransportForm.disable({emitEvent: false});
} else { } else {
this.coapDeviceTransportForm.enable({emitEvent: false}); this.coapDeviceTransportForm.enable({emitEvent: false});
this.coapDeviceTransportForm.get('powerMode').updateValueAndValidity({onlySelf: true});
} }
} }
@ -119,12 +120,7 @@ export class CoapDeviceTransportConfigurationComponent implements ControlValueAc
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
this.coapDeviceTransportForm.patchValue(value, {emitEvent: false}); this.coapDeviceTransportForm.patchValue(value, {emitEvent: false});
} else { } else {
this.coapDeviceTransportForm.patchValue({ this.coapDeviceTransportForm.get('powerMode').patchValue(null, {emitEvent: false});
powerMode: null,
edrxCycle: 0,
psmActivityTimer: 0,
pagingTransmissionWindow: 0
}, {emitEvent: false});
} }
if (!this.disabled) { if (!this.disabled) {
this.coapDeviceTransportForm.get('powerMode').updateValueAndValidity({onlySelf: true}); 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; [key: string]: any;
} }
export interface CoapClientSetting {
powerMode?: PowerMode | null;
edrxCycle?: number;
pagingTransmissionWindow?: number;
psmActivityTimer?: number;
}
export interface CoapDeviceProfileTransportConfiguration { export interface CoapDeviceProfileTransportConfiguration {
coapDeviceTypeConfiguration?: { coapDeviceTypeConfiguration?: {
coapDeviceType?: CoapTransportDeviceType; coapDeviceType?: CoapTransportDeviceType;
@ -252,6 +259,7 @@ export interface CoapDeviceProfileTransportConfiguration {
[key: string]: any; [key: string]: any;
}; };
}; };
clientSettings?: CoapClientSetting;
} }
export interface Lwm2mDeviceProfileTransportConfiguration { export interface Lwm2mDeviceProfileTransportConfiguration {

Loading…
Cancel
Save