diff --git a/ui-ngx/src/app/modules/home/components/home-components.module.ts b/ui-ngx/src/app/modules/home/components/home-components.module.ts
index 735e11c2c8..71b983b4d4 100644
--- a/ui-ngx/src/app/modules/home/components/home-components.module.ts
+++ b/ui-ngx/src/app/modules/home/components/home-components.module.ts
@@ -141,7 +141,7 @@ import { DashboardImageDialogComponent } from '@home/components/dashboard-page/d
import { WidgetContainerComponent } from '@home/components/widget/widget-container.component';
import { SnmpDeviceProfileTransportModule } from '@home/components/profile/device/snpm/snmp-device-profile-transport.module';
import { DeviceCredentialsModule } from '@home/components/device/device-credentials.module';
-import { PowerModeSettingComponent } from '@home/components/profile/device/common/power-mode-setting.component';
+import { DeviceProfileCommonModule } from '@home/components/profile/device/common/device-profile-common.module';
@NgModule({
declarations:
@@ -260,8 +260,7 @@ import { PowerModeSettingComponent } from '@home/components/profile/device/commo
DashboardStateDialogComponent,
DashboardImageDialogComponent,
EmbedDashboardDialogComponent,
- DisplayWidgetTypesPanelComponent,
- PowerModeSettingComponent
+ DisplayWidgetTypesPanelComponent
],
imports: [
CommonModule,
@@ -270,7 +269,8 @@ import { PowerModeSettingComponent } from '@home/components/profile/device/commo
Lwm2mProfileComponentsModule,
SnmpDeviceProfileTransportModule,
StatesControllerModule,
- DeviceCredentialsModule
+ DeviceCredentialsModule,
+ DeviceProfileCommonModule
],
exports: [
EntitiesTableComponent,
@@ -371,8 +371,7 @@ import { PowerModeSettingComponent } from '@home/components/profile/device/commo
DashboardStateDialogComponent,
DashboardImageDialogComponent,
EmbedDashboardDialogComponent,
- DisplayWidgetTypesPanelComponent,
- PowerModeSettingComponent
+ DisplayWidgetTypesPanelComponent
],
providers: [
WidgetComponentService,
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/common/device-profile-common.module.ts b/ui-ngx/src/app/modules/home/components/profile/device/common/device-profile-common.module.ts
new file mode 100644
index 0000000000..81bdcc49af
--- /dev/null
+++ b/ui-ngx/src/app/modules/home/components/profile/device/common/device-profile-common.module.ts
@@ -0,0 +1,34 @@
+///
+/// Copyright © 2016-2021 The Thingsboard Authors
+///
+/// Licensed under the Apache License, Version 2.0 (the "License");
+/// you may not use this file except in compliance with the License.
+/// You may obtain a copy of the License at
+///
+/// http://www.apache.org/licenses/LICENSE-2.0
+///
+/// Unless required by applicable law or agreed to in writing, software
+/// distributed under the License is distributed on an "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+/// See the License for the specific language governing permissions and
+/// limitations under the License.
+///
+
+import { NgModule } from '@angular/core';
+import { PowerModeSettingComponent } from '@home/components/profile/device/common/power-mode-setting.component';
+import { SharedModule } from '@shared/shared.module';
+import { CommonModule } from '@angular/common';
+
+@NgModule({
+ declarations: [
+ PowerModeSettingComponent
+ ],
+ imports: [
+ CommonModule,
+ SharedModule
+ ],
+ exports: [
+ PowerModeSettingComponent
+ ]
+})
+export class DeviceProfileCommonModule { }
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
index 6e4f4f3929..834071dfb4 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
@@ -132,7 +132,7 @@
{{ 'device-profile.lwm2m.fw-update-strategy-data' | translate }}
-
+
{{ 'device-profile.lwm2m.fw-update-resource' | translate }}
@@ -149,7 +149,7 @@
{{ 'device-profile.lwm2m.sw-update-strategy-package-uri' | translate }}
-
+
{{ 'device-profile.lwm2m.sw-update-resource' | translate }}
@@ -159,25 +159,8 @@
{{ 'device-profile.lwm2m.composite-operations-support' | translate }}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
index 1fd6835cb7..0934a9b6e2 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
@@ -16,7 +16,15 @@
import { DeviceProfileTransportConfiguration } from '@shared/models/device.models';
import { Component, forwardRef, Input, OnDestroy } from '@angular/core';
-import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
+import {
+ ControlValueAccessor,
+ FormBuilder,
+ FormGroup, NG_VALIDATORS,
+ NG_VALUE_ACCESSOR,
+ ValidationErrors,
+ Validator,
+ Validators
+} from '@angular/forms';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import {
ATTRIBUTE,
@@ -30,10 +38,7 @@ import {
DEFAULT_NOTIF_IF_DESIBLED,
DEFAULT_SW_UPDATE_RESOURCE,
getDefaultBootstrapServerSecurityConfig,
- getDefaultBootstrapServersSecurityConfig,
getDefaultLwM2MServerSecurityConfig,
- getDefaultProfileClientLwM2mSettingsConfig,
- getDefaultProfileObserveAttrConfig,
Instance,
INSTANCES,
KEY_NAME,
@@ -41,7 +46,6 @@ import {
ObjectLwM2M,
OBSERVE,
PowerMode,
- PowerModeTranslationMap,
RESOURCES,
ServerSecurityConfig,
TELEMETRY
@@ -58,13 +62,19 @@ import { takeUntil } from 'rxjs/operators';
selector: 'tb-profile-lwm2m-device-transport-configuration',
templateUrl: './lwm2m-device-profile-transport-configuration.component.html',
styleUrls: ['./lwm2m-device-profile-transport-configuration.component.scss'],
- providers: [{
- provide: NG_VALUE_ACCESSOR,
- useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent),
- multi: true
- }]
+ providers: [
+ {
+ provide: NG_VALUE_ACCESSOR,
+ useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent),
+ multi: true
+ },
+ {
+ provide: NG_VALIDATORS,
+ useExisting: forwardRef(() => Lwm2mDeviceProfileTransportConfigurationComponent),
+ multi: true
+ }]
})
-export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, Validators, OnDestroy {
+export class Lwm2mDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, Validator, OnDestroy {
private configurationValue: Lwm2mProfileConfigModels;
private requiredValue: boolean;
@@ -76,10 +86,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
lwm2mDeviceProfileFormGroup: FormGroup;
lwm2mDeviceConfigFormGroup: FormGroup;
sortFunction: (key: string, value: object) => object;
- isFwUpdateStrategy: boolean;
- isSwUpdateStrategy: boolean;
- powerMods = Object.values(PowerMode);
- powerModeTranslationMap = PowerModeTranslationMap;
get required(): boolean {
return this.requiredValue;
@@ -116,7 +122,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
fwUpdateResource: [{value: '', disabled: true}, []],
swUpdateResource: [{value: '', disabled: true}, []],
powerMode: [PowerMode.DRX, Validators.required],
- edrxCycle: [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]*')]],
compositeOperationsSupport: [false]
})
});
@@ -128,42 +136,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
).subscribe((fwStrategy) => {
if (fwStrategy === 2) {
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').enable({emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource')
- .patchValue(DEFAULT_FW_UPDATE_RESOURCE, {emitEvent: false});
- this.isFwUpdateStrategy = true;
} else {
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').disable({emitEvent: false});
- this.isFwUpdateStrategy = false;
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource')
+ .reset(DEFAULT_FW_UPDATE_RESOURCE, {emitEvent: false});
}
- this.otaUpdateFwStrategyValidate(true);
});
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe((swStrategy) => {
if (swStrategy === 2) {
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').enable({emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource')
- .patchValue(DEFAULT_SW_UPDATE_RESOURCE, {emitEvent: false});
- this.isSwUpdateStrategy = true;
} else {
- this.isSwUpdateStrategy = false;
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').disable({emitEvent: false});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource')
+ .reset(DEFAULT_SW_UPDATE_RESOURCE, {emitEvent: false});
}
- this.otaUpdateSwStrategyValidate(true);
- });
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode').valueChanges.pipe(
- takeUntil(this.destroy$)
- ).subscribe((powerMode: PowerMode) => {
- if (powerMode === PowerMode.E_DRX) {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').enable({emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').patchValue(0, {emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle')
- .setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
- } else {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').disable({emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').clearValidators();
- }
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').updateValueAndValidity({emitEvent: false});
});
this.lwm2mDeviceProfileFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
@@ -198,24 +186,33 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} else {
this.lwm2mDeviceProfileFormGroup.enable({emitEvent: false});
this.lwm2mDeviceConfigFormGroup.enable({emitEvent: false});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode').updateValueAndValidity({onlySelf: true});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').updateValueAndValidity({onlySelf: true});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').updateValueAndValidity({onlySelf: true});
}
}
async writeValue(value: Lwm2mProfileConfigModels | null) {
- if (isDefinedAndNotNull(value)) {
- if (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap) {
- this.configurationValue = value;
- } else {
- this.configurationValue = await this.defaultProfileConfig();
- }
+ if (isDefinedAndNotNull(value) && (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap)) {
+ this.configurationValue = value;
+ const defaultFormSettings = !(value.observeAttr.attribute.length && value.observeAttr.telemetry.length);
this.lwm2mDeviceConfigFormGroup.patchValue({
configurationJson: this.configurationValue
- }, {emitEvent: false});
+ }, {emitEvent: defaultFormSettings});
+ if (defaultFormSettings) {
+ await this.defaultProfileConfig();
+ }
this.initWriteValue();
}
}
- private async defaultProfileConfig(): Promise {
+ validate(): ValidationErrors | null {
+ return this.lwm2mDeviceProfileFormGroup.valid ? null : {
+ lwm2mDeviceProfile: false
+ };
+ }
+
+ private async defaultProfileConfig(): Promise {
let bootstrap: ServerSecurityConfig;
let lwm2m: ServerSecurityConfig;
try {
@@ -227,15 +224,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
bootstrap = getDefaultBootstrapServerSecurityConfig();
lwm2m = getDefaultLwM2MServerSecurityConfig();
}
- return {
- observeAttr: getDefaultProfileObserveAttrConfig(),
- bootstrap: {
- servers: getDefaultBootstrapServersSecurityConfig(),
- bootstrapServer: bootstrap,
- lwm2mServer: lwm2m
- },
- clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig()
- };
+
+ this.configurationValue.bootstrap.bootstrapServer = bootstrap;
+ this.configurationValue.bootstrap.lwm2mServer = lwm2m;
+ this.lwm2mDeviceConfigFormGroup.patchValue({
+ configurationJson: this.configurationValue
+ }, {emitEvent: false});
+ this.lwm2mDeviceProfileFormGroup.patchValue({
+ bootstrap: this.configurationValue.bootstrap
+ }, {emitEvent: false});
}
private initWriteValue = (): void => {
@@ -256,10 +253,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
}
private updateWriteValue = (value: ObjectLwM2M[]): void => {
- const fwResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.fwUpdateResource) ?
- this.configurationValue.clientLwM2mSettings.fwUpdateResource : '';
- const swResource = isDefinedAndNotNull(this.configurationValue.clientLwM2mSettings.swUpdateResource) ?
- this.configurationValue.clientLwM2mSettings.swUpdateResource : '';
this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value),
@@ -268,22 +261,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1,
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1,
- fwUpdateResource: fwResource,
- swUpdateResource: swResource,
+ fwUpdateResource: this.configurationValue.clientLwM2mSettings.fwUpdateResource || '',
+ swUpdateResource: this.configurationValue.clientLwM2mSettings.swUpdateResource || '',
powerMode: this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX,
edrxCycle: this.configurationValue.clientLwM2mSettings.edrxCycle || 0,
compositeOperationsSupport: this.configurationValue.clientLwM2mSettings.compositeOperationsSupport || false
}
},
{emitEvent: false});
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode')
- .patchValue(this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX, {emitEvent: false, onlySelf: true});
- this.configurationValue.clientLwM2mSettings.fwUpdateResource = fwResource;
- this.configurationValue.clientLwM2mSettings.swUpdateResource = swResource;
- this.isFwUpdateStrategy = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === 2;
- this.isSwUpdateStrategy = this.configurationValue.clientLwM2mSettings.swUpdateStrategy === 2;
- this.otaUpdateSwStrategyValidate();
- this.otaUpdateFwStrategyValidate();
+ if (!this.disabled) {
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode').updateValueAndValidity({onlySelf: true});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').updateValueAndValidity({onlySelf: true});
+ this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').updateValueAndValidity({onlySelf: true});
+ }
}
private updateModel = (): void => {
@@ -576,22 +566,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
});
}
- private otaUpdateFwStrategyValidate(updated = false): void {
- if (this.isFwUpdateStrategy) {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').setValidators([Validators.required]);
- } else {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').clearValidators();
- }
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').updateValueAndValidity({emitEvent: updated});
- }
-
- private otaUpdateSwStrategyValidate(updated = false): void {
- if (this.isSwUpdateStrategy) {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').setValidators([Validators.required]);
- } else {
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').clearValidators();
- }
- this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').updateValueAndValidity({emitEvent: updated});
+ get clientSettingsFormGroup(): FormGroup {
+ return this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings') as FormGroup;
}
}
diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component.html b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component.html
index 29822c3e1c..a1231e94ae 100644
--- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component.html
+++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-dialog.component.html
@@ -17,7 +17,7 @@
-->