|
|
|
@ -76,12 +76,11 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
testScript: (expression: string) => Observable<string>; |
|
|
|
|
|
|
|
private modelValue: AlarmRule; |
|
|
|
private propagatedValue: AlarmRule; |
|
|
|
|
|
|
|
alarmRuleFormGroup = this.fb.group({ |
|
|
|
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required), |
|
|
|
alarmDetails: [null], |
|
|
|
dashboardId: [null] |
|
|
|
alarmDetails: this.fb.control<string | null>(null), |
|
|
|
dashboardId: this.fb.control<string | null>(null) |
|
|
|
}); |
|
|
|
|
|
|
|
private propagateChange = (v: any) => { }; |
|
|
|
@ -106,8 +105,8 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
ngOnInit() { |
|
|
|
this.alarmRuleFormGroup.valueChanges.pipe( |
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
).subscribe(() => { |
|
|
|
this.updateModel(); |
|
|
|
).subscribe((value) => { |
|
|
|
this.updateModel(value); |
|
|
|
}); |
|
|
|
this.alarmRuleFormGroup.statusChanges.pipe( |
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
@ -126,13 +125,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: AlarmRule): void { |
|
|
|
this.modelValue = value; |
|
|
|
const model = this.modelValue ? { |
|
|
|
...this.modelValue, |
|
|
|
dashboardId: this.modelValue.dashboardId?.id |
|
|
|
const model = value ? { |
|
|
|
...value, |
|
|
|
dashboardId: value.dashboardId?.id |
|
|
|
} : null; |
|
|
|
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); |
|
|
|
this.propagatedValue = this.toModel(this.alarmRuleFormGroup.value); |
|
|
|
this.modelValue = model ? this.toModel(model) : null; |
|
|
|
} |
|
|
|
|
|
|
|
public openEditDetailsDialog($event: Event) { |
|
|
|
@ -162,17 +160,16 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private updateModel() { |
|
|
|
const modelValue = this.toModel(this.alarmRuleFormGroup.value); |
|
|
|
if (isEqual(modelValue, this.propagatedValue)) { |
|
|
|
private updateModel(value: typeof this.alarmRuleFormGroup.value): void { |
|
|
|
const modelValue = this.toModel(value); |
|
|
|
if (isEqual(modelValue, this.modelValue)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.modelValue = modelValue; |
|
|
|
this.propagatedValue = modelValue; |
|
|
|
this.propagateChange(modelValue); |
|
|
|
} |
|
|
|
|
|
|
|
private toModel(value: any): AlarmRule { |
|
|
|
private toModel(value: typeof this.alarmRuleFormGroup.value): AlarmRule { |
|
|
|
return {...value, dashboardId: value.dashboardId ? new DashboardId(value.dashboardId) : null} as AlarmRule; |
|
|
|
} |
|
|
|
} |
|
|
|
|