Timewindow: clear parameters depending on selected aggregation function
This commit is contained in:
parent
8390760698
commit
3fb6a30c50
@ -29,6 +29,7 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
|||||||
import { TimeService } from '@core/services/time.service';
|
import { TimeService } from '@core/services/time.service';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
import { isDefined } from '@core/utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-datapoints-limit',
|
selector: 'tb-datapoints-limit',
|
||||||
@ -69,7 +70,11 @@ export class DatapointsLimitComponent implements ControlValueAccessor, Validator
|
|||||||
@Input()
|
@Input()
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
|
||||||
private propagateChange = (v: any) => { };
|
private propagateChangeValue: any;
|
||||||
|
|
||||||
|
private propagateChange = (v: any) => {
|
||||||
|
this.propagateChangeValue = v;
|
||||||
|
};
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
|
||||||
@ -79,6 +84,9 @@ export class DatapointsLimitComponent implements ControlValueAccessor, Validator
|
|||||||
|
|
||||||
registerOnChange(fn: any): void {
|
registerOnChange(fn: any): void {
|
||||||
this.propagateChange = fn;
|
this.propagateChange = fn;
|
||||||
|
if (isDefined(this.propagateChangeValue)) {
|
||||||
|
this.propagateChange(this.propagateChangeValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOnTouched(fn: any): void {
|
registerOnTouched(fn: any): void {
|
||||||
@ -115,19 +123,20 @@ export class DatapointsLimitComponent implements ControlValueAccessor, Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkLimit(limit?: number): number {
|
writeValue(value: number | null): void {
|
||||||
if (!limit || limit < this.minDatapointsLimit()) {
|
this.modelValue = value;
|
||||||
return this.minDatapointsLimit();
|
let limit = this.modelValue;
|
||||||
|
if (!limit) {
|
||||||
|
limit = Math.ceil(this.maxDatapointsLimit() / 2);
|
||||||
|
} else if (limit < this.minDatapointsLimit()) {
|
||||||
|
limit = this.minDatapointsLimit();
|
||||||
} else if (limit > this.maxDatapointsLimit()) {
|
} else if (limit > this.maxDatapointsLimit()) {
|
||||||
return this.maxDatapointsLimit();
|
limit = this.maxDatapointsLimit();
|
||||||
}
|
|
||||||
return limit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeValue(value: number | null): void {
|
this.updateView(limit);
|
||||||
this.modelValue = this.checkLimit(value);
|
|
||||||
this.datapointsLimitFormGroup.patchValue(
|
this.datapointsLimitFormGroup.patchValue(
|
||||||
{ limit: this.modelValue }, {emitEvent: false}
|
{ limit: limit }, {emitEvent: false}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1125,6 +1125,7 @@ export const cloneSelectedTimewindow = (timewindow: Timewindow): Timewindow => {
|
|||||||
|
|
||||||
export const clearTimewindowConfig = (timewindow: Timewindow, quickIntervalOnly: boolean,
|
export const clearTimewindowConfig = (timewindow: Timewindow, quickIntervalOnly: boolean,
|
||||||
historyOnly: boolean, hasAggregation: boolean, hasTimezone = true): Timewindow => {
|
historyOnly: boolean, hasAggregation: boolean, hasTimezone = true): Timewindow => {
|
||||||
|
const noneAggregation = hasAggregation && timewindow.aggregation?.type === AggregationType.NONE;
|
||||||
if (timewindow.selectedTab === TimewindowType.REALTIME) {
|
if (timewindow.selectedTab === TimewindowType.REALTIME) {
|
||||||
if (quickIntervalOnly || timewindow.realtime.realtimeType === RealtimeWindowType.INTERVAL) {
|
if (quickIntervalOnly || timewindow.realtime.realtimeType === RealtimeWindowType.INTERVAL) {
|
||||||
delete timewindow.realtime.timewindowMs;
|
delete timewindow.realtime.timewindowMs;
|
||||||
@ -1138,7 +1139,7 @@ export const clearTimewindowConfig = (timewindow: Timewindow, quickIntervalOnly:
|
|||||||
delete timewindow.history?.quickInterval;
|
delete timewindow.history?.quickInterval;
|
||||||
|
|
||||||
delete timewindow.history?.interval;
|
delete timewindow.history?.interval;
|
||||||
if (!hasAggregation) {
|
if (!hasAggregation || noneAggregation) {
|
||||||
delete timewindow.realtime.interval;
|
delete timewindow.realtime.interval;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1162,13 +1163,15 @@ export const clearTimewindowConfig = (timewindow: Timewindow, quickIntervalOnly:
|
|||||||
delete timewindow.realtime?.quickInterval;
|
delete timewindow.realtime?.quickInterval;
|
||||||
|
|
||||||
delete timewindow.realtime?.interval;
|
delete timewindow.realtime?.interval;
|
||||||
if (!hasAggregation) {
|
if (!hasAggregation || noneAggregation) {
|
||||||
delete timewindow.history.interval;
|
delete timewindow.history.interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasAggregation) {
|
if (!hasAggregation) {
|
||||||
delete timewindow.aggregation;
|
delete timewindow.aggregation;
|
||||||
|
} else if (!noneAggregation) {
|
||||||
|
delete timewindow.aggregation.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (historyOnly) {
|
if (historyOnly) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user