Browse Source

Merge remote-tracking branch 'upstream/develop/3.3' into develop/3.3-edge

pull/3811/head
Volodymyr Babak 6 years ago
parent
commit
28f5d9ed9e
  1. 2
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java
  2. 7
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts
  3. 2
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
  4. 158
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts
  5. 1
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts
  6. 3
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances.component.ts
  7. 5
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts
  8. 1
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resource.component.ts
  9. 33
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts
  10. 18
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts

2
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2MTransportServiceImpl.java

@ -148,7 +148,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService {
public void onRegistered(LeshanServer lwServer, Registration registration, Collection<Observation> previousObsersations) { public void onRegistered(LeshanServer lwServer, Registration registration, Collection<Observation> previousObsersations) {
executorRegistered.submit(() -> { executorRegistered.submit(() -> {
try { try {
// log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration); LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration);
if (lwM2MClient != null) { if (lwM2MClient != null) {
lwM2MClient.setLwM2MTransportServiceImpl(this); lwM2MClient.setLwM2MTransportServiceImpl(this);

7
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts

@ -51,6 +51,7 @@ import { TranslateService } from '@ngx-translate/core';
export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor { export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor {
private requiredValue: boolean; private requiredValue: boolean;
private disabled = false;
valuePrev = null; valuePrev = null;
serverFormGroup: FormGroup; serverFormGroup: FormGroup;
@ -61,10 +62,6 @@ export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor {
lenMaxServerPublicKey = LEN_MAX_PUBLIC_KEY_RPK; lenMaxServerPublicKey = LEN_MAX_PUBLIC_KEY_RPK;
currentSecurityMode = null; currentSecurityMode = null;
@Input()
disabled: boolean;
@Input() @Input()
bootstrapServerIs: boolean; bootstrapServerIs: boolean;
@ -142,7 +139,7 @@ export class Lwm2mDeviceConfigServerComponent implements ControlValueAccessor {
Validators.maxLength(this.lenMaxServerPublicKey)]); Validators.maxLength(this.lenMaxServerPublicKey)]);
} }
writeValue(value: any): void { writeValue(value: ServerSecurityConfig): void {
if (value) { if (value) {
this.updateValueFields(value); this.updateValueFields(value);
} }

2
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
--> -->
<section style="padding-bottom: 16px;" mat-dialog-content> <section style="padding-bottom: 16px; margin: 0" mat-dialog-content>
<mat-tab-group dynamicHeight> <mat-tab-group dynamicHeight>
<mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}"> <mat-tab label="{{ 'device-profile.lwm2m.model-tab' | translate }}">
<ng-template matTabContent> <ng-template matTabContent>

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

@ -21,16 +21,11 @@ import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state'; import { AppState } from '@app/core/core.state';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { import {
ATTR, INSTANCES, RESOURCES, OBSERVE_ATTR_TELEMETRY, OBSERVE, ATTRIBUTE, TELEMETRY, KEY_NAME,
getDefaultProfileConfig, getDefaultProfileConfig,
Instance,
KEY_NAME,
ObjectLwM2M, ObjectLwM2M,
OBSERVE,
OBSERVE_ATTR,
ProfileConfigModels, ProfileConfigModels,
ResourceLwM2M, ModelValue
TELEMETRY
} from './profile-config.models'; } from './profile-config.models';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
@ -55,11 +50,6 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
lwm2mDeviceProfileFormGroup: FormGroup; lwm2mDeviceProfileFormGroup: FormGroup;
lwm2mDeviceConfigFormGroup: FormGroup; lwm2mDeviceConfigFormGroup: FormGroup;
observeAttr = OBSERVE_ATTR;
observe = OBSERVE;
attribute = ATTR;
telemetry = TELEMETRY;
keyName = KEY_NAME;
bootstrapServers: string; bootstrapServers: string;
bootstrapServer: string; bootstrapServer: string;
lwm2mServer: string; lwm2mServer: string;
@ -122,7 +112,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
} }
writeValue(value: any | null): void { writeValue(value: ProfileConfigModels | null): void {
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value; this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
this.lwm2mDeviceConfigFormGroup.patchValue({ this.lwm2mDeviceConfigFormGroup.patchValue({
configurationJson: this.configurationValue configurationJson: this.configurationValue
@ -131,7 +121,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private initWriteValue = (): void => { private initWriteValue = (): void => {
const modelValue = {objectIds: null, objectsList: []}; const modelValue = {objectIds: null, objectsList: []} as ModelValue;
modelValue.objectIds = this.getObjectsFromJsonAllConfig(); modelValue.objectIds = this.getObjectsFromJsonAllConfig();
if (modelValue.objectIds !== null) { if (modelValue.objectIds !== null) {
const sortOrder = { const sortOrder = {
@ -149,11 +139,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
} }
private updateWriteValue = (value: any): void => { private updateWriteValue = (value: ModelValue): void => {
const objectsList = value.objectsList;
this.lwm2mDeviceProfileFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value, objectIds: value,
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(objectsList), observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value['objectsList']),
shortId: this.configurationValue.bootstrap.servers.shortId, shortId: this.configurationValue.bootstrap.servers.shortId,
lifetime: this.configurationValue.bootstrap.servers.lifetime, lifetime: this.configurationValue.bootstrap.servers.lifetime,
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod, defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod,
@ -199,22 +188,22 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): object => { private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): object => {
const clientObserveAttrTelemetry = listObject; const clientObserveAttrTelemetry = listObject;
if (this.configurationValue[this.observeAttr]) { if (this.configurationValue.observeAttr) {
const observeArray = this.configurationValue[this.observeAttr][this.observe]; const observeArray = this.configurationValue.observeAttr.observe;
const attributeArray = this.configurationValue[this.observeAttr][this.attribute]; const attributeArray = this.configurationValue.observeAttr.attribute;
const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry]; const telemetryArray = this.configurationValue.observeAttr.telemetry;
const keyNameJson = this.configurationValue[this.observeAttr][this.keyName]; const keyNameJson = this.configurationValue.observeAttr.keyName;
if (this.includesNotZeroInstance(attributeArray, telemetryArray)) { if (this.includesNotZeroInstance(attributeArray, telemetryArray)) {
this.addInstances(attributeArray, telemetryArray, clientObserveAttrTelemetry); this.addInstances(attributeArray, telemetryArray, clientObserveAttrTelemetry);
} }
if (isDefinedAndNotNull(observeArray)) { if (isDefinedAndNotNull(observeArray)) {
this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttrTelemetry, 'observe'); this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttrTelemetry, OBSERVE);
} }
if (isDefinedAndNotNull(attributeArray)) { if (isDefinedAndNotNull(attributeArray)) {
this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttrTelemetry, 'attribute'); this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttrTelemetry, ATTRIBUTE);
} }
if (isDefinedAndNotNull(telemetryArray)) { if (isDefinedAndNotNull(telemetryArray)) {
this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, 'telemetry'); this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, TELEMETRY);
} }
if (isDefinedAndNotNull(keyNameJson)) { if (isDefinedAndNotNull(keyNameJson)) {
this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry); this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry);
@ -273,74 +262,51 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const telemetryArray: Array<string> = []; const telemetryArray: Array<string> = [];
const keyNameNew = {}; const keyNameNew = {};
const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val)); const observeJson: ObjectLwM2M[] = JSON.parse(JSON.stringify(val));
const paths = new Set<string>();
let pathObj;
let pathInst;
let pathRes;
observeJson.forEach(obj => { observeJson.forEach(obj => {
for (const [key, value] of Object.entries(obj)) { if (obj.hasOwnProperty(INSTANCES) && Array.isArray(obj.instances)) {
if (key === 'id') { obj.instances.forEach(instance => {
pathObj = value; if (instance.hasOwnProperty(RESOURCES) && Array.isArray(instance.resources)) {
} instance.resources.forEach(resource => {
if (key === 'instances') { if (resource.attribute || resource.telemetry) {
const instancesJson = value as Instance[]; let pathRes = `/${obj.id}/${instance.id}/${resource.id}`;
if (instancesJson.length > 0) { if (resource.observe) {
instancesJson.forEach(instance => { observeArray.push(pathRes);
for (const [instanceKey, instanceValue] of Object.entries(instance)) { }
if (instanceKey === 'id') { if (resource.attribute) {
pathInst = instanceValue; attributeArray.push(pathRes);
} }
if (instanceKey === 'resources') { if (resource.telemetry) {
const resourcesJson = instanceValue as ResourceLwM2M[]; telemetryArray.push(pathRes);
if (resourcesJson.length > 0) {
resourcesJson.forEach(res => {
for (const [resourceKey, value] of Object.entries(res)) {
if (resourceKey === 'id') {
pathRes = `/${pathObj}/${pathInst}/${value}`;
} else if (resourceKey === 'observe' && value) {
observeArray.push(pathRes);
} else if (resourceKey === 'attribute' && value) {
attributeArray.push(pathRes);
paths.add(pathRes);
} else if (resourceKey === 'telemetry' && value) {
telemetryArray.push(pathRes);
paths.add(pathRes);
}
else if (resourceKey === this.keyName && paths.has(pathRes)) {
console.warn(pathRes, value);
keyNameNew[pathRes] = value;
}
}
});
}
} }
keyNameNew[pathRes] = resource.keyName;
} }
}); })
} }
} })
} }
}); });
if (isUndefined(this.configurationValue[this.observeAttr])) { if (isUndefined(this.configurationValue.observeAttr)) {
this.configurationValue[this.observeAttr] = { this.configurationValue.observeAttr = {
[this.observe]: observeArray, observe: observeArray,
[this.attribute]: attributeArray, attribute: attributeArray,
[this.telemetry]: telemetryArray telemetry: telemetryArray,
keyName: this.sortObjectKeyPathJson(KEY_NAME, keyNameNew)
}; };
} else { } else {
this.configurationValue[this.observeAttr][this.observe] = observeArray; this.configurationValue.observeAttr.observe = observeArray;
this.configurationValue[this.observeAttr][this.attribute] = attributeArray; this.configurationValue.observeAttr.attribute = attributeArray;
this.configurationValue[this.observeAttr][this.telemetry] = telemetryArray; this.configurationValue.observeAttr.telemetry = telemetryArray;
this.configurationValue.observeAttr.keyName = this.sortObjectKeyPathJson(KEY_NAME, keyNameNew);
} }
this.configurationValue[this.observeAttr][this.keyName] = this.sortObjectKeyPathJson('keyName', keyNameNew);
} }
sortObjectKeyPathJson = (key: string, value: object): object => { sortObjectKeyPathJson = (key: string, value: object): object => {
if (key === 'keyName') { if (key === KEY_NAME) {
return Object.keys(value).sort(this.sortPath).reduce((obj, keySort) => { return Object.keys(value).sort(this.sortPath).reduce((obj, keySort) => {
obj[keySort] = value[keySort]; obj[keySort] = value[keySort];
return obj; return obj;
}, {}); }, {});
} else if (key === 'observe' || key === 'attribute' || key === 'telemetry') { } else if (key === OBSERVE || key === ATTRIBUTE || key === TELEMETRY) {
return Object.values(value).sort(this.sortPath).reduce((arr, arrValue) => { return Object.values(value).sort(this.sortPath).reduce((arr, arrValue) => {
arr.push(arrValue); arr.push(arrValue);
return arr; return arr;
@ -359,19 +325,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private getObjectsFromJsonAllConfig = (): number[] => { private getObjectsFromJsonAllConfig = (): number[] => {
const objectsIds = new Set<number>(); const objectsIds = new Set<number>();
if (this.configurationValue[this.observeAttr]) { if (this.configurationValue.observeAttr) {
if (this.configurationValue[this.observeAttr][this.observe]) { if (this.configurationValue.observeAttr.observe) {
this.configurationValue[this.observeAttr][this.observe].forEach(obj => { this.configurationValue.observeAttr.observe.forEach(obj => {
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]); objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
}); });
} }
if (this.configurationValue[this.observeAttr][this.attribute]) { if (this.configurationValue.observeAttr.attribute) {
this.configurationValue[this.observeAttr][this.attribute].forEach(obj => { this.configurationValue.observeAttr.attribute.forEach(obj => {
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]); objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
}); });
} }
if (this.configurationValue[this.observeAttr][this.telemetry]) { if (this.configurationValue.observeAttr.telemetry) {
this.configurationValue[this.observeAttr][this.telemetry].forEach(obj => { this.configurationValue.observeAttr.telemetry.forEach(obj => {
objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]); objectsIds.add(Array.from(obj.substring(1).split('/'), Number)[0]);
}); });
} }
@ -390,15 +356,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
removeObjectsList = (value: ObjectLwM2M): void => { removeObjectsList = (value: ObjectLwM2M): void => {
const objectsOld = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M; const objectsOld = this.lwm2mDeviceProfileFormGroup.get(OBSERVE_ATTR_TELEMETRY).value.clientLwM2M;
const isIdIndex = (element) => element.id === value.id; const isIdIndex = (element) => element.id === value.id;
const index = objectsOld.findIndex(isIdIndex); const index = objectsOld.findIndex(isIdIndex);
if (index >= 0) { if (index >= 0) {
objectsOld.splice(index, 1); objectsOld.splice(index, 1);
} }
this.removeObserveAttrTelemetryFromJson(this.observe, value.id); this.removeObserveAttrTelemetryFromJson(OBSERVE, value.id);
this.removeObserveAttrTelemetryFromJson(this.telemetry, value.id); this.removeObserveAttrTelemetryFromJson(TELEMETRY, value.id);
this.removeObserveAttrTelemetryFromJson(this.attribute, value.id); this.removeObserveAttrTelemetryFromJson(ATTRIBUTE, value.id);
this.removeKeyNameFromJson(value.id); this.removeKeyNameFromJson(value.id);
this.updateObserveAttrTelemetryObjectFormGroup(objectsOld); this.updateObserveAttrTelemetryObjectFormGroup(objectsOld);
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
@ -406,15 +372,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private removeObserveAttrTelemetryFromJson = (observeAttrTel: string, id: number): void => { private removeObserveAttrTelemetryFromJson = (observeAttrTel: string, id: number): void => {
const isIdIndex = (element) => element.startsWith(`/${id}`); const isIdIndex = (element) => element.startsWith(`/${id}`);
let index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex); let index = this.configurationValue.observeAttr[observeAttrTel].findIndex(isIdIndex);
while (index >= 0) { while (index >= 0) {
this.configurationValue[this.observeAttr][observeAttrTel].splice(index, 1); this.configurationValue.observeAttr[observeAttrTel].splice(index, 1);
index = this.configurationValue[this.observeAttr][observeAttrTel].findIndex(isIdIndex, index); index = this.configurationValue.observeAttr[observeAttrTel].findIndex(isIdIndex, index);
} }
} }
private removeKeyNameFromJson = (id: number): void => { private removeKeyNameFromJson = (id: number): void => {
const keyNameJson = this.configurationValue[this.observeAttr][this.keyName]; const keyNameJson = this.configurationValue.observeAttr.keyName;
Object.keys(keyNameJson).forEach(key => { Object.keys(keyNameJson).forEach(key => {
if (key.startsWith(`/${id}`)) { if (key.startsWith(`/${id}`)) {
delete keyNameJson[key]; delete keyNameJson[key];
@ -423,17 +389,17 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
isPathInJson(path: string): boolean { isPathInJson(path: string): boolean {
let isPath = this.findPathInJson(path, this.attribute); let isPath = this.findPathInJson(path, ATTRIBUTE);
if (!isPath) { if (!isPath) {
isPath = this.findPathInJson(path, this.telemetry); isPath = this.findPathInJson(path, TELEMETRY);
} }
return !!isPath; return !!isPath;
} }
private findPathInJson = (path: string, side: string): string => { private findPathInJson = (path: string, side: string): string => {
if (this.configurationValue[this.observeAttr]) { if (this.configurationValue.observeAttr) {
if (this.configurationValue[this.observeAttr][side]) { if (this.configurationValue.observeAttr[side]) {
return this.configurationValue[this.observeAttr][side].find( return this.configurationValue.bootstrap[side].find(
pathJs => pathJs === path); pathJs => pathJs === path);
} }
} }

1
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances-list.component.ts

@ -25,7 +25,6 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
@Component({ @Component({
selector: 'tb-profile-lwm2m-object-add-instances-list', selector: 'tb-profile-lwm2m-object-add-instances-list',
templateUrl: './lwm2m-object-add-instances-list.component.html', templateUrl: './lwm2m-object-add-instances-list.component.html',
styleUrls: [],
providers: [{ providers: [{
provide: NG_VALUE_ACCESSOR, provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => Lwm2mObjectAddInstancesListComponent), useExisting: forwardRef(() => Lwm2mObjectAddInstancesListComponent),

3
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-add-instances.component.ts

@ -30,8 +30,7 @@ export interface Lwm2mObjectAddInstancesData {
@Component({ @Component({
selector: 'tb-lwm2m-object-add-instances', selector: 'tb-lwm2m-object-add-instances',
templateUrl: './lwm2m-object-add-instances.component.html', templateUrl: './lwm2m-object-add-instances.component.html'
styleUrls: []
}) })
export class Lwm2mObjectAddInstancesComponent extends DialogComponent<Lwm2mObjectAddInstancesComponent, object> implements OnInit { export class Lwm2mObjectAddInstancesComponent extends DialogComponent<Lwm2mObjectAddInstancesComponent, object> implements OnInit {

5
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-object-list.component.ts

@ -21,7 +21,7 @@ import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { filter, map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators'; import { filter, map, mergeMap, publishReplay, refCount, tap } from 'rxjs/operators';
import { ObjectLwM2M } from './profile-config.models'; import { ModelValue, ObjectLwM2M } from './profile-config.models';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { DeviceProfileService } from '@core/http/device-profile.service'; import { DeviceProfileService } from '@core/http/device-profile.service';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
@ -120,7 +120,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
} }
} }
writeValue(value: any): void { writeValue(value: ModelValue): void {
this.searchText = ''; this.searchText = '';
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
if (Array.isArray(value.objectIds)) { if (Array.isArray(value.objectIds)) {
@ -193,7 +193,6 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
return this.lw2mModels; return this.lw2mModels;
} }
onFocus = (): void => { onFocus = (): void => {
if (!this.dirty) { if (!this.dirty) {
this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true}); this.lwm2mListFormGroup.get('objectLwm2m').updateValueAndValidity({onlySelf: true, emitEvent: true});

1
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry-resource.component.ts

@ -25,7 +25,6 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
@Component({ @Component({
selector: 'tb-profile-lwm2m-observe-attr-telemetry-resource', selector: 'tb-profile-lwm2m-observe-attr-telemetry-resource',
templateUrl: './lwm2m-observe-attr-telemetry-resource.component.html', templateUrl: './lwm2m-observe-attr-telemetry-resource.component.html',
styleUrls: [],
providers: [ providers: [
{ {
provide: NG_VALUE_ACCESSOR, provide: NG_VALUE_ACCESSOR,

33
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-observe-attr-telemetry.component.ts

@ -28,7 +28,7 @@ import {
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { Instance, ObjectLwM2M, ResourceLwM2M } from './profile-config.models'; import { CLIENT_LWM2M, Instance, INSTANCES, ObjectLwM2M, ResourceLwM2M, RESOURCES } from './profile-config.models';
import { deepClone, isDefinedAndNotNull, isEqual, isUndefined } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isEqual, isUndefined } from '@core/utils';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -78,7 +78,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
private dialog: MatDialog, private dialog: MatDialog,
public translate: TranslateService) { public translate: TranslateService) {
this.observeAttrTelemetryFormGroup = this.fb.group({ this.observeAttrTelemetryFormGroup = this.fb.group({
clientLwM2M: this.fb.array([]) [CLIENT_LWM2M]: this.fb.array([])
}); });
this.observeAttrTelemetryFormGroup.valueChanges.subscribe(value => { this.observeAttrTelemetryFormGroup.valueChanges.subscribe(value => {
if (isUndefined(this.disabled) || !this.disabled) { if (isUndefined(this.disabled) || !this.disabled) {
@ -87,7 +87,8 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
}); });
} }
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => {
};
registerOnChange(fn: any): void { registerOnChange(fn: any): void {
this.propagateChange = fn; this.propagateChange = fn;
@ -123,14 +124,14 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
} }
} }
writeValue(value: any): void { writeValue(value: {}): void {
if (isDefinedAndNotNull(value)) { if (isDefinedAndNotNull(value)) {
this.buildClientObjectsLwM2M(value.clientLwM2M); this.buildClientObjectsLwM2M(value[CLIENT_LWM2M]);
} }
} }
private buildClientObjectsLwM2M = (objectsLwM2M: ObjectLwM2M []): void => { private buildClientObjectsLwM2M = (objectsLwM2M: ObjectLwM2M []): void => {
this.observeAttrTelemetryFormGroup.setControl('clientLwM2M', this.observeAttrTelemetryFormGroup.setControl(CLIENT_LWM2M,
this.createObjectsLwM2M(objectsLwM2M) this.createObjectsLwM2M(objectsLwM2M)
); );
} }
@ -157,23 +158,23 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
} }
get clientLwM2MFormArray(): FormArray { get clientLwM2MFormArray(): FormArray {
return this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray; return this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray;
} }
instancesLwm2mFormArray = (objectLwM2M: AbstractControl): FormArray => { instancesLwm2mFormArray = (objectLwM2M: AbstractControl): FormArray => {
return objectLwM2M.get('instances') as FormArray; return objectLwM2M.get(INSTANCES) as FormArray;
} }
changeInstanceResourcesCheckBox = (value: boolean, instance: AbstractControl, type: string): void => { changeInstanceResourcesCheckBox = (value: boolean, instance: AbstractControl, type: string): void => {
const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]); const resources = deepClone(instance.get(RESOURCES).value as ResourceLwM2M[]);
resources.forEach(resource => resource[type] = value); resources.forEach(resource => resource[type] = value);
instance.get('resources').patchValue(resources); instance.get(RESOURCES).patchValue(resources);
this.propagateChange(this.observeAttrTelemetryFormGroup.value); this.propagateChange(this.observeAttrTelemetryFormGroup.value);
} }
private updateValidators = (): void => { private updateValidators = (): void => {
this.observeAttrTelemetryFormGroup.get('clientLwM2M').setValidators(this.required ? Validators.required : []); this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).setValidators(this.required ? Validators.required : []);
this.observeAttrTelemetryFormGroup.get('clientLwM2M').updateValueAndValidity(); this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M).updateValueAndValidity();
} }
trackByParams = (index: number, element: any): number => { trackByParams = (index: number, element: any): number => {
@ -181,7 +182,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
} }
getIndeterminate = (instance: AbstractControl, type: string): boolean => { getIndeterminate = (instance: AbstractControl, type: string): boolean => {
const resources = instance.get('resources').value as ResourceLwM2M[]; const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
if (isDefinedAndNotNull(resources)) { if (isDefinedAndNotNull(resources)) {
const checkedResource = resources.filter(resource => resource[type]); const checkedResource = resources.filter(resource => resource[type]);
return checkedResource.length !== 0 && checkedResource.length !== resources.length; return checkedResource.length !== 0 && checkedResource.length !== resources.length;
@ -190,7 +191,7 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
} }
getChecked = (instance: AbstractControl, type: string): boolean => { getChecked = (instance: AbstractControl, type: string): boolean => {
const resources = instance.get('resources').value as ResourceLwM2M[]; const resources = instance.get(RESOURCES).value as ResourceLwM2M[];
return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]); return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]);
} }
@ -239,10 +240,10 @@ export class Lwm2mObserveAttrTelemetryComponent implements ControlValueAccessor
} }
private updateInstancesIds = (data: Lwm2mObjectAddInstancesData): void => { private updateInstancesIds = (data: Lwm2mObjectAddInstancesData): void => {
const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get('clientLwM2M') as FormArray).controls const objectLwM2MFormGroup = (this.observeAttrTelemetryFormGroup.get(CLIENT_LWM2M) as FormArray).controls
.find(e => e.value.id === data.objectId) as FormGroup; .find(e => e.value.id === data.objectId) as FormGroup;
const instancesArray = objectLwM2MFormGroup.value.instances as Instance []; const instancesArray = objectLwM2MFormGroup.value.instances as Instance [];
const instancesFormArray = objectLwM2MFormGroup.get('instances') as FormArray; const instancesFormArray = objectLwM2MFormGroup.get(INSTANCES) as FormArray;
const instance0 = deepClone(instancesFormArray.at(0).value as Instance); const instance0 = deepClone(instancesFormArray.at(0).value as Instance);
instance0.resources.forEach(r => { instance0.resources.forEach(r => {
r.attribute = false; r.attribute = false;

18
ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts

@ -14,11 +14,16 @@
/// limitations under the License. /// limitations under the License.
/// ///
export const OBSERVE_ATTR = 'observeAttr'; import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
export const INSTANCES = 'instances';
export const RESOURCES = 'resources';
export const OBSERVE_ATTR_TELEMETRY = 'observeAttrTelemetry';
export const OBSERVE = 'observe'; export const OBSERVE = 'observe';
export const ATTR = 'attribute'; export const ATTRIBUTE = 'attribute';
export const TELEMETRY = 'telemetry'; export const TELEMETRY = 'telemetry';
export const KEY_NAME = 'keyName'; export const KEY_NAME = 'keyName';
export const CLIENT_LWM2M = 'clientLwM2M';
export const DEFAULT_ID_SERVER = 123; export const DEFAULT_ID_SERVER = 123;
export const DEFAULT_ID_BOOTSTRAP = 111; export const DEFAULT_ID_BOOTSTRAP = 111;
export const DEFAULT_HOST_NAME = 'localhost'; export const DEFAULT_HOST_NAME = 'localhost';
@ -53,6 +58,11 @@ export const SECURITY_CONFIG_MODE_NAMES = new Map<SECURITY_CONFIG_MODE, string>(
] ]
); );
export interface ModelValue {
objectIds: number[] | null,
objectsList: ObjectLwM2M[]
}
export interface BootstrapServersSecurityConfig { export interface BootstrapServersSecurityConfig {
shortId: number; shortId: number;
lifetime: number; lifetime: number;
@ -89,7 +99,7 @@ export interface ObservableAttributes {
observe: string[]; observe: string[];
attribute: string[]; attribute: string[];
telemetry: string[]; telemetry: string[];
keyName: string[]; keyName: {};
} }
export function getDefaultBootstrapServersSecurityConfig(): BootstrapServersSecurityConfig { export function getDefaultBootstrapServersSecurityConfig(): BootstrapServersSecurityConfig {
@ -138,7 +148,7 @@ export function getDefaultProfileConfig(hostname?: any): ProfileConfigModels {
observe: [], observe: [],
attribute: [], attribute: [],
telemetry: [], telemetry: [],
keyName: [] keyName: {}
} }
}; };
} }

Loading…
Cancel
Save