Commit bd558ed4c68cc63f62266ae107ffc0afca8aebc5

Authored by Vladyslav_Prykhodko
Committed by Andrew Shvayka
1 parent 8e78b65e

UI: LwM2M device profile refactoring select attributes and telemetry

@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 <mat-checkbox color="warn" 32 <mat-checkbox color="warn"
33 [disabled]="this.disabled" 33 [disabled]="this.disabled"
34 [checked]="getChecked(instances, 'attribute')" 34 [checked]="getChecked(instances, 'attribute')"
  35 + (click)="$event.stopPropagation()"
35 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'attribute')" 36 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'attribute')"
36 [indeterminate]="getIndeterminate(instances, 'attribute')"> 37 [indeterminate]="getIndeterminate(instances, 'attribute')">
37 </mat-checkbox> 38 </mat-checkbox>
@@ -40,14 +41,16 @@ @@ -40,14 +41,16 @@
40 <mat-checkbox color="primary" 41 <mat-checkbox color="primary"
41 [disabled]="this.disabled" 42 [disabled]="this.disabled"
42 [checked]="getChecked(instances, 'telemetry')" 43 [checked]="getChecked(instances, 'telemetry')"
  44 + (click)="$event.stopPropagation()"
43 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'telemetry')" 45 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'telemetry')"
44 [indeterminate]="getIndeterminate(instances, 'telemetry')"> 46 [indeterminate]="getIndeterminate(instances, 'telemetry')">
45 </mat-checkbox> 47 </mat-checkbox>
46 </div> 48 </div>
47 <div fxLayoutAlign="center center" fxFlex="10"> 49 <div fxLayoutAlign="center center" fxFlex="10">
48 <mat-checkbox color="primary" 50 <mat-checkbox color="primary"
49 - [disabled]="this.disabled || !(getIndeterminate(instances, 'telemetry') || getIndeterminate(instances, 'attribute'))" 51 + [disabled]="disableObserve(instances)"
50 [checked]="getChecked(instances, 'observe')" 52 [checked]="getChecked(instances, 'observe')"
  53 + (click)="$event.stopPropagation()"
51 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'observe')" 54 (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'observe')"
52 [indeterminate]="getIndeterminate(instances, 'observe')"> 55 [indeterminate]="getIndeterminate(instances, 'observe')">
53 </mat-checkbox> 56 </mat-checkbox>
@@ -161,6 +161,13 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue @@ -161,6 +161,13 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue
161 const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]); 161 const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]);
162 if (value && type === 'observe') { 162 if (value && type === 'observe') {
163 resources.forEach(resource => resource[type] = resource.telemetry || resource.attribute); 163 resources.forEach(resource => resource[type] = resource.telemetry || resource.attribute);
  164 + } else if (!value && type !== 'observe') {
  165 + resources.forEach(resource => {
  166 + resource[type] = value;
  167 + if (resource.observe && !(resource.telemetry || resource.attribute)) {
  168 + resource.observe = false;
  169 + }
  170 + });
164 } else { 171 } else {
165 resources.forEach(resource => resource[type] = value); 172 resources.forEach(resource => resource[type] = value);
166 } 173 }
@@ -190,6 +197,15 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue @@ -190,6 +197,15 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue
190 return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]); 197 return isDefinedAndNotNull(resources) && resources.every(resource => resource[type]);
191 } 198 }
192 199
  200 + disableObserve(instance: AbstractControl): boolean {
  201 + return this.disabled || !(
  202 + this.getIndeterminate(instance, 'telemetry') ||
  203 + this.getIndeterminate(instance, 'attribute') ||
  204 + this.getChecked(instance, 'telemetry') ||
  205 + this.getChecked(instance, 'attribute')
  206 + );
  207 + }
  208 +
193 get isExpend(): boolean { 209 get isExpend(): boolean {
194 return this.instancesFormArray.length === 1; 210 return this.instancesFormArray.length === 1;
195 } 211 }
@@ -129,7 +129,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue @@ -129,7 +129,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue
129 129
130 private updatedResources(resources: ResourceLwM2M[]): void { 130 private updatedResources(resources: ResourceLwM2M[]): void {
131 if (resources.length === this.resourcesFormArray.length) { 131 if (resources.length === this.resourcesFormArray.length) {
132 - this.resourcesFormArray.patchValue(resources, {emitEvent: false}); 132 + this.resourcesFormArray.patchValue(resources, {onlySelf: true});
133 } else { 133 } else {
134 if (this.valueChange$) { 134 if (this.valueChange$) {
135 this.valueChange$.unsubscribe(); 135 this.valueChange$.unsubscribe();
@@ -144,7 +144,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue @@ -144,7 +144,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue
144 if (this.disabled) { 144 if (this.disabled) {
145 this.resourcesFormGroup.disable({emitEvent: false}); 145 this.resourcesFormGroup.disable({emitEvent: false});
146 } 146 }
147 - this.valueChange$ = this.resourcesFormGroup.valueChanges.subscribe(value => { 147 + this.valueChange$ = this.resourcesFormGroup.valueChanges.subscribe(() => {
148 this.updateModel(this.resourcesFormGroup.getRawValue().resources); 148 this.updateModel(this.resourcesFormGroup.getRawValue().resources);
149 }); 149 });
150 } 150 }