Commit e2e5694013a271b31c0b975ad070472afb7a1485

Authored by Igor Kulikov
Committed by GitHub
2 parents ad6d6ce4 45961519

Merge pull request #5330 from ArtemDzhereleiko/bug-fix/table/pagination

[3.3.2] UI:Fixed tables pagination after updated
... ... @@ -282,6 +282,7 @@ export interface IWidgetSubscription {
282 282 hiddenData?: Array<{data: DataSet}>;
283 283 timeWindowConfig?: Timewindow;
284 284 timeWindow?: WidgetTimewindow;
  285 + widgetTimewindowChanged$: Observable<WidgetTimewindow>;
285 286 comparisonEnabled?: boolean;
286 287 comparisonTimeWindow?: WidgetTimewindow;
287 288
... ...
... ... @@ -67,7 +67,7 @@ import {
67 67 KeyFilter,
68 68 updateDatasourceFromEntityInfo
69 69 } from '@shared/models/query/query.models';
70   -import { filter, map, switchMap, takeUntil } from 'rxjs/operators';
  70 +import { distinct, filter, map, switchMap, takeUntil } from 'rxjs/operators';
71 71 import { AlarmDataListener } from '@core/api/alarm-data.service';
72 72 import { RpcStatus } from '@shared/models/rpc.models';
73 73
... ... @@ -139,6 +139,11 @@ export class WidgetSubscription implements IWidgetSubscription {
139 139 executingSubjects: Array<Subject<any>>;
140 140
141 141 subscribed = false;
  142 + widgetTimewindowChangedSubject: Subject<WidgetTimewindow> = new ReplaySubject<WidgetTimewindow>();
  143 +
  144 + widgetTimewindowChanged$ = this.widgetTimewindowChangedSubject.asObservable().pipe(
  145 + distinct()
  146 + );
142 147
143 148 constructor(subscriptionContext: WidgetSubscriptionContext, public options: WidgetSubscriptionOptions) {
144 149 const subscriptionSubject = new ReplaySubject<IWidgetSubscription>();
... ... @@ -805,6 +810,7 @@ export class WidgetSubscription implements IWidgetSubscription {
805 810
806 811 update(isTimewindowTypeChanged = false) {
807 812 if (this.type !== widgetType.rpc) {
  813 + this.widgetTimewindowChangedSubject.next(this.timeWindowConfig);
808 814 if (this.type === widgetType.alarm) {
809 815 this.updateAlarmDataSubscription();
810 816 } else {
... ... @@ -1118,6 +1124,7 @@ export class WidgetSubscription implements IWidgetSubscription {
1118 1124
1119 1125 destroy(): void {
1120 1126 this.unsubscribe();
  1127 + this.widgetTimewindowChangedSubject.complete();
1121 1128 for (const cafId of Object.keys(this.cafs)) {
1122 1129 if (this.cafs[cafId]) {
1123 1130 this.cafs[cafId]();
... ...
... ... @@ -198,6 +198,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
198 198 attributeScopeChanged(attributeScope: TelemetryType) {
199 199 this.attributeScope = attributeScope;
200 200 this.mode = 'default';
  201 + this.paginator.pageIndex = 0;
201 202 this.updateData(true);
202 203 }
203 204
... ... @@ -447,7 +448,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
447 448 if (this.mode === 'widget') {
448 449 this.widgetsList = [];
449 450 this.widgetsListCache = [];
450   - this.widgetsCarouselIndex = 0;
  451 + this.widgetsCarouselIndex = 0;
451 452 if (widgetsBundle) {
452 453 this.widgetsLoaded = false;
453 454 const bundleAlias = widgetsBundle.alias;
... ...
... ... @@ -242,6 +242,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
242 242 if (this.breakpointObserverSubscription) {
243 243 this.breakpointObserverSubscription.unsubscribe();
244 244 }
  245 + this.dashboardTimewindowChangedSubject.complete();
245 246 this.gridster = null;
246 247 }
247 248
... ...
... ... @@ -432,6 +432,9 @@ export class EntitiesTableComponent extends PageComponent implements AfterViewIn
432 432 }
433 433
434 434 onTimewindowChange() {
  435 + if (this.displayPagination) {
  436 + this.paginator.pageIndex = 0;
  437 + }
435 438 this.updateData();
436 439 }
437 440
... ...
... ... @@ -124,6 +124,7 @@ export class RelationTableComponent extends PageComponent implements AfterViewIn
124 124 directionChanged(direction: EntitySearchDirection) {
125 125 this.direction = direction;
126 126 this.updateColumns();
  127 + this.paginator.pageIndex = 0;
127 128 this.updateData(true);
128 129 }
129 130
... ...
... ... @@ -48,7 +48,7 @@ import cssjs from '@core/css/css';
48 48 import { sortItems } from '@shared/models/page/page-link';
49 49 import { Direction } from '@shared/models/page/sort-order';
50 50 import { CollectionViewer, DataSource, SelectionModel } from '@angular/cdk/collections';
51   -import { BehaviorSubject, forkJoin, fromEvent, merge, Observable } from 'rxjs';
  51 +import { BehaviorSubject, forkJoin, fromEvent, merge, Observable, Subscription } from 'rxjs';
52 52 import { emptyPageData, PageData } from '@shared/models/page/page-data';
53 53 import { entityTypeTranslations } from '@shared/models/entity-type.models';
54 54 import { debounceTime, distinctUntilChanged, map, take, tap } from 'rxjs/operators';
... ... @@ -193,6 +193,8 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
193 193
194 194 private rowStylesInfo: RowStyleInfo;
195 195
  196 + private widgetTimewindowChanged$: Subscription;
  197 +
196 198 private searchAction: WidgetAction = {
197 199 name: 'action.search',
198 200 show: true,
... ... @@ -248,6 +250,19 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
248 250 this.initializeConfig();
249 251 this.updateAlarmSource();
250 252 this.ctx.updateWidgetParams();
  253 +
  254 + if (this.displayPagination) {
  255 + this.widgetTimewindowChanged$ = this.ctx.defaultSubscription.widgetTimewindowChanged$.subscribe(
  256 + () => this.pageLink.page = 0
  257 + );
  258 + }
  259 + }
  260 +
  261 + ngOnDestroy(): void {
  262 + if (this.widgetTimewindowChanged$) {
  263 + this.widgetTimewindowChanged$.unsubscribe();
  264 + this.widgetTimewindowChanged$ = null;
  265 + }
251 266 }
252 267
253 268 ngAfterViewInit(): void {
... ...
... ... @@ -147,6 +147,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
147 147 private rowStylesInfo: RowStyleInfo;
148 148
149 149 private subscriptions: Subscription[] = [];
  150 + private widgetTimewindowChanged$: Subscription;
150 151
151 152 private searchAction: WidgetAction = {
152 153 name: 'action.search',
... ... @@ -176,6 +177,25 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
176 177 this.datasources = this.ctx.datasources;
177 178 this.initialize();
178 179 this.ctx.updateWidgetParams();
  180 +
  181 + if (this.displayPagination) {
  182 + this.widgetTimewindowChanged$ = this.ctx.defaultSubscription.widgetTimewindowChanged$.subscribe(
  183 + () => {
  184 + this.sources.forEach((source) => {
  185 + if (this.displayPagination) {
  186 + source.pageLink.page = 0;
  187 + }
  188 + });
  189 + }
  190 + );
  191 + }
  192 + }
  193 +
  194 + ngOnDestroy(): void {
  195 + if (this.widgetTimewindowChanged$) {
  196 + this.widgetTimewindowChanged$.unsubscribe();
  197 + this.widgetTimewindowChanged$ = null;
  198 + }
179 199 }
180 200
181 201 ngAfterViewInit(): void {
... ...