Timewindow: leave only selected realtime/history and aggregation parameters for saving and remove others from configuration

This commit is contained in:
Ekaterina Chantsova 2025-07-18 18:56:02 +03:00
parent 3491419dd9
commit 083078b7f5
5 changed files with 192 additions and 105 deletions

View File

@ -295,7 +295,8 @@ export class DashboardUtilsService {
widgetConfig.datasources = this.validateAndUpdateDatasources(widgetConfig.datasources); widgetConfig.datasources = this.validateAndUpdateDatasources(widgetConfig.datasources);
if (type === widgetType.latest) { if (type === widgetType.latest) {
const onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(widgetConfig.datasources); const onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(widgetConfig.datasources);
widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, onlyHistoryTimewindow, this.timeService); widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true,
onlyHistoryTimewindow, this.timeService, false);
} else if (type === widgetType.rpc) { } else if (type === widgetType.rpc) {
if (widgetConfig.targetDeviceAliasIds && widgetConfig.targetDeviceAliasIds.length) { if (widgetConfig.targetDeviceAliasIds && widgetConfig.targetDeviceAliasIds.length) {
widgetConfig.targetDevice = { widgetConfig.targetDevice = {

View File

@ -152,73 +152,73 @@ export class TimewindowConfigDialogComponent extends PageComponent implements On
this.timewindowForm = this.fb.group({ this.timewindowForm = this.fb.group({
selectedTab: [isDefined(this.timewindow.selectedTab) ? this.timewindow.selectedTab : TimewindowType.REALTIME], selectedTab: [isDefined(this.timewindow.selectedTab) ? this.timewindow.selectedTab : TimewindowType.REALTIME],
realtime: this.fb.group({ realtime: this.fb.group({
realtimeType: [ isDefined(realtime?.realtimeType) ? this.timewindow.realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL ], realtimeType: [ isDefined(realtime?.realtimeType) ? realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL ],
timewindowMs: [ isDefined(realtime?.timewindowMs) ? this.timewindow.realtime.timewindowMs : null ], timewindowMs: [ isDefined(realtime?.timewindowMs) ? realtime.timewindowMs : null ],
interval: [ isDefined(realtime?.interval) ? this.timewindow.realtime.interval : null ], interval: [ isDefined(realtime?.interval) ? realtime.interval : null ],
quickInterval: [ isDefined(realtime?.quickInterval) ? this.timewindow.realtime.quickInterval : null ], quickInterval: [ isDefined(realtime?.quickInterval) ? realtime.quickInterval : null ],
disableCustomInterval: [ isDefinedAndNotNull(this.timewindow.realtime?.disableCustomInterval) disableCustomInterval: [ isDefinedAndNotNull(realtime?.disableCustomInterval)
? this.timewindow.realtime?.disableCustomInterval : false ], ? realtime.disableCustomInterval : false ],
disableCustomGroupInterval: [ isDefinedAndNotNull(this.timewindow.realtime?.disableCustomGroupInterval) disableCustomGroupInterval: [ isDefinedAndNotNull(realtime?.disableCustomGroupInterval)
? this.timewindow.realtime?.disableCustomGroupInterval : false ], ? realtime.disableCustomGroupInterval : false ],
hideInterval: [ isDefinedAndNotNull(this.timewindow.realtime.hideInterval) hideInterval: [ isDefinedAndNotNull(realtime?.hideInterval)
? this.timewindow.realtime.hideInterval : false ], ? realtime.hideInterval : false ],
hideLastInterval: [{ hideLastInterval: [{
value: isDefinedAndNotNull(this.timewindow.realtime.hideLastInterval) value: isDefinedAndNotNull(realtime?.hideLastInterval)
? this.timewindow.realtime.hideLastInterval : false, ? realtime.hideLastInterval : false,
disabled: this.timewindow.realtime.hideInterval disabled: realtime?.hideInterval
}], }],
hideQuickInterval: [{ hideQuickInterval: [{
value: isDefinedAndNotNull(this.timewindow.realtime.hideQuickInterval) value: isDefinedAndNotNull(realtime?.hideQuickInterval)
? this.timewindow.realtime.hideQuickInterval : false, ? realtime.hideQuickInterval : false,
disabled: this.timewindow.realtime.hideInterval disabled: realtime?.hideInterval
}], }],
advancedParams: this.fb.group({ advancedParams: this.fb.group({
allowedLastIntervals: [ isDefinedAndNotNull(this.timewindow.realtime?.advancedParams?.allowedLastIntervals) allowedLastIntervals: [ isDefinedAndNotNull(realtime?.advancedParams?.allowedLastIntervals)
? this.timewindow.realtime.advancedParams.allowedLastIntervals : null ], ? realtime.advancedParams.allowedLastIntervals : null ],
allowedQuickIntervals: [ isDefinedAndNotNull(this.timewindow.realtime?.advancedParams?.allowedQuickIntervals) allowedQuickIntervals: [ isDefinedAndNotNull(realtime?.advancedParams?.allowedQuickIntervals)
? this.timewindow.realtime.advancedParams.allowedQuickIntervals : null ], ? realtime.advancedParams.allowedQuickIntervals : null ],
lastAggIntervalsConfig: [ isDefinedAndNotNull(this.timewindow.realtime?.advancedParams?.lastAggIntervalsConfig) lastAggIntervalsConfig: [ isDefinedAndNotNull(realtime?.advancedParams?.lastAggIntervalsConfig)
? this.timewindow.realtime.advancedParams.lastAggIntervalsConfig : null ], ? realtime.advancedParams.lastAggIntervalsConfig : null ],
quickAggIntervalsConfig: [ isDefinedAndNotNull(this.timewindow.realtime?.advancedParams?.quickAggIntervalsConfig) quickAggIntervalsConfig: [ isDefinedAndNotNull(realtime?.advancedParams?.quickAggIntervalsConfig)
? this.timewindow.realtime.advancedParams.quickAggIntervalsConfig : null ] ? realtime.advancedParams.quickAggIntervalsConfig : null ]
}) })
}), }),
history: this.fb.group({ history: this.fb.group({
historyType: [ isDefined(history?.historyType) ? this.timewindow.history.historyType : HistoryWindowType.LAST_INTERVAL ], historyType: [ isDefined(history?.historyType) ? history.historyType : HistoryWindowType.LAST_INTERVAL ],
timewindowMs: [ isDefined(history?.timewindowMs) ? this.timewindow.history.timewindowMs : null ], timewindowMs: [ isDefined(history?.timewindowMs) ? history.timewindowMs : null ],
interval: [ isDefined(history?.interval) ? this.timewindow.history.interval : null ], interval: [ isDefined(history?.interval) ? history.interval : null ],
fixedTimewindow: [ isDefined(history?.fixedTimewindow) ? this.timewindow.history.fixedTimewindow : null ], fixedTimewindow: [ isDefined(history?.fixedTimewindow) ? history.fixedTimewindow : null ],
quickInterval: [ isDefined(history?.quickInterval) ? this.timewindow.history.quickInterval : null ], quickInterval: [ isDefined(history?.quickInterval) ? history.quickInterval : null ],
disableCustomInterval: [ isDefinedAndNotNull(this.timewindow.history?.disableCustomInterval) disableCustomInterval: [ isDefinedAndNotNull(history?.disableCustomInterval)
? this.timewindow.history?.disableCustomInterval : false ], ? history.disableCustomInterval : false ],
disableCustomGroupInterval: [ isDefinedAndNotNull(this.timewindow.history?.disableCustomGroupInterval) disableCustomGroupInterval: [ isDefinedAndNotNull(history?.disableCustomGroupInterval)
? this.timewindow.history?.disableCustomGroupInterval : false ], ? history.disableCustomGroupInterval : false ],
hideInterval: [ isDefinedAndNotNull(this.timewindow.history.hideInterval) hideInterval: [ isDefinedAndNotNull(history?.hideInterval)
? this.timewindow.history.hideInterval : false ], ? history.hideInterval : false ],
hideLastInterval: [{ hideLastInterval: [{
value: isDefinedAndNotNull(this.timewindow.history.hideLastInterval) value: isDefinedAndNotNull(history?.hideLastInterval)
? this.timewindow.history.hideLastInterval : false, ? history.hideLastInterval : false,
disabled: this.timewindow.history.hideInterval disabled: history?.hideInterval
}], }],
hideQuickInterval: [{ hideQuickInterval: [{
value: isDefinedAndNotNull(this.timewindow.history.hideQuickInterval) value: isDefinedAndNotNull(history?.hideQuickInterval)
? this.timewindow.history.hideQuickInterval : false, ? history.hideQuickInterval : false,
disabled: this.timewindow.history.hideInterval disabled: history?.hideInterval
}], }],
hideFixedInterval: [{ hideFixedInterval: [{
value: isDefinedAndNotNull(this.timewindow.history.hideFixedInterval) value: isDefinedAndNotNull(history?.hideFixedInterval)
? this.timewindow.history.hideFixedInterval : false, ? history.hideFixedInterval : false,
disabled: this.timewindow.history.hideInterval disabled: history?.hideInterval
}], }],
advancedParams: this.fb.group({ advancedParams: this.fb.group({
allowedLastIntervals: [ isDefinedAndNotNull(this.timewindow.history?.advancedParams?.allowedLastIntervals) allowedLastIntervals: [ isDefinedAndNotNull(history?.advancedParams?.allowedLastIntervals)
? this.timewindow.history.advancedParams.allowedLastIntervals : null ], ? history.advancedParams.allowedLastIntervals : null ],
allowedQuickIntervals: [ isDefinedAndNotNull(this.timewindow.history?.advancedParams?.allowedQuickIntervals) allowedQuickIntervals: [ isDefinedAndNotNull(history?.advancedParams?.allowedQuickIntervals)
? this.timewindow.history.advancedParams.allowedQuickIntervals : null ], ? history.advancedParams.allowedQuickIntervals : null ],
lastAggIntervalsConfig: [ isDefinedAndNotNull(this.timewindow.history?.advancedParams?.lastAggIntervalsConfig) lastAggIntervalsConfig: [ isDefinedAndNotNull(history?.advancedParams?.lastAggIntervalsConfig)
? this.timewindow.history.advancedParams.lastAggIntervalsConfig : null ], ? history.advancedParams.lastAggIntervalsConfig : null ],
quickAggIntervalsConfig: [ isDefinedAndNotNull(this.timewindow.history?.advancedParams?.quickAggIntervalsConfig) quickAggIntervalsConfig: [ isDefinedAndNotNull(history?.advancedParams?.quickAggIntervalsConfig)
? this.timewindow.history.advancedParams.quickAggIntervalsConfig : null ] ? history.advancedParams.quickAggIntervalsConfig : null ]
}) })
}), }),
aggregation: this.fb.group({ aggregation: this.fb.group({

View File

@ -27,12 +27,14 @@ import {
} from '@angular/core'; } from '@angular/core';
import { import {
AggregationType, AggregationType,
clearTimewindowConfig,
currentHistoryTimewindow, currentHistoryTimewindow,
currentRealtimeTimewindow, currentRealtimeTimewindow,
historyAllowedAggIntervals, historyAllowedAggIntervals,
HistoryWindowType, HistoryWindowType,
historyWindowTypeTranslations, historyWindowTypeTranslations,
Interval, Interval,
MINUTE,
QuickTimeInterval, QuickTimeInterval,
realtimeAllowedAggIntervals, realtimeAllowedAggIntervals,
RealtimeWindowType, RealtimeWindowType,
@ -167,14 +169,14 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
}); });
} }
if ((this.isEdit || !this.timewindow.realtime.hideLastInterval) && !this.quickIntervalOnly) { if ((this.isEdit || !this.timewindow.realtime?.hideLastInterval) && !this.quickIntervalOnly) {
this.realtimeTimewindowOptions.push({ this.realtimeTimewindowOptions.push({
name: this.translate.instant(realtimeWindowTypeTranslations.get(RealtimeWindowType.LAST_INTERVAL)), name: this.translate.instant(realtimeWindowTypeTranslations.get(RealtimeWindowType.LAST_INTERVAL)),
value: this.realtimeTypes.LAST_INTERVAL value: this.realtimeTypes.LAST_INTERVAL
}); });
} }
if (this.isEdit || !this.timewindow.realtime.hideQuickInterval || this.quickIntervalOnly) { if (this.isEdit || !this.timewindow.realtime?.hideQuickInterval || this.quickIntervalOnly) {
this.realtimeTimewindowOptions.push({ this.realtimeTimewindowOptions.push({
name: this.translate.instant(realtimeWindowTypeTranslations.get(RealtimeWindowType.INTERVAL)), name: this.translate.instant(realtimeWindowTypeTranslations.get(RealtimeWindowType.INTERVAL)),
value: this.realtimeTypes.INTERVAL value: this.realtimeTypes.INTERVAL
@ -188,21 +190,21 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
}); });
} }
if (this.isEdit || !this.timewindow.history.hideLastInterval) { if (this.isEdit || !this.timewindow.history?.hideLastInterval) {
this.historyTimewindowOptions.push({ this.historyTimewindowOptions.push({
name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.LAST_INTERVAL)), name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.LAST_INTERVAL)),
value: this.historyTypes.LAST_INTERVAL value: this.historyTypes.LAST_INTERVAL
}); });
} }
if (this.isEdit || !this.timewindow.history.hideFixedInterval) { if (this.isEdit || !this.timewindow.history?.hideFixedInterval) {
this.historyTimewindowOptions.push({ this.historyTimewindowOptions.push({
name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.FIXED)), name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.FIXED)),
value: this.historyTypes.FIXED value: this.historyTypes.FIXED
}); });
} }
if (this.isEdit || !this.timewindow.history.hideQuickInterval) { if (this.isEdit || !this.timewindow.history?.hideQuickInterval) {
this.historyTimewindowOptions.push({ this.historyTimewindowOptions.push({
name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.INTERVAL)), name: this.translate.instant(historyWindowTypeTranslations.get(HistoryWindowType.INTERVAL)),
value: this.historyTypes.INTERVAL value: this.historyTypes.INTERVAL
@ -211,10 +213,10 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
this.realtimeTypeSelectionAvailable = this.realtimeTimewindowOptions.length > 1; this.realtimeTypeSelectionAvailable = this.realtimeTimewindowOptions.length > 1;
this.historyTypeSelectionAvailable = this.historyTimewindowOptions.length > 1; this.historyTypeSelectionAvailable = this.historyTimewindowOptions.length > 1;
this.realtimeIntervalSelectionAvailable = this.isEdit || !(this.timewindow.realtime.hideInterval || this.realtimeIntervalSelectionAvailable = this.isEdit || !(this.timewindow.realtime?.hideInterval ||
(this.timewindow.realtime.hideLastInterval && this.timewindow.realtime.hideQuickInterval)); (this.timewindow.realtime?.hideLastInterval && this.timewindow.realtime?.hideQuickInterval));
this.historyIntervalSelectionAvailable = this.isEdit || !(this.timewindow.history.hideInterval || this.historyIntervalSelectionAvailable = this.isEdit || !(this.timewindow.history?.hideInterval ||
(this.timewindow.history.hideLastInterval && this.timewindow.history.hideQuickInterval && this.timewindow.history.hideFixedInterval)); (this.timewindow.history?.hideLastInterval && this.timewindow.history?.hideQuickInterval && this.timewindow.history?.hideFixedInterval));
this.aggregationOptionsAvailable = this.aggregation && (this.isEdit || this.aggregationOptionsAvailable = this.aggregation && (this.isEdit ||
!(this.timewindow.hideAggregation && this.timewindow.hideAggInterval)); !(this.timewindow.hideAggregation && this.timewindow.hideAggInterval));
@ -230,28 +232,28 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
const aggregation = this.timewindow.aggregation; const aggregation = this.timewindow.aggregation;
if (!this.isEdit) { if (!this.isEdit) {
if (realtime.hideLastInterval && !realtime.hideQuickInterval) { if (realtime?.hideLastInterval && !realtime?.hideQuickInterval) {
realtime.realtimeType = RealtimeWindowType.INTERVAL; realtime.realtimeType = RealtimeWindowType.INTERVAL;
} }
if (realtime.hideQuickInterval && !realtime.hideLastInterval) { if (realtime?.hideQuickInterval && !realtime?.hideLastInterval) {
realtime.realtimeType = RealtimeWindowType.LAST_INTERVAL; realtime.realtimeType = RealtimeWindowType.LAST_INTERVAL;
} }
if (history.hideLastInterval) { if (history?.hideLastInterval) {
if (!history.hideFixedInterval) { if (!history.hideFixedInterval) {
history.historyType = HistoryWindowType.FIXED; history.historyType = HistoryWindowType.FIXED;
} else if (!history.hideQuickInterval) { } else if (!history.hideQuickInterval) {
history.historyType = HistoryWindowType.INTERVAL; history.historyType = HistoryWindowType.INTERVAL;
} }
} }
if (history.hideFixedInterval) { if (history?.hideFixedInterval) {
if (!history.hideLastInterval) { if (!history.hideLastInterval) {
history.historyType = HistoryWindowType.LAST_INTERVAL; history.historyType = HistoryWindowType.LAST_INTERVAL;
} else if (!history.hideQuickInterval) { } else if (!history.hideQuickInterval) {
history.historyType = HistoryWindowType.INTERVAL; history.historyType = HistoryWindowType.INTERVAL;
} }
} }
if (history.hideQuickInterval) { if (history?.hideQuickInterval) {
if (!history.hideLastInterval) { if (!history.hideLastInterval) {
history.historyType = HistoryWindowType.LAST_INTERVAL; history.historyType = HistoryWindowType.LAST_INTERVAL;
} else if (!history.hideFixedInterval) { } else if (!history.hideFixedInterval) {
@ -265,29 +267,29 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
realtime: this.fb.group({ realtime: this.fb.group({
realtimeType: [{ realtimeType: [{
value: isDefined(realtime?.realtimeType) ? realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL, value: isDefined(realtime?.realtimeType) ? realtime.realtimeType : RealtimeWindowType.LAST_INTERVAL,
disabled: realtime.hideInterval disabled: realtime?.hideInterval
}], }],
timewindowMs: [{ timewindowMs: [{
value: isDefined(realtime?.timewindowMs) ? realtime.timewindowMs : null, value: isDefined(realtime?.timewindowMs) ? realtime.timewindowMs : MINUTE,
disabled: realtime.hideInterval || realtime.hideLastInterval disabled: realtime?.hideInterval || realtime?.hideLastInterval
}], }],
interval: [{ interval: [{
value:isDefined(realtime?.interval) ? realtime.interval : null, value:isDefined(realtime?.interval) ? realtime.interval : null,
disabled: hideAggInterval disabled: hideAggInterval
}], }],
quickInterval: [{ quickInterval: [{
value: isDefined(realtime?.quickInterval) ? realtime.quickInterval : null, value: isDefined(realtime?.quickInterval) ? realtime.quickInterval : QuickTimeInterval.CURRENT_DAY,
disabled: realtime.hideInterval || realtime.hideQuickInterval disabled: realtime?.hideInterval || realtime?.hideQuickInterval
}] }]
}), }),
history: this.fb.group({ history: this.fb.group({
historyType: [{ historyType: [{
value: isDefined(history?.historyType) ? history.historyType : HistoryWindowType.LAST_INTERVAL, value: isDefined(history?.historyType) ? history.historyType : HistoryWindowType.LAST_INTERVAL,
disabled: history.hideInterval disabled: history?.hideInterval
}], }],
timewindowMs: [{ timewindowMs: [{
value: isDefined(history?.timewindowMs) ? history.timewindowMs : null, value: isDefined(history?.timewindowMs) ? history.timewindowMs : MINUTE,
disabled: history.hideInterval || history.hideLastInterval disabled: history?.hideInterval || history?.hideLastInterval
}], }],
interval: [{ interval: [{
value:isDefined(history?.interval) ? history.interval : null, value:isDefined(history?.interval) ? history.interval : null,
@ -296,11 +298,11 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
fixedTimewindow: [{ fixedTimewindow: [{
value: isDefined(history?.fixedTimewindow) && this.timewindow.selectedTab === TimewindowType.HISTORY value: isDefined(history?.fixedTimewindow) && this.timewindow.selectedTab === TimewindowType.HISTORY
&& history.historyType === HistoryWindowType.FIXED ? history.fixedTimewindow : null, && history.historyType === HistoryWindowType.FIXED ? history.fixedTimewindow : null,
disabled: history.hideInterval || history.hideFixedInterval disabled: history?.hideInterval || history?.hideFixedInterval
}], }],
quickInterval: [{ quickInterval: [{
value: isDefined(history?.quickInterval) ? history.quickInterval : null, value: isDefined(history?.quickInterval) ? history.quickInterval : QuickTimeInterval.CURRENT_DAY,
disabled: history.hideInterval || history.hideQuickInterval disabled: history?.hideInterval || history?.hideQuickInterval
}] }]
}), }),
aggregation: this.fb.group({ aggregation: this.fb.group({
@ -380,6 +382,7 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
takeUntil(this.destroy$) takeUntil(this.destroy$)
).subscribe(() => { ).subscribe(() => {
this.prepareTimewindowConfig(); this.prepareTimewindowConfig();
this.clearTimewindowConfig();
this.changeTimewindow.emit(this.timewindow); this.changeTimewindow.emit(this.timewindow);
}); });
} }
@ -407,6 +410,7 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
update() { update() {
this.prepareTimewindowConfig(); this.prepareTimewindowConfig();
this.clearTimewindowConfig();
this.result = this.timewindow; this.result = this.timewindow;
this.overlayRef?.dispose(); this.overlayRef?.dispose();
} }
@ -414,21 +418,25 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
private prepareTimewindowConfig() { private prepareTimewindowConfig() {
const timewindowFormValue = this.timewindowForm.getRawValue(); const timewindowFormValue = this.timewindowForm.getRawValue();
this.timewindow.selectedTab = timewindowFormValue.selectedTab; this.timewindow.selectedTab = timewindowFormValue.selectedTab;
if (this.timewindow.selectedTab === TimewindowType.REALTIME) {
this.timewindow.realtime = {...this.timewindow.realtime, ...{ this.timewindow.realtime = {...this.timewindow.realtime, ...{
realtimeType: timewindowFormValue.realtime.realtimeType, realtimeType: timewindowFormValue.realtime.realtimeType,
timewindowMs: timewindowFormValue.realtime.timewindowMs, timewindowMs: timewindowFormValue.realtime.timewindowMs,
quickInterval: timewindowFormValue.realtime.quickInterval, quickInterval: timewindowFormValue.realtime.quickInterval,
interval: timewindowFormValue.realtime.interval
}}; }};
} else {
this.timewindow.history = {...this.timewindow.history, ...{ this.timewindow.history = {...this.timewindow.history, ...{
historyType: timewindowFormValue.history.historyType, historyType: timewindowFormValue.history.historyType,
timewindowMs: timewindowFormValue.history.timewindowMs, timewindowMs: timewindowFormValue.history.timewindowMs,
interval: timewindowFormValue.history.interval,
fixedTimewindow: timewindowFormValue.history.fixedTimewindow, fixedTimewindow: timewindowFormValue.history.fixedTimewindow,
quickInterval: timewindowFormValue.history.quickInterval, quickInterval: timewindowFormValue.history.quickInterval,
}}; }};
}
if (this.aggregation) { if (this.aggregation) {
this.timewindow.realtime.interval = timewindowFormValue.realtime.interval;
this.timewindow.history.interval = timewindowFormValue.history.interval;
this.timewindow.aggregation = { this.timewindow.aggregation = {
type: timewindowFormValue.aggregation.type, type: timewindowFormValue.aggregation.type,
limit: timewindowFormValue.aggregation.limit limit: timewindowFormValue.aggregation.limit
@ -439,6 +447,10 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
} }
} }
private clearTimewindowConfig() {
clearTimewindowConfig(this.timewindow, this.quickIntervalOnly, this.historyOnly, this.aggregation, this.timezone);
}
private updateTimewindowForm() { private updateTimewindowForm() {
this.timewindowForm.patchValue(this.timewindow, {emitEvent: false}); this.timewindowForm.patchValue(this.timewindow, {emitEvent: false});
this.updateValidators(this.timewindowForm.get('aggregation.type').value); this.updateValidators(this.timewindowForm.get('aggregation.type').value);
@ -568,12 +580,12 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
} }
private updateTimewindowAdvancedParams() { private updateTimewindowAdvancedParams() {
this.realtimeDisableCustomInterval = this.timewindow.realtime.disableCustomInterval; this.realtimeDisableCustomInterval = this.timewindow.realtime?.disableCustomInterval;
this.realtimeDisableCustomGroupInterval = this.timewindow.realtime.disableCustomGroupInterval; this.realtimeDisableCustomGroupInterval = this.timewindow.realtime?.disableCustomGroupInterval;
this.historyDisableCustomInterval = this.timewindow.history.disableCustomInterval; this.historyDisableCustomInterval = this.timewindow.history?.disableCustomInterval;
this.historyDisableCustomGroupInterval = this.timewindow.history.disableCustomGroupInterval; this.historyDisableCustomGroupInterval = this.timewindow.history?.disableCustomGroupInterval;
if (this.timewindow.realtime.advancedParams) { if (this.timewindow.realtime?.advancedParams) {
this.realtimeAdvancedParams = this.timewindow.realtime.advancedParams; this.realtimeAdvancedParams = this.timewindow.realtime.advancedParams;
this.realtimeAllowedLastIntervals = this.timewindow.realtime.advancedParams.allowedLastIntervals; this.realtimeAllowedLastIntervals = this.timewindow.realtime.advancedParams.allowedLastIntervals;
this.realtimeAllowedQuickIntervals = this.timewindow.realtime.advancedParams.allowedQuickIntervals; this.realtimeAllowedQuickIntervals = this.timewindow.realtime.advancedParams.allowedQuickIntervals;
@ -582,7 +594,7 @@ export class TimewindowPanelComponent extends PageComponent implements OnInit, O
this.realtimeAllowedLastIntervals = null; this.realtimeAllowedLastIntervals = null;
this.realtimeAllowedQuickIntervals = null; this.realtimeAllowedQuickIntervals = null;
} }
if (this.timewindow.history.advancedParams) { if (this.timewindow.history?.advancedParams) {
this.historyAdvancedParams = this.timewindow.history.advancedParams; this.historyAdvancedParams = this.timewindow.history.advancedParams;
this.historyAllowedLastIntervals = this.timewindow.history.advancedParams.allowedLastIntervals; this.historyAllowedLastIntervals = this.timewindow.history.advancedParams.allowedLastIntervals;
this.historyAllowedQuickIntervals = this.timewindow.history.advancedParams.allowedQuickIntervals; this.historyAllowedQuickIntervals = this.timewindow.history.advancedParams.allowedQuickIntervals;

View File

@ -319,7 +319,8 @@ export class TimewindowComponent implements ControlValueAccessor, OnInit, OnChan
} }
writeValue(obj: Timewindow): void { writeValue(obj: Timewindow): void {
this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.historyOnly, this.timeService); this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.historyOnly, this.timeService,
this.aggregation);
this.timewindowDisabled = this.isTimewindowDisabled(); this.timewindowDisabled = this.isTimewindowDisabled();
if (this.onHistoryOnlyChanged()) { if (this.onHistoryOnlyChanged()) {
setTimeout(() => { setTimeout(() => {

View File

@ -15,11 +15,12 @@
/// ///
import { TimeService } from '@core/services/time.service'; import { TimeService } from '@core/services/time.service';
import { deepClone, isDefined, isDefinedAndNotNull, isNumeric, isUndefined } from '@app/core/utils'; import { deepClone, isDefined, isDefinedAndNotNull, isNumeric, isUndefined, isUndefinedOrNull } from '@app/core/utils';
import moment_ from 'moment'; import moment_ from 'moment';
import * as momentTz from 'moment-timezone'; import * as momentTz from 'moment-timezone';
import { IntervalType } from '@shared/models/telemetry/telemetry.models'; import { IntervalType } from '@shared/models/telemetry/telemetry.models';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { isEmpty } from 'lodash';
const moment = moment_; const moment = moment_;
@ -314,7 +315,7 @@ const getTimewindowType = (timewindow: Timewindow): TimewindowType => {
}; };
export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean, export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean,
historyOnly: boolean, timeService: TimeService): Timewindow => { historyOnly: boolean, timeService: TimeService, hasAggregation: boolean): Timewindow => {
const model = defaultTimewindow(timeService); const model = defaultTimewindow(timeService);
if (value) { if (value) {
if (value.allowedAggTypes?.length) { if (value.allowedAggTypes?.length) {
@ -446,14 +447,17 @@ export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalO
} }
model.aggregation.limit = value.aggregation.limit || Math.floor(timeService.getMaxDatapointsLimit() / 2); model.aggregation.limit = value.aggregation.limit || Math.floor(timeService.getMaxDatapointsLimit() / 2);
} }
if (value.timezone) {
model.timezone = value.timezone; model.timezone = value.timezone;
} }
}
if (quickIntervalOnly) { if (quickIntervalOnly) {
model.realtime.realtimeType = RealtimeWindowType.INTERVAL; model.realtime.realtimeType = RealtimeWindowType.INTERVAL;
} }
if (historyOnly) { if (historyOnly) {
model.selectedTab = TimewindowType.HISTORY; model.selectedTab = TimewindowType.HISTORY;
} }
clearTimewindowConfig(model, quickIntervalOnly, historyOnly, hasAggregation);
return model; return model;
}; };
@ -1106,13 +1110,82 @@ export const cloneSelectedTimewindow = (timewindow: Timewindow): Timewindow => {
if (isDefined(timewindow.selectedTab)) { if (isDefined(timewindow.selectedTab)) {
cloned.selectedTab = timewindow.selectedTab; cloned.selectedTab = timewindow.selectedTab;
} }
if (isDefined(timewindow.realtime)) {
cloned.realtime = deepClone(timewindow.realtime); cloned.realtime = deepClone(timewindow.realtime);
}
if (isDefined(timewindow.history)) {
cloned.history = deepClone(timewindow.history); cloned.history = deepClone(timewindow.history);
}
if (isDefined(timewindow.aggregation)) {
cloned.aggregation = deepClone(timewindow.aggregation); cloned.aggregation = deepClone(timewindow.aggregation);
}
if (timewindow.timezone) {
cloned.timezone = timewindow.timezone; cloned.timezone = timewindow.timezone;
}
return cloned; return cloned;
}; };
export const clearTimewindowConfig = (timewindow: Timewindow, quickIntervalOnly: boolean,
historyOnly: boolean, hasAggregation: boolean, hasTimezone = true): Timewindow => {
if (timewindow.selectedTab === TimewindowType.REALTIME) {
if (quickIntervalOnly || timewindow.realtime.realtimeType === RealtimeWindowType.INTERVAL) {
delete timewindow.realtime.timewindowMs;
} else {
delete timewindow.realtime.quickInterval;
}
delete timewindow.history.historyType;
delete timewindow.history.timewindowMs;
delete timewindow.history.fixedTimewindow;
delete timewindow.history.quickInterval;
delete timewindow.history.interval;
if (!hasAggregation) {
delete timewindow.realtime.interval;
}
} else {
if (timewindow.history.historyType === HistoryWindowType.LAST_INTERVAL) {
delete timewindow.history.fixedTimewindow;
delete timewindow.history.quickInterval;
} else if (timewindow.history.historyType === HistoryWindowType.FIXED) {
delete timewindow.history.timewindowMs;
delete timewindow.history.quickInterval;
} else if (timewindow.history.historyType === HistoryWindowType.INTERVAL) {
delete timewindow.history.timewindowMs;
delete timewindow.history.fixedTimewindow;
} else {
delete timewindow.history.timewindowMs;
delete timewindow.history.fixedTimewindow;
delete timewindow.history.quickInterval;
}
delete timewindow.realtime.realtimeType;
delete timewindow.realtime.timewindowMs;
delete timewindow.realtime.quickInterval;
delete timewindow.realtime.interval;
if (!hasAggregation) {
delete timewindow.history.interval;
}
}
if (!hasAggregation) {
delete timewindow.aggregation;
}
if (isEmpty(timewindow.history)) {
delete timewindow.history;
}
if (historyOnly || isEmpty(timewindow.realtime)) {
delete timewindow.realtime;
}
if (!hasTimezone || isUndefinedOrNull(timewindow.timezone)) {
delete timewindow.timezone;
}
return timewindow;
};
export interface TimeInterval { export interface TimeInterval {
name: string; name: string;
translateParams: {[key: string]: any}; translateParams: {[key: string]: any};