From e2b0fd6c155ffa4a2b5488d05a5d9fc518afc521 Mon Sep 17 00:00:00 2001 From: ArtemDzhereleiko Date: Fri, 8 Oct 2021 13:05:44 +0300 Subject: [PATCH] Add compleate to subject and do subscribe if display pagination turn on --- ui-ngx/src/app/core/api/widget-api.models.ts | 4 +++- .../lib/alarms-table-widget.component.ts | 9 +++++--- .../date-range-navigator.component.ts | 1 + .../lib/timeseries-table-widget.component.ts | 21 +++++++++++-------- .../home/models/dashboard-component.models.ts | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/core/api/widget-api.models.ts b/ui-ngx/src/app/core/api/widget-api.models.ts index 4f46212231..2ed130cc60 100644 --- a/ui-ngx/src/app/core/api/widget-api.models.ts +++ b/ui-ngx/src/app/core/api/widget-api.models.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Observable } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { EntityId } from '@app/shared/models/id/entity-id'; import { DataSet, @@ -277,6 +277,8 @@ export interface IWidgetSubscription { hiddenData?: Array<{data: DataSet}>; timeWindowConfig?: Timewindow; timeWindow?: WidgetTimewindow; + widgetTimewindowChanged: Observable; + widgetTimewindowChangedSubject: Subject; comparisonEnabled?: boolean; comparisonTimeWindow?: WidgetTimewindow; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts index deb3083b8f..4054041c48 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/alarms-table-widget.component.ts @@ -246,9 +246,11 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, this.updateAlarmSource(); this.ctx.updateWidgetParams(); - this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( - () => this.pageLink.page = 0 - ); + if (this.displayPagination) { + this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( + () => this.pageLink.page = 0 + ); + } } ngOnDestroy(): void { @@ -256,6 +258,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, this.widgetTimewindowChangedSubscription.unsubscribe(); this.widgetTimewindowChangedSubscription = null; } + this.ctx.defaultSubscription.widgetTimewindowChangedSubject.complete(); } ngAfterViewInit(): void { diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/date-range-navigator/date-range-navigator.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/date-range-navigator/date-range-navigator.component.ts index 526913af8d..640e09478c 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/date-range-navigator/date-range-navigator.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/date-range-navigator/date-range-navigator.component.ts @@ -119,6 +119,7 @@ export class DateRangeNavigatorWidgetComponent extends PageComponent implements this.dashboardTimewindowChangedSubscription.unsubscribe(); this.dashboardTimewindowChangedSubscription = null; } + this.ctx.dashboard.dashboardTimewindowChangedSubject.complete(); } openNavigatorPanel($event: Event) { diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts index e22c7b6f1c..5dfd47ed83 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/timeseries-table-widget.component.ts @@ -171,15 +171,17 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI this.initialize(); this.ctx.updateWidgetParams(); - this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( - () => { - this.sources.forEach((source) => { - if (this.displayPagination) { - source.pageLink.page = 0; - } - }); - } - ); + if (this.displayPagination) { + this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( + () => { + this.sources.forEach((source) => { + if (this.displayPagination) { + source.pageLink.page = 0; + } + }); + } + ); + } } ngOnDestroy(): void { @@ -187,6 +189,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI this.widgetTimewindowChangedSubscription.unsubscribe(); this.widgetTimewindowChangedSubscription = null; } + this.ctx.defaultSubscription.widgetTimewindowChangedSubject.complete(); } ngAfterViewInit(): void { diff --git a/ui-ngx/src/app/modules/home/models/dashboard-component.models.ts b/ui-ngx/src/app/modules/home/models/dashboard-component.models.ts index ffcaef06ef..3ce1779bf6 100644 --- a/ui-ngx/src/app/modules/home/models/dashboard-component.models.ts +++ b/ui-ngx/src/app/modules/home/models/dashboard-component.models.ts @@ -67,6 +67,7 @@ export interface IDashboardComponent { autofillHeight: boolean; dashboardTimewindow: Timewindow; dashboardTimewindowChanged: Observable; + dashboardTimewindowChangedSubject: Subject; aliasController: IAliasController; stateController: IStateController; onUpdateTimewindow(startTimeMs: number, endTimeMs: number, interval?: number, persist?: boolean): void;