Commit bd558ed4c68cc63f62266ae107ffc0afca8aebc5
Committed by
Andrew Shvayka
1 parent
8e78b65e
UI: LwM2M device profile refactoring select attributes and telemetry
Showing
3 changed files
with
22 additions
and
3 deletions
... | ... | @@ -32,6 +32,7 @@ |
32 | 32 | <mat-checkbox color="warn" |
33 | 33 | [disabled]="this.disabled" |
34 | 34 | [checked]="getChecked(instances, 'attribute')" |
35 | + (click)="$event.stopPropagation()" | |
35 | 36 | (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'attribute')" |
36 | 37 | [indeterminate]="getIndeterminate(instances, 'attribute')"> |
37 | 38 | </mat-checkbox> |
... | ... | @@ -40,14 +41,16 @@ |
40 | 41 | <mat-checkbox color="primary" |
41 | 42 | [disabled]="this.disabled" |
42 | 43 | [checked]="getChecked(instances, 'telemetry')" |
44 | + (click)="$event.stopPropagation()" | |
43 | 45 | (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'telemetry')" |
44 | 46 | [indeterminate]="getIndeterminate(instances, 'telemetry')"> |
45 | 47 | </mat-checkbox> |
46 | 48 | </div> |
47 | 49 | <div fxLayoutAlign="center center" fxFlex="10"> |
48 | 50 | <mat-checkbox color="primary" |
49 | - [disabled]="this.disabled || !(getIndeterminate(instances, 'telemetry') || getIndeterminate(instances, 'attribute'))" | |
51 | + [disabled]="disableObserve(instances)" | |
50 | 52 | [checked]="getChecked(instances, 'observe')" |
53 | + (click)="$event.stopPropagation()" | |
51 | 54 | (change)="changeInstanceResourcesCheckBox($event.checked, instances, 'observe')" |
52 | 55 | [indeterminate]="getIndeterminate(instances, 'observe')"> |
53 | 56 | </mat-checkbox> | ... | ... |
... | ... | @@ -161,6 +161,13 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue |
161 | 161 | const resources = deepClone(instance.get('resources').value as ResourceLwM2M[]); |
162 | 162 | if (value && type === 'observe') { |
163 | 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 | 171 | } else { |
165 | 172 | resources.forEach(resource => resource[type] = value); |
166 | 173 | } |
... | ... | @@ -190,6 +197,15 @@ export class Lwm2mObserveAttrTelemetryInstancesComponent implements ControlValue |
190 | 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 | 209 | get isExpend(): boolean { |
194 | 210 | return this.instancesFormArray.length === 1; |
195 | 211 | } | ... | ... |
... | ... | @@ -129,7 +129,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue |
129 | 129 | |
130 | 130 | private updatedResources(resources: ResourceLwM2M[]): void { |
131 | 131 | if (resources.length === this.resourcesFormArray.length) { |
132 | - this.resourcesFormArray.patchValue(resources, {emitEvent: false}); | |
132 | + this.resourcesFormArray.patchValue(resources, {onlySelf: true}); | |
133 | 133 | } else { |
134 | 134 | if (this.valueChange$) { |
135 | 135 | this.valueChange$.unsubscribe(); |
... | ... | @@ -144,7 +144,7 @@ export class Lwm2mObserveAttrTelemetryResourcesComponent implements ControlValue |
144 | 144 | if (this.disabled) { |
145 | 145 | this.resourcesFormGroup.disable({emitEvent: false}); |
146 | 146 | } |
147 | - this.valueChange$ = this.resourcesFormGroup.valueChanges.subscribe(value => { | |
147 | + this.valueChange$ = this.resourcesFormGroup.valueChanges.subscribe(() => { | |
148 | 148 | this.updateModel(this.resourcesFormGroup.getRawValue().resources); |
149 | 149 | }); |
150 | 150 | } | ... | ... |