From 33c76828e3aa7efbcad40a1d74ddc008e74e6bb0 Mon Sep 17 00:00:00 2001 From: Ekaterina Chantsova Date: Thu, 27 Nov 2025 20:08:40 +0200 Subject: [PATCH] Map widgets: fix subscription for latest data when aggregation enabled for one of keys --- .../core/services/dashboard-utils.service.ts | 1 + .../basic/map/map-basic-config.component.html | 2 +- .../basic/map/map-basic-config.component.ts | 26 +++++++++++++------ .../home/components/widget/lib/maps/map.ts | 6 ++++- .../widget/widget-config.component.ts | 17 ++++++++---- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/core/services/dashboard-utils.service.ts b/ui-ngx/src/app/core/services/dashboard-utils.service.ts index b630811f93..d2a6ce6f20 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -297,6 +297,7 @@ export class DashboardUtilsService { } widgetConfig.datasources = this.validateAndUpdateDatasources(widgetConfig.datasources); if (type === widgetType.latest) { + // TODO: the following won't work for maps if (datasourcesHasAggregation(widgetConfig.datasources)) { const onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(widgetConfig.datasources); widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/map/map-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/config/basic/map/map-basic-config.component.html index d6634949e2..43bfeb73ad 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/map/map-basic-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/map/map-basic-config.component.html @@ -16,7 +16,7 @@ --> - + , protected widgetConfigComponent: WidgetConfigComponent, private $injector: Injector, @@ -106,15 +107,11 @@ export class MapBasicConfigComponent extends BasicWidgetConfigComponent { actions: [configData.config.actions || {}, []] }); - if (this.trip) { - this.mapWidgetConfigForm.addControl('timewindowConfig', this.fb.control(getTimewindowConfig(configData.config))) - } + this.mapWidgetConfigForm.addControl('timewindowConfig', this.fb.control(getTimewindowConfig(configData.config))); } protected prepareOutputConfig(config: any): WidgetConfigComponentData { - if (this.trip) { - setTimewindowConfig(this.widgetConfig.config, config.timewindowConfig); - } + setTimewindowConfig(this.widgetConfig.config, config.timewindowConfig); this.widgetConfig.config.settings = config.mapSettings || {}; this.widgetConfig.config.showTitle = config.showTitle; @@ -186,4 +183,17 @@ export class MapBasicConfigComponent extends BasicWidgetConfigComponent { config.enableFullscreen = buttons.includes('fullscreen'); } + public get displayTimewindowConfig(): boolean { + if (this.trip) { + return true; + } else { + const widgetDefinition = findWidgetModelDefinition(this.widget); + if (widgetDefinition) { + return widgetDefinition.hasTimewindow(this.widget); + } else { + return false; + } + } + } + } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts index 68bbff277d..5a37643fe4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts @@ -342,7 +342,8 @@ export abstract class TbMap { const dataLayersSubscriptionOptions: WidgetSubscriptionOptions = { datasources, hasDataPageLink: true, - useDashboardTimewindow: false, + useDashboardTimewindow: isDefined(this.ctx.widgetConfig.useDashboardTimewindow) + ? this.ctx.widgetConfig.useDashboardTimewindow : true, type: widgetType.latest, callbacks: { onDataUpdated: (subscription) => { @@ -354,6 +355,9 @@ export abstract class TbMap { } } }; + if (!dataLayersSubscriptionOptions.useDashboardTimewindow) { + dataLayersSubscriptionOptions.timeWindowConfig = this.ctx.widgetConfig.timewindow; + } this.ctx.subscriptionApi.createSubscription(dataLayersSubscriptionOptions, false).subscribe( (dataLayersSubscription) => { let pageSize = this.settings.mapPageSize; diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts index 5967fb4c1a..f902c7318d 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.ts @@ -38,10 +38,11 @@ import { TargetDevice, targetDeviceValid, Widget, - widgetTypeCanHaveTimewindow, WidgetConfigMode, widgetTitleAutocompleteValues, - widgetType + widgetType, + widgetTypeCanHaveTimewindow, + widgetTypeHasTimewindow } from '@shared/models/widget.models'; import { AsyncValidator, @@ -88,6 +89,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { WidgetService } from '@core/http/widget.service'; import { TimeService } from '@core/services/time.service'; import { initModelFromDefaultTimewindow } from '@shared/models/time/time.models'; +import { findWidgetModelDefinition } from '@shared/models/widget/widget-model.definition'; import Timeout = NodeJS.Timeout; @Component({ @@ -734,11 +736,16 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, OnDe } public get displayTimewindowConfig(): boolean { - if (this.widgetType === widgetType.timeseries || this.widgetType === widgetType.alarm) { + if (widgetTypeHasTimewindow(this.widgetType)) { return true; } else if (this.widgetType === widgetType.latest) { - const datasources = this.dataSettings.get('datasources').value; - return datasourcesHasAggregation(datasources); + const widgetDefinition = findWidgetModelDefinition(this.widget); + if (widgetDefinition) { + return widgetDefinition.hasTimewindow(this.widget); + } else { + const datasources = this.dataSettings.get('datasources').value; + return datasourcesHasAggregation(datasources); + } } }