UI: Fix timewindow panel form validation - disable aggregation limit check when aggregation is not none.
This commit is contained in:
parent
423a9e2e04
commit
442bb83784
@ -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"
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user