diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalations.component.ts b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalations.component.ts index 14f93566ee..4413ca2941 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalations.component.ts +++ b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalations.component.ts @@ -54,7 +54,6 @@ import { coerceBoolean } from '@shared/decorators/coerce-boolean'; export class EscalationsComponent implements ControlValueAccessor, Validator, OnDestroy { escalationsFormGroup: FormGroup; - newEscalation = false; @Input() @coerceBoolean() @@ -63,11 +62,6 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On @Input() disabled: boolean; - private mainEscalaion = { - delayInSec: 0, - targets: null - }; - private destroy$ = new Subject(); private propagateChange = (v: any) => { }; @@ -113,23 +107,18 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On writeValue(escalations: {[key: string]: Array} | null): void { const escalationParse: Array = []; - // tslint:disable-next-line:forin for (const escalation in escalations) { - escalationParse.push({delayInSec: Number(escalation), targets: escalations[escalation]}); + escalationParse.push({delayInSec: Number(escalation) * 1000, targets: escalations[escalation]}); } if (escalationParse.length === 0) { - this.addEscalation(); + this.addEscalation(0); } else if (escalationParse?.length === this.escalationsFormArray.length) { this.escalationsFormArray.patchValue(escalationParse, {emitEvent: false}); } else { const escalationsControls: Array = []; - if (escalationParse) { - escalationParse.forEach(escalation => { - escalationsControls.push(this.fb.control(escalation, [Validators.required])); - }); - } else { - escalationsControls.push(this.fb.control(this.mainEscalaion, [Validators.required])); - } + escalationParse.forEach(escalation => { + escalationsControls.push(this.fb.control(escalation, [Validators.required])); + }); this.escalationsFormGroup.setControl('escalations', this.fb.array(escalationsControls), {emitEvent: false}); if (this.disabled) { this.escalationsFormGroup.disable({emitEvent: false}); @@ -143,18 +132,13 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On (this.escalationsFormGroup.get('escalations') as FormArray).removeAt(index); } - public addEscalation() { + public addEscalation(delay = 60000) { const escalation = { - delayInSec: 0, + delayInSec: delay, targets: null }; - this.newEscalation = true; const escalationArray = this.escalationsFormGroup.get('escalations') as FormArray; - escalationArray.push(this.fb.control(escalation, [])); - this.escalationsFormGroup.updateValueAndValidity(); - if (!this.escalationsFormGroup.valid) { - this.updateModel(); - } + escalationArray.push(this.fb.control(escalation, []), {emitEvent: false}); } public validate(c: AbstractControl): ValidationErrors | null { @@ -168,7 +152,7 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On private updateModel() { const escalations = {}; this.escalationsFormGroup.get('escalations').value.forEach( - escalation => escalations[escalation.delayInSec] = escalation.targets + escalation => escalations[escalation.delayInSec / 1000] = escalation.targets ); this.propagateChange(escalations); } diff --git a/ui-ngx/src/app/shared/components/time/timeinterval.component.ts b/ui-ngx/src/app/shared/components/time/timeinterval.component.ts index 49bfec6fe3..b3375cc53d 100644 --- a/ui-ngx/src/app/shared/components/time/timeinterval.component.ts +++ b/ui-ngx/src/app/shared/components/time/timeinterval.component.ts @@ -17,8 +17,9 @@ import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { TimeInterval, TimeService } from '@core/services/time.service'; -import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion'; +import { coerceNumberProperty } from '@angular/cdk/coercion'; import { SubscriptSizing } from '@angular/material/form-field'; +import { coerceBoolean } from '@shared/decorators/coerce-boolean'; @Component({ selector: 'tb-timeinterval', @@ -59,38 +60,19 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor { @Input() predefinedName: string; - isEditValue = false; - @Input() - set isEdit(val) { - this.isEditValue = coerceBooleanProperty(val); - } - - get isEdit() { - return this.isEditValue; - } + @coerceBoolean() + isEdit = false; hideFlagValue = false; @Input() - get hideFlag() { - return this.hideFlagValue; - } - - set hideFlag(val) { - this.hideFlagValue = coerceBooleanProperty(val); - } - - private disabledAdvancedValue = false; - - get disabledAdvanced() { - return this.disabledAdvancedValue; - } + @coerceBoolean() + hideFlag = false; @Input() - set disabledAdvanced(val) { - this.disabledAdvancedValue = coerceBooleanProperty(val); - } + @coerceBoolean() + disabledAdvanced = false @Output() hideFlagChange = new EventEmitter();