Browse Source

UI: Refactoring LwM2M

pull/3980/head
Vladyslav_Prykhodko 6 years ago
parent
commit
de77c53fcc
  1. 16
      ui-ngx/src/app/core/http/device-profile.service.ts
  2. 62
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.html
  3. 195
      ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts

16
ui-ngx/src/app/core/http/device-profile.service.ts

@ -43,14 +43,16 @@ export class DeviceProfileService {
return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config)); return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config));
} }
public getLwm2mObjects(objectIds?: number[], searchText?: string, sortOrder?: SortOrder, config?: RequestConfig): public getLwm2mObjects(objectIds: number[] = [], searchText?: string, sortOrder?: SortOrder, config?: RequestConfig):
Observable<Array<ObjectLwM2M>> { Observable<Array<ObjectLwM2M>> {
// tslint:disable-next-line:no-debugger let url = `/api/lwm2m/deviceProfile/?objectIds=${objectIds}`;
debugger; if (isDefinedAndNotNull(searchText)) {
return this.http.get<Array<ObjectLwM2M>> url += `&searchText=${searchText}`;
(`/api/lwm2m/deviceProfile/?objectIds=${objectIds}&searchText=${searchText}&sortProperty=${sortOrder.property} }
&sortOrder=${sortOrder.direction}`, if (isDefinedAndNotNull(sortOrder)) {
defaultHttpOptionsFromConfig(config)); url += `&sortProperty=${sortOrder.property}&sortOrder=${sortOrder.direction}`;
}
return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config));
} }
public getLwm2mBootstrapSecurityInfo(securityMode: string, bootstrapServerIs: boolean, public getLwm2mBootstrapSecurityInfo(securityMode: string, bootstrapServerIs: boolean,

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

@ -15,11 +15,11 @@
limitations under the License. limitations under the License.
--> -->
<form [formGroup]="lwm2mDeviceProfileTransportConfFormGroup" style="padding-bottom: 16px;"> <section style="padding-bottom: 16px;" mat-dialog-content>
<div 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> <section [formGroup]="lwm2mDeviceProfileFormGroup">
<div class="mat-padding"> <div class="mat-padding">
<tb-profile-lwm2m-object-list <tb-profile-lwm2m-object-list
(addList)="addObjectsList($event)" (addList)="addObjectsList($event)"
@ -34,10 +34,12 @@
formControlName="observeAttrTelemetry"> formControlName="observeAttrTelemetry">
</tb-profile-lwm2m-observe-attr-telemetry> </tb-profile-lwm2m-observe-attr-telemetry>
</div> </div>
</ng-template> </section>
</mat-tab> </ng-template>
<mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}"> </mat-tab>
<ng-template matTabContent> <mat-tab label="{{ 'device-profile.lwm2m.bootstrap-tab' | translate }}">
<ng-template matTabContent>
<section [formGroup]="lwm2mDeviceProfileFormGroup">
<div class="mat-padding"> <div class="mat-padding">
<mat-accordion multi="true" class="mat-body-1"> <mat-accordion multi="true" class="mat-body-1">
<mat-expansion-panel> <mat-expansion-panel>
@ -52,7 +54,7 @@
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.short-id' | translate }}</mat-label>
<input matInput type="number" formControlName="shortId" required> <input matInput type="number" formControlName="shortId" required>
<mat-error *ngIf="lwm2mDeviceProfileTransportConfFormGroup.get('shortId').hasError('required')"> <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('shortId').hasError('required')">
{{ 'device-profile.lwm2m.short-id' | translate }} {{ 'device-profile.lwm2m.short-id' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong> <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error> </mat-error>
@ -61,7 +63,7 @@
<mat-label>{{ 'device-profile.lwm2m.lifetime' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.lifetime' | translate }}</mat-label>
<input matInput type="number" formControlName="lifetime" required> <input matInput type="number" formControlName="lifetime" required>
<mat-error <mat-error
*ngIf="lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').hasError('required')"> *ngIf="lwm2mDeviceProfileFormGroup.get('lifetime').hasError('required')">
{{ 'device-profile.lwm2m.lifetime' | translate }} {{ 'device-profile.lwm2m.lifetime' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong> <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error> </mat-error>
@ -72,7 +74,7 @@
<mat-label>{{ 'device-profile.lwm2m.default-min-period' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.default-min-period' | translate }}</mat-label>
<input matInput type="number" formControlName="defaultMinPeriod" required> <input matInput type="number" formControlName="defaultMinPeriod" required>
<mat-error <mat-error
*ngIf="lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').hasError('required')"> *ngIf="lwm2mDeviceProfileFormGroup.get('defaultMinPeriod').hasError('required')">
{{ 'device-profile.lwm2m.default-min-period' | translate }} {{ 'device-profile.lwm2m.default-min-period' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong> <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error> </mat-error>
@ -80,7 +82,7 @@
<mat-form-field fxFlex> <mat-form-field fxFlex>
<mat-label>{{ 'device-profile.lwm2m.binding' | translate }}</mat-label> <mat-label>{{ 'device-profile.lwm2m.binding' | translate }}</mat-label>
<input matInput type="text" formControlName="binding" required> <input matInput type="text" formControlName="binding" required>
<mat-error *ngIf="lwm2mDeviceProfileTransportConfFormGroup.get('binding').hasError('required')"> <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('binding').hasError('required')">
{{ 'device-profile.lwm2m.binding' | translate }} {{ 'device-profile.lwm2m.binding' | translate }}
<strong>{{ 'device-profile.lwm2m.required' | translate }}</strong> <strong>{{ 'device-profile.lwm2m.required' | translate }}</strong>
</mat-error> </mat-error>
@ -133,20 +135,20 @@
</mat-expansion-panel> </mat-expansion-panel>
</mat-accordion> </mat-accordion>
</div> </div>
</ng-template> </section>
</mat-tab> </ng-template>
<mat-tab label="{{ 'device-profile.lwm2m.config-json-tab' | translate }}"> </mat-tab>
<ng-template matTabContent> <mat-tab label="{{ 'device-profile.lwm2m.config-json-tab' | translate }}">
<div class="mat-padding"> <ng-template matTabContent>
<tb-json-object-edit <section [formGroup]="lwm2mDeviceConfigFormGroup" class="mat-padding">
[required]="required" <tb-json-object-edit
[sort]="sortFunction" [required]="required"
label="{{ 'device-profile.transport-type-lwm2m' | translate }}" [sort]="sortFunction"
formControlName="configurationJson"> label="{{ 'device-profile.transport-type-lwm2m' | translate }}"
</tb-json-object-edit> formControlName="configurationJson">
</div> </tb-json-object-edit>
</ng-template> </section>
</mat-tab> </ng-template>
</mat-tab-group> </mat-tab>
</div> </mat-tab-group>
</form> </section>

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

@ -33,11 +33,10 @@ import {
TELEMETRY 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, isUndefined } from '@core/utils'; import { deepClone, isDefinedAndNotNull, isUndefined } from '@core/utils';
import { WINDOW } from '@core/services/window.service'; import { WINDOW } from '@core/services/window.service';
import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point'; import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined'; import { Direction } from '@shared/models/page/sort-order';
import { Direction, SortOrder } from '@shared/models/page/sort-order';
@Component({ @Component({
selector: 'tb-profile-lwm2m-device-transport-configuration', selector: 'tb-profile-lwm2m-device-transport-configuration',
@ -54,7 +53,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private requiredValue: boolean; private requiredValue: boolean;
private disabled = false; private disabled = false;
lwm2mDeviceProfileTransportConfFormGroup: FormGroup; lwm2mDeviceProfileFormGroup: FormGroup;
lwm2mDeviceConfigFormGroup: FormGroup;
observeAttr = OBSERVE_ATTR; observeAttr = OBSERVE_ATTR;
observe = OBSERVE; observe = OBSERVE;
attribute = ATTR; attribute = ATTR;
@ -80,7 +80,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private fb: FormBuilder, private fb: FormBuilder,
private deviceProfileService: DeviceProfileService, private deviceProfileService: DeviceProfileService,
@Inject(WINDOW) private window: Window) { @Inject(WINDOW) private window: Window) {
this.lwm2mDeviceProfileTransportConfFormGroup = this.fb.group({ this.lwm2mDeviceProfileFormGroup = this.fb.group({
objectIds: [{}, Validators.required], objectIds: [{}, Validators.required],
observeAttrTelemetry: [{clientLwM2M: []}, Validators.required], observeAttrTelemetry: [{clientLwM2M: []}, Validators.required],
shortId: [null, Validators.required], shortId: [null, Validators.required],
@ -90,9 +90,18 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
binding: ['U', Validators.required], binding: ['U', Validators.required],
bootstrapServer: [null, Validators.required], bootstrapServer: [null, Validators.required],
lwm2mServer: [null, Validators.required], lwm2mServer: [null, Validators.required],
configurationJson: [null, Validators.required],
}); });
this.lwm2mDeviceProfileTransportConfFormGroup.valueChanges.subscribe(() => { this.lwm2mDeviceConfigFormGroup = this.fb.group({
configurationJson: [null, Validators.required]
});
this.lwm2mDeviceProfileFormGroup.valueChanges.subscribe(() => {
console.warn('main form');
if (!this.disabled) {
this.updateModel();
}
});
this.lwm2mDeviceConfigFormGroup.valueChanges.subscribe(() => {
console.warn('config form');
if (!this.disabled) { if (!this.disabled) {
this.updateModel(); this.updateModel();
} }
@ -110,18 +119,19 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (isDisabled) { if (isDisabled) {
this.lwm2mDeviceProfileTransportConfFormGroup.disable({emitEvent: false}); this.lwm2mDeviceProfileFormGroup.disable({emitEvent: false});
this.lwm2mDeviceConfigFormGroup.disable({emitEvent: false});
} else { } else {
this.lwm2mDeviceProfileTransportConfFormGroup.enable({emitEvent: false}); this.lwm2mDeviceProfileFormGroup.enable({emitEvent: false});
this.lwm2mDeviceConfigFormGroup.enable({emitEvent: false});
} }
} }
writeValue(value: any | null): void { writeValue(value: any | null): void {
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value; this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ this.lwm2mDeviceConfigFormGroup.patchValue({
configurationJson: this.configurationValue configurationJson: this.configurationValue
}, }, {emitEvent: false});
{emitEvent: false});
this.initWriteValue(); this.initWriteValue();
} }
@ -146,7 +156,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private updateWriteValue = (value: any): void => { private updateWriteValue = (value: any): void => {
const objectsList = value.objectsList; const objectsList = value.objectsList;
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
objectIds: value, objectIds: value,
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}, observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)},
shortId: this.configurationValue.bootstrap.servers.shortId, shortId: this.configurationValue.bootstrap.servers.shortId,
@ -162,20 +172,20 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private updateModel = (): void => { private updateModel = (): void => {
let configuration: DeviceProfileTransportConfiguration = null; let configuration: DeviceProfileTransportConfiguration = null;
if (this.lwm2mDeviceProfileTransportConfFormGroup.valid) { if (this.lwm2mDeviceConfigFormGroup.valid) {
this.upDateValueToJson(); this.upDateValueToJson();
configuration = this.lwm2mDeviceProfileTransportConfFormGroup.getRawValue().configurationJson; configuration = this.lwm2mDeviceConfigFormGroup.getRawValue().configurationJson;
configuration.type = DeviceTransportType.LWM2M; configuration.type = DeviceTransportType.LWM2M;
} }
this.propagateChange(configuration); this.propagateChange(configuration);
} }
private updateObserveAttrTelemetryObjectFormGroup = (objectsList: ObjectLwM2M[]): void => { private updateObserveAttrTelemetryObjectFormGroup = (objectsList: ObjectLwM2M[]): void => {
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)} observeAttrTelemetry: {clientLwM2M: this.getObserveAttrTelemetryObjects(objectsList)}
}, },
{emitEvent: false}); {emitEvent: false});
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').markAsPristine({
onlySelf: true onlySelf: true
}); });
} }
@ -186,11 +196,11 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private upDateValueToJsonTab0 = (): void => { private upDateValueToJsonTab0 = (): void => {
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').pristine) {
this.upDateObserveAttrTelemetryFromGroupToJson( this.upDateObserveAttrTelemetryFromGroupToJson(
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M
); );
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
@ -199,16 +209,16 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private upDateValueToJsonTab1 = (): void => { private upDateValueToJsonTab1 = (): void => {
this.upDateValueServersToJson(); this.upDateValueServersToJson();
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('bootstrapServer').pristine) {
this.configurationValue.bootstrap.bootstrapServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').value; this.configurationValue.bootstrap.bootstrapServer = this.lwm2mDeviceProfileFormGroup.get('bootstrapServer').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('bootstrapServer').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('bootstrapServer').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('lwm2mServer').pristine) {
this.configurationValue.bootstrap.lwm2mServer = this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').value; this.configurationValue.bootstrap.lwm2mServer = this.lwm2mDeviceProfileFormGroup.get('lwm2mServer').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('lwm2mServer').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('lwm2mServer').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
@ -217,37 +227,37 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
private upDateValueServersToJson = (): void => { private upDateValueServersToJson = (): void => {
const bootstrapServers = this.configurationValue.bootstrap.servers; const bootstrapServers = this.configurationValue.bootstrap.servers;
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('shortId').pristine) {
bootstrapServers.shortId = this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').value; bootstrapServers.shortId = this.lwm2mDeviceProfileFormGroup.get('shortId').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('shortId').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('shortId').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('lifetime').pristine) {
bootstrapServers.lifetime = this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').value; bootstrapServers.lifetime = this.lwm2mDeviceProfileFormGroup.get('lifetime').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('lifetime').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('lifetime').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('defaultMinPeriod').pristine) {
bootstrapServers.defaultMinPeriod = this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').value; bootstrapServers.defaultMinPeriod = this.lwm2mDeviceProfileFormGroup.get('defaultMinPeriod').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('defaultMinPeriod').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('defaultMinPeriod').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('notifIfDisabled').pristine) {
bootstrapServers.notifIfDisabled = this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').value; bootstrapServers.notifIfDisabled = this.lwm2mDeviceProfileFormGroup.get('notifIfDisabled').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('notifIfDisabled').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('notifIfDisabled').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
} }
if (!this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').pristine) { if (!this.lwm2mDeviceProfileFormGroup.get('binding').pristine) {
bootstrapServers.binding = this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').value; bootstrapServers.binding = this.lwm2mDeviceProfileFormGroup.get('binding').value;
this.lwm2mDeviceProfileTransportConfFormGroup.get('binding').markAsPristine({ this.lwm2mDeviceProfileFormGroup.get('binding').markAsPristine({
onlySelf: true onlySelf: true
}); });
this.upDateJsonAllConfig(); this.upDateJsonAllConfig();
@ -255,55 +265,50 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): ObjectLwM2M [] => { private getObserveAttrTelemetryObjects = (listObject: ObjectLwM2M[]): ObjectLwM2M [] => {
const clientObserveAttr = listObject; const clientObserveAttrTelemetry = listObject;
if (this.configurationValue[this.observeAttr]) { if (this.configurationValue[this.observeAttr]) {
const observeArray = this.configurationValue[this.observeAttr][this.observe]; const observeArray = this.configurationValue[this.observeAttr][this.observe];
const attributeArray = this.configurationValue[this.observeAttr][this.attribute]; const attributeArray = this.configurationValue[this.observeAttr][this.attribute];
const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry]; const telemetryArray = this.configurationValue[this.observeAttr][this.telemetry];
const keyNameJson = this.configurationValue[this.observeAttr][this.keyName]; const keyNameJson = this.configurationValue[this.observeAttr][this.keyName];
if (this.includesInstancesNo(attributeArray, telemetryArray)) { if (this.includesNotZeroInstance(attributeArray, telemetryArray)) {
this.addInstances(attributeArray, telemetryArray, clientObserveAttr); this.addInstances(attributeArray, telemetryArray, clientObserveAttrTelemetry);
} }
if (observeArray) { if (isDefinedAndNotNull(observeArray)) {
this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttr, 'observe'); this.updateObserveAttrTelemetryObjects(observeArray, clientObserveAttrTelemetry, 'observe');
} }
if (attributeArray) { if (isDefinedAndNotNull(attributeArray)) {
this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttr, 'attribute'); this.updateObserveAttrTelemetryObjects(attributeArray, clientObserveAttrTelemetry, 'attribute');
} }
if (telemetryArray) { if (isDefinedAndNotNull(telemetryArray)) {
this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttr, 'telemetry'); this.updateObserveAttrTelemetryObjects(telemetryArray, clientObserveAttrTelemetry, 'telemetry');
} }
if (keyNameJson) { if (isDefinedAndNotNull(keyNameJson)) {
this.updateKeyNameObjects(deepClone(keyNameJson), clientObserveAttr); this.updateKeyNameObjects(keyNameJson, clientObserveAttrTelemetry);
} }
} }
clientObserveAttr.forEach(obj => { clientObserveAttrTelemetry.forEach(obj => {
obj.instances.sort((a, b) => a.id - b.id); obj.instances.sort((a, b) => a.id - b.id);
}); });
return clientObserveAttr; return clientObserveAttrTelemetry;
} }
private includesInstancesNo = (attributeArray: Array<string>, telemetryArray: Array<string>): boolean => { private includesNotZeroInstance = (attribute: string[], telemetry: string[]): boolean => {
const isIdIndex = (element) => !element.includes('/0/'); const isNotZeroInstanceId = (instance) => !instance.includes('/0/');
return attributeArray.findIndex(isIdIndex) >= 0 || telemetryArray.findIndex(isIdIndex) >= 0; return attribute.some(isNotZeroInstanceId) || telemetry.some(isNotZeroInstanceId);
} }
private addInstances = (attributeArray: Array<string>, telemetryArray: Array<string>, private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
clientObserveAttr: ObjectLwM2M[]): void => { const instancesPath = attribute.concat(telemetry)
const attr = [] as Array<string>; .filter(instance => !instance.includes('/0/'))
[...attributeArray].filter(x => (!x.includes('/0/'))).forEach(x => { .map(instance => this.convertPathToInstance(instance))
attr.push(this.convertPathToInstance(x)); .sort();
});
const telemetry = [] as Array<string>; new Set(instancesPath).forEach(path => {
[...telemetryArray].filter(x => (!x.includes('/0/'))).forEach(x => {
telemetry.push(this.convertPathToInstance(x));
});
const instancesNoZero = new Set(attr.concat(telemetry).sort());
instancesNoZero.forEach(path => {
const pathParameter = Array.from(path.split('/'), Number); const pathParameter = Array.from(path.split('/'), Number);
const objectLwM2M = clientObserveAttr.find(x => (x.id === pathParameter[0])); const objectLwM2M = clientObserveAttrTelemetry.find(x => x.id === pathParameter[0]);
if (objectLwM2M) { if (objectLwM2M) {
const instance = deepClone(objectLwM2M.instances[0]) as Instance; const instance = deepClone(objectLwM2M.instances[0]);
instance.id = pathParameter[1]; instance.id = pathParameter[1];
objectLwM2M.instances.push(instance); objectLwM2M.instances.push(instance);
} }
@ -311,36 +316,36 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private convertPathToInstance = (path: string): string => { private convertPathToInstance = (path: string): string => {
const newX = Array.from(path.substring(1).split('/'), Number); const [objectId, instanceId] = path.substring(1).split('/');
return [newX[0], newX[1]].join('/'); return `${objectId}/${instanceId}`;
} }
private updateObserveAttrTelemetryObjects = (isParameter: Array<string>, clientObserveAttr: ObjectLwM2M[], private updateObserveAttrTelemetryObjects = (parameters: string[], clientObserveAttrTelemetry: ObjectLwM2M[],
nameParameter: string): void => { nameParameter: string): void => {
isParameter.forEach(attr => { parameters.forEach(parameter => {
const idKeys = Array.from(attr.substring(1).split('/'), Number); const [objectId, instanceId, resourceId] = Array.from(parameter.substring(1).split('/'), Number);
clientObserveAttr clientObserveAttrTelemetry
.forEach(e => { .forEach(key => {
if (e.id === idKeys[0]) { if (key.id === objectId) {
const instance = e.instances.find(itrInstance => itrInstance.id === idKeys[1]); const instance = key.instances.find(itrInstance => itrInstance.id === instanceId);
if (isNotNullOrUndefined(instance)) { if (isDefinedAndNotNull(instance)) {
instance.resources.find(resource => resource.id === idKeys[2])[nameParameter] = true; instance.resources.find(resource => resource.id === resourceId)[nameParameter] = true;
} }
} }
}); });
}); });
} }
private updateKeyNameObjects = (nameJson: JsonObject, clientObserveAttr: ObjectLwM2M[]): void => { private updateKeyNameObjects = (nameJson: JsonObject, clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
const keyName = JSON.parse(JSON.stringify(nameJson)); const keyName = JSON.parse(JSON.stringify(nameJson));
Object.keys(keyName).forEach(key => { Object.keys(keyName).forEach(key => {
const idKeys = Array.from(key.substring(1).split('/'), Number); const [objectId, instanceId, resourceId] = Array.from(key.substring(1).split('/'), Number);
clientObserveAttr clientObserveAttrTelemetry
.forEach(e => { .forEach(object => {
if (e.id === idKeys[0]) { if (object.id === objectId) {
e.instances object.instances
.find(instance => instance.id === idKeys[1]).resources .find(instance => instance.id === instanceId).resources
.find(resource => resource.id === idKeys[2]).keyName = keyName[key]; .find(resource => resource.id === resourceId).keyName = keyName[key];
} }
}); });
}); });
@ -444,7 +449,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
paths.forEach(path => { paths.forEach(path => {
const pathParameter = this.findIndexesForIds(path); const pathParameter = this.findIndexesForIds(path);
if (pathParameter.length === 3) { if (pathParameter.length === 3) {
keyNameNew[path] = this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value keyNameNew[path] = this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value
.clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName]; .clientLwM2M[pathParameter[0]].instances[pathParameter[1]].resources[pathParameter[2]][this.keyName];
} }
}); });
@ -455,7 +460,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
const pathParameter = Array.from(path.substring(1).split('/'), Number); const pathParameter = Array.from(path.substring(1).split('/'), Number);
const pathParameterIndexes: number[] = []; const pathParameterIndexes: number[] = [];
const objectsOld = deepClone( const objectsOld = deepClone(
this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[]; this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').value.clientLwM2M) as ObjectLwM2M[];
let isIdIndex = (element) => element.id === pathParameter[0]; let isIdIndex = (element) => element.id === pathParameter[0];
const objIndex = objectsOld.findIndex(isIdIndex); const objIndex = objectsOld.findIndex(isIdIndex);
if (objIndex >= 0) { if (objIndex >= 0) {
@ -497,10 +502,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
private upDateJsonAllConfig = (): void => { private upDateJsonAllConfig = (): void => {
this.lwm2mDeviceProfileTransportConfFormGroup.patchValue({ this.lwm2mDeviceProfileFormGroup.patchValue({
configurationJson: this.configurationValue configurationJson: this.configurationValue
}, {emitEvent: false}); }, {emitEvent: false});
this.lwm2mDeviceProfileTransportConfFormGroup.markAsPristine({ this.lwm2mDeviceProfileFormGroup.markAsPristine({
onlySelf: true onlySelf: true
}); });
} }
@ -510,7 +515,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
} }
removeObjectsList = (value: ObjectLwM2M): void => { removeObjectsList = (value: ObjectLwM2M): void => {
const objectsOld = deepClone(this.lwm2mDeviceProfileTransportConfFormGroup.get('observeAttrTelemetry').value.clientLwM2M); const objectsOld = deepClone(this.lwm2mDeviceProfileFormGroup.get('observeAttrTelemetry').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) {

Loading…
Cancel
Save