|
|
|
@ -20,8 +20,9 @@ import { |
|
|
|
FormBuilder, |
|
|
|
NG_VALIDATORS, |
|
|
|
NG_VALUE_ACCESSOR, |
|
|
|
UntypedFormControl, |
|
|
|
Validator |
|
|
|
ValidationErrors, |
|
|
|
Validator, |
|
|
|
Validators |
|
|
|
} from '@angular/forms'; |
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { isDefinedAndNotNull } from '@core/utils'; |
|
|
|
@ -76,7 +77,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
private modelValue: AlarmRule; |
|
|
|
|
|
|
|
alarmRuleFormGroup = this.fb.group({ |
|
|
|
condition: this.fb.control<AlarmRuleCondition | null>(null), |
|
|
|
condition: this.fb.control<AlarmRuleCondition | null>(null, Validators.required), |
|
|
|
alarmDetails: [null], |
|
|
|
dashboardId: [null] |
|
|
|
}); |
|
|
|
@ -113,14 +114,12 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: AlarmRule): void { |
|
|
|
if (value) { |
|
|
|
this.modelValue = value; |
|
|
|
const model = this.modelValue ? { |
|
|
|
...this.modelValue, |
|
|
|
dashboardId: this.modelValue.dashboardId?.id |
|
|
|
} : null; |
|
|
|
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); |
|
|
|
} |
|
|
|
this.modelValue = value; |
|
|
|
const model = this.modelValue ? { |
|
|
|
...this.modelValue, |
|
|
|
dashboardId: this.modelValue.dashboardId?.id |
|
|
|
} : null; |
|
|
|
this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); |
|
|
|
} |
|
|
|
|
|
|
|
public openEditDetailsDialog($event: Event) { |
|
|
|
@ -142,7 +141,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public validate(c: UntypedFormControl) { |
|
|
|
public validate(): ValidationErrors | null { |
|
|
|
return (!this.required && !this.modelValue || this.alarmRuleFormGroup.valid) ? null : { |
|
|
|
alarmRule: { |
|
|
|
valid: false, |
|
|
|
|