Browse Source

Minor code fixes

pull/15549/head
Maksym Tsymbarov 1 month ago
parent
commit
af69860291
  1. 13
      ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts
  2. 14
      ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts
  3. 19
      ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts

13
ui-ngx/src/app/modules/home/components/widget/lib/alarm/alarms-table-widget.component.ts

@ -42,7 +42,6 @@ import {
hashCode,
isDefined,
isDefinedAndNotNull,
isEqual,
isNotEmptyStr,
isObject,
isUndefined
@ -81,6 +80,7 @@ import {
isValidPageStepIncrement,
noDataMessage,
prepareTableCellButtonActions,
resetPaginationOnStateChange,
RowStyleInfo,
TableCellButtonActionDescriptor,
TableWidgetDataKeySettings,
@ -333,16 +333,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
if (this.displayPagination) {
this.sort.sortChange.pipe(takeUntil(this.destroy$)).subscribe(() => this.paginator.pageIndex = 0);
let currentStateParams = deepClone(this.ctx.stateController?.getStateParams());
this.ctx.stateController?.stateChanged().pipe(
takeUntil(this.destroy$)
).subscribe(() => {
const newStateParams = this.ctx.stateController.getStateParams();
if (!isEqual(currentStateParams, newStateParams)) {
currentStateParams = deepClone(newStateParams);
this.paginator.firstPage();
}
});
resetPaginationOnStateChange(this.ctx, this.paginator, this.destroy$);
this.ctx.aliasController?.filtersChanged.pipe(
takeUntil(this.destroy$)

14
ui-ngx/src/app/modules/home/components/widget/lib/entity/entities-table-widget.component.ts

@ -42,7 +42,7 @@ import {
import { IWidgetSubscription } from '@core/api/widget-api.models';
import { UtilsService } from '@core/services/utils.service';
import { TranslateService } from '@ngx-translate/core';
import { deepClone, hashCode, isDefined, isDefinedAndNotNull, isEqual, isObject, isUndefined } from '@core/utils';
import { deepClone, hashCode, isDefined, isDefinedAndNotNull, isObject, isUndefined } from '@core/utils';
import cssjs from '@core/css/css';
import { CollectionViewer, DataSource } from '@angular/cdk/collections';
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
@ -79,6 +79,7 @@ import {
isValidPageStepIncrement,
noDataMessage,
prepareTableCellButtonActions,
resetPaginationOnStateChange,
RowStyleInfo,
TableCellButtonActionDescriptor,
TableWidgetDataKeySettings,
@ -267,16 +268,7 @@ export class EntitiesTableWidgetComponent extends PageComponent implements OnIni
if (this.displayPagination) {
this.sort.sortChange.pipe(takeUntil(this.destroy$)).subscribe(() => this.paginator.pageIndex = 0);
let currentStateParams = deepClone(this.ctx.stateController?.getStateParams());
this.ctx.stateController?.stateChanged().pipe(
takeUntil(this.destroy$)
).subscribe(() => {
const newStateParams = this.ctx.stateController.getStateParams();
if (!isEqual(currentStateParams, newStateParams)) {
currentStateParams = deepClone(newStateParams);
this.paginator.firstPage();
}
});
resetPaginationOnStateChange(this.ctx, this.paginator, this.destroy$);
this.ctx.aliasController?.filtersChanged.pipe(
takeUntil(this.destroy$)

19
ui-ngx/src/app/modules/home/components/widget/lib/table-widget.models.ts

@ -16,7 +16,7 @@
import { EntityId } from '@shared/models/id/entity-id';
import { DataKey, FormattedData, WidgetActionDescriptor, WidgetConfig } from '@shared/models/widget.models';
import { getDescendantProp, isDefined, isNotEmptyStr } from '@core/utils';
import { deepClone, getDescendantProp, isDefined, isEqual, isNotEmptyStr } from '@core/utils';
import { AlarmDataInfo, alarmFields } from '@shared/models/alarm.models';
import tinycolor from 'tinycolor2';
import { Direction } from '@shared/models/page/sort-order';
@ -32,8 +32,9 @@ import {
isNotEmptyTbFunction,
TbFunction
} from '@shared/models/js-function.models';
import { forkJoin, Observable, of, ReplaySubject } from 'rxjs';
import { catchError, map, share } from 'rxjs/operators';
import { forkJoin, Observable, of, ReplaySubject, Subject } from 'rxjs';
import { catchError, distinctUntilChanged, map, share, skip, startWith, takeUntil } from 'rxjs/operators';
import { MatPaginator } from '@angular/material/paginator';
import type { ValueFormatProcessor } from '@shared/models/widget-settings.models';
type ColumnVisibilityOptions = 'visible' | 'hidden' | 'hidden-mobile';
@ -516,3 +517,15 @@ export function isValidPageStepIncrement(value: number): boolean {
export function isValidPageStepCount(value: number): boolean {
return Number.isInteger(value) && value > 0 && value <= 100;
}
export function resetPaginationOnStateChange(ctx: WidgetContext,
paginator: MatPaginator,
destroy$: Subject<void>): void {
ctx.stateController?.stateChanged().pipe(
map(() => deepClone(ctx.stateController.getStateParams())),
startWith(deepClone(ctx.stateController?.getStateParams())),
distinctUntilChanged(isEqual),
skip(1),
takeUntil(destroy$)
).subscribe(() => paginator.firstPage());
}

Loading…
Cancel
Save