Timewindow: take into account default and allowed group intervals when switching between realtime and history

This commit is contained in:
Ekaterina Chantsova 2024-11-29 15:08:01 +02:00
parent 66c5917bd1
commit e7dca95e01
3 changed files with 165 additions and 120 deletions

View File

@ -26,7 +26,8 @@ import {
realtimeAllowedAggIntervals, realtimeAllowedAggIntervals,
RealtimeWindowType, RealtimeWindowType,
realtimeWindowTypeTranslations, realtimeWindowTypeTranslations,
Timewindow, TimewindowAggIntervalsConfig, Timewindow,
TimewindowAggIntervalsConfig,
TimewindowType, TimewindowType,
updateFormValuesOnTimewindowTypeChange updateFormValuesOnTimewindowTypeChange
} from '@shared/models/time/time.models'; } from '@shared/models/time/time.models';
@ -234,11 +235,13 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
hideTimezone: [ isDefinedAndNotNull(this.timewindow.hideTimezone) hideTimezone: [ isDefinedAndNotNull(this.timewindow.hideTimezone)
? this.timewindow.hideTimezone : false ] ? this.timewindow.hideTimezone : false ]
}); });
this.updateValidators(this.timewindowForm.get('aggregation.type').value);
if (this.aggregation) {
this.timewindowForm.get('realtime.timewindowMs').valueChanges.pipe( this.timewindowForm.get('realtime.timewindowMs').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((timewindowMs: number) => { ).subscribe((timewindowMs: number) => {
const lastAggIntervalsConfig:TimewindowAggIntervalsConfig = const lastAggIntervalsConfig: TimewindowAggIntervalsConfig =
this.timewindowForm.get('realtime.advancedParams.lastAggIntervalsConfig').value; this.timewindowForm.get('realtime.advancedParams.lastAggIntervalsConfig').value;
if (lastAggIntervalsConfig?.hasOwnProperty(timewindowMs) && if (lastAggIntervalsConfig?.hasOwnProperty(timewindowMs) &&
lastAggIntervalsConfig[timewindowMs].defaultAggInterval) { lastAggIntervalsConfig[timewindowMs].defaultAggInterval) {
@ -250,7 +253,7 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
this.timewindowForm.get('realtime.quickInterval').valueChanges.pipe( this.timewindowForm.get('realtime.quickInterval').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((quickInterval: number) => { ).subscribe((quickInterval: number) => {
const quickAggIntervalsConfig:TimewindowAggIntervalsConfig = const quickAggIntervalsConfig: TimewindowAggIntervalsConfig =
this.timewindowForm.get('realtime.advancedParams.quickAggIntervalsConfig').value; this.timewindowForm.get('realtime.advancedParams.quickAggIntervalsConfig').value;
if (quickAggIntervalsConfig?.hasOwnProperty(quickInterval) && if (quickAggIntervalsConfig?.hasOwnProperty(quickInterval) &&
quickAggIntervalsConfig[quickInterval].defaultAggInterval) { quickAggIntervalsConfig[quickInterval].defaultAggInterval) {
@ -262,7 +265,7 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
this.timewindowForm.get('history.timewindowMs').valueChanges.pipe( this.timewindowForm.get('history.timewindowMs').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((timewindowMs: number) => { ).subscribe((timewindowMs: number) => {
const lastAggIntervalsConfig:TimewindowAggIntervalsConfig = const lastAggIntervalsConfig: TimewindowAggIntervalsConfig =
this.timewindowForm.get('history.advancedParams.lastAggIntervalsConfig').value; this.timewindowForm.get('history.advancedParams.lastAggIntervalsConfig').value;
if (lastAggIntervalsConfig?.hasOwnProperty(timewindowMs) && if (lastAggIntervalsConfig?.hasOwnProperty(timewindowMs) &&
lastAggIntervalsConfig[timewindowMs].defaultAggInterval) { lastAggIntervalsConfig[timewindowMs].defaultAggInterval) {
@ -274,7 +277,7 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
this.timewindowForm.get('history.quickInterval').valueChanges.pipe( this.timewindowForm.get('history.quickInterval').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((quickInterval: number) => { ).subscribe((quickInterval: number) => {
const quickAggIntervalsConfig:TimewindowAggIntervalsConfig = const quickAggIntervalsConfig: TimewindowAggIntervalsConfig =
this.timewindowForm.get('history.advancedParams.quickAggIntervalsConfig').value; this.timewindowForm.get('history.advancedParams.quickAggIntervalsConfig').value;
if (quickAggIntervalsConfig?.hasOwnProperty(quickInterval) && if (quickAggIntervalsConfig?.hasOwnProperty(quickInterval) &&
quickAggIntervalsConfig[quickInterval].defaultAggInterval) { quickAggIntervalsConfig[quickInterval].defaultAggInterval) {
@ -284,12 +287,13 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
} }
}); });
this.updateValidators(this.timewindowForm.get('aggregation.type').value);
this.timewindowForm.get('aggregation.type').valueChanges.pipe( this.timewindowForm.get('aggregation.type').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((aggregationType: AggregationType) => { ).subscribe((aggregationType: AggregationType) => {
this.updateValidators(aggregationType); this.updateValidators(aggregationType);
}); });
}
this.timewindowForm.get('selectedTab').valueChanges.pipe( this.timewindowForm.get('selectedTab').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((selectedTab: TimewindowType) => { ).subscribe((selectedTab: TimewindowType) => {
@ -414,13 +418,9 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
const timewindowFormValue = this.timewindowForm.getRawValue(); const timewindowFormValue = this.timewindowForm.getRawValue();
const realtimeDisableCustomInterval = timewindowFormValue.realtime.disableCustomInterval; const realtimeDisableCustomInterval = timewindowFormValue.realtime.disableCustomInterval;
const historyDisableCustomInterval = timewindowFormValue.history.disableCustomInterval; const historyDisableCustomInterval = timewindowFormValue.history.disableCustomInterval;
const realtimeAllowedLastIntervals = timewindowFormValue.realtime.advancedParams.allowedLastIntervals;
const realtimeAllowedQuickIntervals = timewindowFormValue.realtime.advancedParams.allowedQuickIntervals;
const historyAllowedLastIntervals = timewindowFormValue.history.advancedParams.allowedLastIntervals;
const historyAllowedQuickIntervals = timewindowFormValue.history.advancedParams.allowedQuickIntervals;
updateFormValuesOnTimewindowTypeChange(selectedTab, this.quickIntervalOnly, this.timewindowForm, updateFormValuesOnTimewindowTypeChange(selectedTab, this.quickIntervalOnly, this.timewindowForm,
realtimeDisableCustomInterval, historyDisableCustomInterval, realtimeDisableCustomInterval, historyDisableCustomInterval,
realtimeAllowedLastIntervals, realtimeAllowedQuickIntervals, historyAllowedLastIntervals, historyAllowedQuickIntervals); timewindowFormValue.realtime.advancedParams, timewindowFormValue.history.advancedParams);
this.timewindowForm.patchValue({ this.timewindowForm.patchValue({
hideAggregation: timewindowFormValue.hideAggregation, hideAggregation: timewindowFormValue.hideAggregation,
hideAggInterval: timewindowFormValue.hideAggInterval, hideAggInterval: timewindowFormValue.hideAggInterval,
@ -623,6 +623,7 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
if (result) { if (result) {
this.timewindowForm.get(allowedIntervalsControlName).patchValue(result.allowedIntervals); this.timewindowForm.get(allowedIntervalsControlName).patchValue(result.allowedIntervals);
this.timewindowForm.get(aggIntervalsConfigControlName).patchValue(result.aggIntervalsConfig); this.timewindowForm.get(aggIntervalsConfigControlName).patchValue(result.aggIntervalsConfig);
this.timewindowForm.markAsDirty();
} }
} }
}, },

View File

@ -18,11 +18,13 @@ import { Component, Inject, InjectionToken, OnDestroy, OnInit, ViewContainerRef
import { import {
AggregationType, AggregationType,
currentHistoryTimewindow, currentHistoryTimewindow,
currentRealtimeTimewindow, historyAllowedAggIntervals, currentRealtimeTimewindow,
historyAllowedAggIntervals,
HistoryWindowType, HistoryWindowType,
historyWindowTypeTranslations, historyWindowTypeTranslations,
Interval, Interval,
QuickTimeInterval, realtimeAllowedAggIntervals, QuickTimeInterval,
realtimeAllowedAggIntervals,
RealtimeWindowType, RealtimeWindowType,
realtimeWindowTypeTranslations, realtimeWindowTypeTranslations,
Timewindow, Timewindow,
@ -298,7 +300,9 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
disabled: hideTimezone disabled: hideTimezone
}] }]
}); });
this.updateValidators(this.timewindowForm.get('aggregation.type').value);
if (this.aggregation) {
this.timewindowForm.get('realtime.timewindowMs').valueChanges.pipe( this.timewindowForm.get('realtime.timewindowMs').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((timewindowMs: number) => { ).subscribe((timewindowMs: number) => {
@ -340,12 +344,12 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
} }
}); });
this.updateValidators(this.timewindowForm.get('aggregation.type').value);
this.timewindowForm.get('aggregation.type').valueChanges.pipe( this.timewindowForm.get('aggregation.type').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe((aggregationType: AggregationType) => { ).subscribe((aggregationType: AggregationType) => {
this.updateValidators(aggregationType); this.updateValidators(aggregationType);
}); });
}
this.timewindowForm.get('selectedTab').valueChanges.pipe( this.timewindowForm.get('selectedTab').valueChanges.pipe(
takeUntil(this.destroy$) takeUntil(this.destroy$)
@ -371,7 +375,7 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
private onTimewindowTypeChange(selectedTab: TimewindowType) { private onTimewindowTypeChange(selectedTab: TimewindowType) {
updateFormValuesOnTimewindowTypeChange(selectedTab, this.quickIntervalOnly, this.timewindowForm, updateFormValuesOnTimewindowTypeChange(selectedTab, this.quickIntervalOnly, this.timewindowForm,
this.realtimeDisableCustomInterval, this.historyDisableCustomInterval, this.realtimeDisableCustomInterval, this.historyDisableCustomInterval,
this.realtimeAllowedLastIntervals, this.realtimeAllowedQuickIntervals, this.historyAllowedLastIntervals, this.historyAllowedQuickIntervals); this.realtimeAdvancedParams, this.historyAdvancedParams);
} }
update() { update() {

View File

@ -528,8 +528,8 @@ export const timewindowTypeChanged = (newTimewindow: Timewindow, oldTimewindow:
export const updateFormValuesOnTimewindowTypeChange = (selectedTab: TimewindowType, export const updateFormValuesOnTimewindowTypeChange = (selectedTab: TimewindowType,
quickIntervalOnly: boolean, timewindowForm: FormGroup, quickIntervalOnly: boolean, timewindowForm: FormGroup,
realtimeDisableCustomInterval: boolean, historyDisableCustomInterval: boolean, realtimeDisableCustomInterval: boolean, historyDisableCustomInterval: boolean,
realtimeAllowedLastIntervals?: Array<Interval>, realtimeAllowedQuickIntervals?: Array<QuickTimeInterval>, realtimeAdvancedParams?: TimewindowAdvancedParams,
historyAllowedLastIntervals?: Array<Interval>, historyAllowedQuickIntervals?: Array<QuickTimeInterval>) => { historyAdvancedParams?: TimewindowAdvancedParams) => {
const timewindowFormValue = timewindowForm.getRawValue(); const timewindowFormValue = timewindowForm.getRawValue();
if (selectedTab === TimewindowType.REALTIME) { if (selectedTab === TimewindowType.REALTIME) {
if (timewindowFormValue.history.historyType !== HistoryWindowType.FIXED if (timewindowFormValue.history.historyType !== HistoryWindowType.FIXED
@ -538,25 +538,37 @@ export const updateFormValuesOnTimewindowTypeChange = (selectedTab: TimewindowTy
timewindowForm.get('realtime.realtimeType').patchValue(RealtimeWindowType[HistoryWindowType[timewindowFormValue.history.historyType]]); timewindowForm.get('realtime.realtimeType').patchValue(RealtimeWindowType[HistoryWindowType[timewindowFormValue.history.historyType]]);
} }
if (!realtimeDisableCustomInterval || if (!realtimeDisableCustomInterval ||
!realtimeAllowedLastIntervals?.length || realtimeAllowedLastIntervals.includes(timewindowFormValue.history.timewindowMs)) { !realtimeAdvancedParams?.allowedLastIntervals?.length || realtimeAdvancedParams.allowedLastIntervals.includes(timewindowFormValue.history.timewindowMs)) {
timewindowForm.get('realtime.timewindowMs').patchValue(timewindowFormValue.history.timewindowMs); timewindowForm.get('realtime.timewindowMs').patchValue(timewindowFormValue.history.timewindowMs);
} }
if (realtimeAllowedQuickIntervals?.includes(timewindowFormValue.history.quickInterval) || if (realtimeAdvancedParams?.allowedQuickIntervals?.includes(timewindowFormValue.history.quickInterval) ||
(!realtimeAllowedQuickIntervals?.length && timewindowFormValue.history.quickInterval.startsWith('CURRENT'))) { (!realtimeAdvancedParams?.allowedQuickIntervals?.length && timewindowFormValue.history.quickInterval.startsWith('CURRENT'))) {
timewindowForm.get('realtime.quickInterval').patchValue(timewindowFormValue.history.quickInterval); timewindowForm.get('realtime.quickInterval').patchValue(timewindowFormValue.history.quickInterval);
} }
setTimeout(() => timewindowForm.get('realtime.interval').patchValue(timewindowFormValue.history.interval)); const defaultAggInterval = realtimeDefaultAggInterval(timewindowForm.getRawValue(), realtimeAdvancedParams);
const allowedAggIntervals = realtimeAllowedAggIntervals(timewindowForm.getRawValue(), realtimeAdvancedParams);
if (defaultAggInterval || !allowedAggIntervals.length || allowedAggIntervals.includes(timewindowFormValue.history.interval)) {
setTimeout(() => timewindowForm.get('realtime.interval').patchValue(
defaultAggInterval ?? timewindowFormValue.history.interval
));
}
} }
} else { } else {
timewindowForm.get('history.historyType').patchValue(HistoryWindowType[RealtimeWindowType[timewindowFormValue.realtime.realtimeType]]); timewindowForm.get('history.historyType').patchValue(HistoryWindowType[RealtimeWindowType[timewindowFormValue.realtime.realtimeType]]);
if (!historyDisableCustomInterval || if (!historyDisableCustomInterval ||
!historyAllowedLastIntervals?.length || historyAllowedLastIntervals?.includes(timewindowFormValue.realtime.timewindowMs)) { !historyAdvancedParams?.allowedLastIntervals?.length || historyAdvancedParams.allowedLastIntervals?.includes(timewindowFormValue.realtime.timewindowMs)) {
timewindowForm.get('history.timewindowMs').patchValue(timewindowFormValue.realtime.timewindowMs); timewindowForm.get('history.timewindowMs').patchValue(timewindowFormValue.realtime.timewindowMs);
} }
if (!historyAllowedQuickIntervals?.length || historyAllowedQuickIntervals?.includes(timewindowFormValue.realtime.quickInterval)) { if (!historyAdvancedParams?.allowedQuickIntervals?.length || historyAdvancedParams.allowedQuickIntervals?.includes(timewindowFormValue.realtime.quickInterval)) {
timewindowForm.get('history.quickInterval').patchValue(timewindowFormValue.realtime.quickInterval); timewindowForm.get('history.quickInterval').patchValue(timewindowFormValue.realtime.quickInterval);
} }
setTimeout(() => timewindowForm.get('history.interval').patchValue(timewindowFormValue.realtime.interval)); const defaultAggInterval = historyDefaultAggInterval(timewindowForm.getRawValue(), historyAdvancedParams);
const allowedAggIntervals = historyAllowedAggIntervals(timewindowForm.getRawValue(), historyAdvancedParams);
if (defaultAggInterval || !allowedAggIntervals.length || allowedAggIntervals.includes(timewindowFormValue.realtime.interval)) {
setTimeout(() => timewindowForm.get('history.interval').patchValue(
defaultAggInterval ?? timewindowFormValue.realtime.interval
));
}
} }
timewindowForm.patchValue({ timewindowForm.patchValue({
aggregation: { aggregation: {
@ -619,6 +631,34 @@ export const historyAllowedAggIntervals = (timewindow: Timewindow,
return []; return [];
}; };
export const realtimeDefaultAggInterval = (timewindow: Timewindow,
advancedParams: TimewindowAdvancedParams): Interval => {
if (timewindow.realtime.realtimeType === RealtimeWindowType.LAST_INTERVAL &&
advancedParams?.lastAggIntervalsConfig?.hasOwnProperty(timewindow.realtime.timewindowMs) &&
advancedParams.lastAggIntervalsConfig[timewindow.realtime.timewindowMs].defaultAggInterval) {
return advancedParams.lastAggIntervalsConfig[timewindow.realtime.timewindowMs].defaultAggInterval;
} else if (timewindow.realtime.realtimeType === RealtimeWindowType.INTERVAL &&
advancedParams?.quickAggIntervalsConfig?.hasOwnProperty(timewindow.realtime.quickInterval) &&
advancedParams.quickAggIntervalsConfig[timewindow.realtime.quickInterval].defaultAggInterval) {
return advancedParams.quickAggIntervalsConfig[timewindow.realtime.quickInterval].defaultAggInterval;
}
return null;
};
export const historyDefaultAggInterval = (timewindow: Timewindow,
advancedParams: TimewindowAdvancedParams): Interval => {
if (timewindow.history.historyType === HistoryWindowType.LAST_INTERVAL &&
advancedParams?.lastAggIntervalsConfig?.hasOwnProperty(timewindow.history.timewindowMs) &&
advancedParams.lastAggIntervalsConfig[timewindow.history.timewindowMs].defaultAggInterval) {
return advancedParams.lastAggIntervalsConfig[timewindow.history.timewindowMs].defaultAggInterval;
} else if (timewindow.history.historyType === HistoryWindowType.INTERVAL &&
advancedParams?.quickAggIntervalsConfig?.hasOwnProperty(timewindow.history.quickInterval) &&
advancedParams.quickAggIntervalsConfig[timewindow.history.quickInterval].defaultAggInterval) {
return advancedParams.quickAggIntervalsConfig[timewindow.history.quickInterval].defaultAggInterval;
}
return null;
};
export const getTimezone = (tz: string): moment_.Moment => moment.tz(tz); export const getTimezone = (tz: string): moment_.Moment => moment.tz(tz);
export const calculateTsOffset = (timezone?: string): number => { export const calculateTsOffset = (timezone?: string): number => {