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 6c36dde958..66c376bc2a 100644 --- a/ui-ngx/src/app/core/services/dashboard-utils.service.ts +++ b/ui-ngx/src/app/core/services/dashboard-utils.service.ts @@ -30,7 +30,14 @@ import { WidgetLayout } from '@shared/models/dashboard.models'; import { isDefined, isString, isUndefined } from '@core/utils'; -import { Datasource, DatasourceType, Widget, WidgetConfig, widgetType } from '@app/shared/models/widget.models'; +import { + Datasource, + datasourcesHasOnlyComparisonAggregation, + DatasourceType, + Widget, + WidgetConfig, + widgetType +} from '@app/shared/models/widget.models'; import { EntityType } from '@shared/models/entity-type.models'; import { AliasFilterType, EntityAlias, EntityAliasFilter } from '@app/shared/models/alias.models'; import { EntityId } from '@app/shared/models/id/entity-id'; @@ -227,7 +234,8 @@ export class DashboardUtilsService { } }); if (type === widgetType.latest) { - widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, this.timeService); + const onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(widgetConfig.datasources); + widgetConfig.timewindow = initModelFromDefaultTimewindow(widgetConfig.timewindow, true, this.timeService, onlyHistoryTimewindow); } if (type === widgetType.alarm) { if (!widgetConfig.alarmFilterConfig) { @@ -421,7 +429,7 @@ export class DashboardUtilsService { targetLayout: DashboardLayoutId, widget: Widget, originalColumns?: number, - originalSize?: {sizeX: number, sizeY: number}, + originalSize?: {sizeX: number; sizeY: number}, row?: number, column?: number): void { const dashboardConfiguration = dashboard.configuration; @@ -494,7 +502,7 @@ export class DashboardUtilsService { this.removeUnusedWidgets(dashboard); } - public isSingleLayoutDashboard(dashboard: Dashboard): {state: string, layout: DashboardLayoutId} { + public isSingleLayoutDashboard(dashboard: Dashboard): {state: string; layout: DashboardLayoutId} { const dashboardConfiguration = dashboard.configuration; const states = dashboardConfiguration.states; const stateKeys = Object.keys(states); diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html index fd827c7f55..6a9ce1f657 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.html @@ -107,7 +107,6 @@ tooltipPosition="below" aggregation="true" timezone="true" - isNgModel [(ngModel)]="dashboardCtx.dashboardTimewindow"> diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-container.component.html b/ui-ngx/src/app/modules/home/components/widget/widget-container.component.html index f173b103eb..23082a121b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-container.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/widget-container.component.html @@ -50,7 +50,6 @@ historyOnly="{{widget.onlyHistoryTimewindow}}" alwaysDisplayTypePrefix timezone="true" - isNgModel [isEdit]="isEdit" [(ngModel)]="widgetComponent.widget.config.timewindow" (ngModelChange)="widgetComponent.onTimewindowChanged($event)"> diff --git a/ui-ngx/src/app/shared/components/time/timewindow.component.ts b/ui-ngx/src/app/shared/components/time/timewindow.component.ts index 933cafe0ca..777c286c1d 100644 --- a/ui-ngx/src/app/shared/components/time/timewindow.component.ts +++ b/ui-ngx/src/app/shared/components/time/timewindow.component.ts @@ -117,10 +117,6 @@ export class TimewindowComponent implements ControlValueAccessor { @coerceBoolean() strokedButton = false; - @Input() - @coerceBoolean() - isNgModel = false; - isEditValue = false; @Input() @@ -149,8 +145,6 @@ export class TimewindowComponent implements ControlValueAccessor { private propagateChange = (_: any) => {}; - private _isControlInitialized = false; - constructor(private overlay: Overlay, private translate: TranslateService, private timeService: TimeService, @@ -229,7 +223,6 @@ export class TimewindowComponent implements ControlValueAccessor { registerOnChange(fn: any): void { this.propagateChange = fn; - this._isControlInitialized = true; } registerOnTouched(fn: any): void { @@ -241,16 +234,14 @@ export class TimewindowComponent implements ControlValueAccessor { } writeValue(obj: Timewindow): void { - if (this._isControlInitialized || !this.isNgModel) { - this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.timeService); - this.timewindowDisabled = this.isTimewindowDisabled(); - if (this.onHistoryOnlyChanged()) { - setTimeout(() => { - this.notifyChanged(); - }); - } else { - this.updateDisplayValue(); - } + this.innerValue = initModelFromDefaultTimewindow(obj, this.quickIntervalOnly, this.timeService, this.historyOnly); + this.timewindowDisabled = this.isTimewindowDisabled(); + if (this.onHistoryOnlyChanged()) { + setTimeout(() => { + this.notifyChanged(); + }); + } else { + this.updateDisplayValue(); } } diff --git a/ui-ngx/src/app/shared/models/time/time.models.ts b/ui-ngx/src/app/shared/models/time/time.models.ts index 3e87150f87..68c7a12436 100644 --- a/ui-ngx/src/app/shared/models/time/time.models.ts +++ b/ui-ngx/src/app/shared/models/time/time.models.ts @@ -245,7 +245,8 @@ const getTimewindowType = (timewindow: Timewindow): TimewindowType => { } }; -export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean, timeService: TimeService): Timewindow => { +export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalOnly: boolean, + timeService: TimeService, historyOnly: boolean): Timewindow => { const model = defaultTimewindow(timeService); if (value) { model.hideInterval = value.hideInterval; @@ -316,6 +317,9 @@ export const initModelFromDefaultTimewindow = (value: Timewindow, quickIntervalO if (quickIntervalOnly) { model.realtime.realtimeType = RealtimeWindowType.INTERVAL; } + if (historyOnly) { + model.selectedTab = TimewindowType.HISTORY; + } return model; };