Browse Source

UI: Fix timewindow panel form validation - disable aggregation limit check when aggregation is not none.

pull/6109/head
Igor Kulikov 5 years ago
parent
commit
442bb83784
  1. 2
      ui-ngx/src/app/shared/components/time/timewindow-panel.component.html
  2. 28
      ui-ngx/src/app/shared/components/time/timewindow-panel.component.ts

2
ui-ngx/src/app/shared/components/time/timewindow-panel.component.html

@ -130,7 +130,7 @@
</mat-form-field>
</section>
</section>
<section fxLayout="row" [fxShow]="timewindowForm.get('aggregation.type').value === aggregationTypes.NONE">
<section fxLayout="row" *ngIf="timewindowForm.get('aggregation.type').value === aggregationTypes.NONE">
<section fxLayout="column" [fxShow]="isEdit">
<label class="tb-small hide-label" translate>timewindow.hide</label>
<mat-checkbox [ngModelOptions]="{standalone: true}" [(ngModel)]="timewindow.hideAggInterval"

28
ui-ngx/src/app/shared/components/time/timewindow-panel.component.ts

@ -155,9 +155,9 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
}),
limit: this.fb.control({
value: this.timewindow.aggregation && typeof this.timewindow.aggregation.limit !== 'undefined'
? this.timewindow.aggregation.limit : null,
? this.checkLimit(this.timewindow.aggregation.limit) : null,
disabled: hideAggInterval
}, [Validators.min(this.minDatapointsLimit()), Validators.max(this.maxDatapointsLimit())])
}, [])
}
),
timezone: this.fb.control({
@ -166,6 +166,30 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit {
disabled: hideTimezone
})
});
this.updateValidators();
this.timewindowForm.get('aggregation.type').valueChanges.subscribe(() => {
this.updateValidators();
});
}
private checkLimit(limit?: number): number {
if (!limit || limit < this.minDatapointsLimit()) {
return this.minDatapointsLimit();
} else if (limit > this.maxDatapointsLimit()) {
return this.maxDatapointsLimit();
}
return limit;
}
private updateValidators() {
const aggType = this.timewindowForm.get('aggregation.type').value;
if (aggType !== AggregationType.NONE) {
this.timewindowForm.get('aggregation.limit').clearValidators();
} else {
this.timewindowForm.get('aggregation.limit').setValidators([Validators.min(this.minDatapointsLimit()),
Validators.max(this.maxDatapointsLimit())]);
}
this.timewindowForm.get('aggregation.limit').updateValueAndValidity({emitEvent: false});
}
update() {

Loading…
Cancel
Save