Browse Source

UI: Fix notification escalation table

pull/7911/head
Vladyslav_Prykhodko 4 years ago
parent
commit
e69970b09f
  1. 34
      ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalations.component.ts
  2. 34
      ui-ngx/src/app/shared/components/time/timeinterval.component.ts

34
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 { export class EscalationsComponent implements ControlValueAccessor, Validator, OnDestroy {
escalationsFormGroup: FormGroup; escalationsFormGroup: FormGroup;
newEscalation = false;
@Input() @Input()
@coerceBoolean() @coerceBoolean()
@ -63,11 +62,6 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On
@Input() @Input()
disabled: boolean; disabled: boolean;
private mainEscalaion = {
delayInSec: 0,
targets: null
};
private destroy$ = new Subject<void>(); private destroy$ = new Subject<void>();
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => { };
@ -113,23 +107,18 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On
writeValue(escalations: {[key: string]: Array<string>} | null): void { writeValue(escalations: {[key: string]: Array<string>} | null): void {
const escalationParse: Array<NonConfirmedNotificationEscalation> = []; const escalationParse: Array<NonConfirmedNotificationEscalation> = [];
// tslint:disable-next-line:forin
for (const escalation in escalations) { 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) { if (escalationParse.length === 0) {
this.addEscalation(); this.addEscalation(0);
} else if (escalationParse?.length === this.escalationsFormArray.length) { } else if (escalationParse?.length === this.escalationsFormArray.length) {
this.escalationsFormArray.patchValue(escalationParse, {emitEvent: false}); this.escalationsFormArray.patchValue(escalationParse, {emitEvent: false});
} else { } else {
const escalationsControls: Array<AbstractControl> = []; const escalationsControls: Array<AbstractControl> = [];
if (escalationParse) { escalationParse.forEach(escalation => {
escalationParse.forEach(escalation => { escalationsControls.push(this.fb.control(escalation, [Validators.required]));
escalationsControls.push(this.fb.control(escalation, [Validators.required])); });
});
} else {
escalationsControls.push(this.fb.control(this.mainEscalaion, [Validators.required]));
}
this.escalationsFormGroup.setControl('escalations', this.fb.array(escalationsControls), {emitEvent: false}); this.escalationsFormGroup.setControl('escalations', this.fb.array(escalationsControls), {emitEvent: false});
if (this.disabled) { if (this.disabled) {
this.escalationsFormGroup.disable({emitEvent: false}); this.escalationsFormGroup.disable({emitEvent: false});
@ -143,18 +132,13 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On
(this.escalationsFormGroup.get('escalations') as FormArray).removeAt(index); (this.escalationsFormGroup.get('escalations') as FormArray).removeAt(index);
} }
public addEscalation() { public addEscalation(delay = 60000) {
const escalation = { const escalation = {
delayInSec: 0, delayInSec: delay,
targets: null targets: null
}; };
this.newEscalation = true;
const escalationArray = this.escalationsFormGroup.get('escalations') as FormArray; const escalationArray = this.escalationsFormGroup.get('escalations') as FormArray;
escalationArray.push(this.fb.control(escalation, [])); escalationArray.push(this.fb.control(escalation, []), {emitEvent: false});
this.escalationsFormGroup.updateValueAndValidity();
if (!this.escalationsFormGroup.valid) {
this.updateModel();
}
} }
public validate(c: AbstractControl): ValidationErrors | null { public validate(c: AbstractControl): ValidationErrors | null {
@ -168,7 +152,7 @@ export class EscalationsComponent implements ControlValueAccessor, Validator, On
private updateModel() { private updateModel() {
const escalations = {}; const escalations = {};
this.escalationsFormGroup.get('escalations').value.forEach( this.escalationsFormGroup.get('escalations').value.forEach(
escalation => escalations[escalation.delayInSec] = escalation.targets escalation => escalations[escalation.delayInSec / 1000] = escalation.targets
); );
this.propagateChange(escalations); this.propagateChange(escalations);
} }

34
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 { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { TimeInterval, TimeService } from '@core/services/time.service'; 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 { SubscriptSizing } from '@angular/material/form-field';
import { coerceBoolean } from '@shared/decorators/coerce-boolean';
@Component({ @Component({
selector: 'tb-timeinterval', selector: 'tb-timeinterval',
@ -59,38 +60,19 @@ export class TimeintervalComponent implements OnInit, ControlValueAccessor {
@Input() predefinedName: string; @Input() predefinedName: string;
isEditValue = false;
@Input() @Input()
set isEdit(val) { @coerceBoolean()
this.isEditValue = coerceBooleanProperty(val); isEdit = false;
}
get isEdit() {
return this.isEditValue;
}
hideFlagValue = false; hideFlagValue = false;
@Input() @Input()
get hideFlag() { @coerceBoolean()
return this.hideFlagValue; hideFlag = false;
}
set hideFlag(val) {
this.hideFlagValue = coerceBooleanProperty(val);
}
private disabledAdvancedValue = false;
get disabledAdvanced() {
return this.disabledAdvancedValue;
}
@Input() @Input()
set disabledAdvanced(val) { @coerceBoolean()
this.disabledAdvancedValue = coerceBooleanProperty(val); disabledAdvanced = false
}
@Output() hideFlagChange = new EventEmitter<boolean>(); @Output() hideFlagChange = new EventEmitter<boolean>();

Loading…
Cancel
Save