From 4a20d153c573ae31d95df5e0cd34048933011014 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 16 May 2022 16:35:07 +0300 Subject: [PATCH] UI: Use 'Maximum entities per datasource' parameter from widget configuration instead of hardcoded value 1024 --- ui-ngx/src/app/core/api/alias-controller.ts | 10 ++++++---- ui-ngx/src/app/core/api/widget-api.models.ts | 4 +++- ui-ngx/src/app/core/api/widget-subscription.ts | 8 +++++--- ui-ngx/src/app/core/http/entity.service.ts | 6 ++++-- .../home/components/widget/lib/maps/map-widget2.ts | 8 ++++++-- .../components/widget/lib/maps/providers/image-map.ts | 1 + .../components/widget/lib/markdown-widget.component.ts | 6 ++++-- .../components/widget/widget-config.component.html | 8 ++++++++ .../home/components/widget/widget-config.component.ts | 2 ++ .../modules/home/components/widget/widget.component.ts | 3 ++- ui-ngx/src/app/shared/models/widget.models.ts | 1 + ui-ngx/src/assets/locale/locale.constant-en_US.json | 1 + 12 files changed, 43 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/core/api/alias-controller.ts b/ui-ngx/src/app/core/api/alias-controller.ts index 14a26388a5..7ad7d7c715 100644 --- a/ui-ngx/src/app/core/api/alias-controller.ts +++ b/ui-ngx/src/app/core/api/alias-controller.ts @@ -17,14 +17,15 @@ import { AliasInfo, IAliasController, StateControllerHolder, StateEntityInfo } from '@core/api/widget-api.models'; import { forkJoin, Observable, of, ReplaySubject, Subject } from 'rxjs'; import { Datasource, DatasourceType, datasourceTypeTranslationMap } from '@app/shared/models/widget.models'; -import { deepClone, isEqual } from '@core/utils'; +import { deepClone, isDefinedAndNotNull, isEqual } from '@core/utils'; import { EntityService } from '@core/http/entity.service'; import { UtilsService } from '@core/services/utils.service'; import { AliasFilterType, EntityAliases, SingleEntityFilter } from '@shared/models/alias.models'; import { EntityInfo } from '@shared/models/entity.models'; import { map, mergeMap } from 'rxjs/operators'; import { - defaultEntityDataPageLink, Filter, FilterInfo, filterInfoToKeyFilters, Filters, KeyFilter, singleEntityDataPageLink, + createDefaultEntityDataPageLink, + Filter, FilterInfo, filterInfoToKeyFilters, Filters, KeyFilter, singleEntityDataPageLink, updateDatasourceFromEntityInfo } from '@shared/models/query/query.models'; import { TranslateService } from '@ngx-translate/core'; @@ -322,7 +323,7 @@ export class AliasController implements IAliasController { ); } - resolveDatasources(datasources: Array, singleEntity?: boolean): Observable> { + resolveDatasources(datasources: Array, singleEntity?: boolean, pageSize = 1024): Observable> { if (!datasources || !datasources.length) { return of([]); } @@ -360,7 +361,8 @@ export class AliasController implements IAliasController { if (singleEntity) { datasource.pageLink = deepClone(singleEntityDataPageLink); } else if (!datasource.pageLink) { - datasource.pageLink = deepClone(defaultEntityDataPageLink); + pageSize = isDefinedAndNotNull(pageSize) && pageSize > 0 ? pageSize : 1024; + datasource.pageLink = createDefaultEntityDataPageLink(pageSize); } } }); 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 6ae258663c..6a413f4a95 100644 --- a/ui-ngx/src/app/core/api/widget-api.models.ts +++ b/ui-ngx/src/app/core/api/widget-api.models.ts @@ -119,7 +119,7 @@ export interface IAliasController { getEntityAliasId(aliasName: string): string; getInstantAliasInfo(aliasId: string): AliasInfo; resolveSingleEntityInfo(aliasId: string): Observable; - resolveDatasources(datasources: Array, singleEntity?: boolean): Observable>; + resolveDatasources(datasources: Array, singleEntity?: boolean, pageSize?: number): Observable>; resolveAlarmSource(alarmSource: Datasource): Observable; getEntityAliases(): EntityAliases; getFilters(): Filters; @@ -184,6 +184,7 @@ export interface SubscriptionInfo { deviceName?: string; deviceNamePrefix?: string; deviceIds?: Array; + pageSize?: number; } export class WidgetSubscriptionContext { @@ -242,6 +243,7 @@ export interface WidgetSubscriptionOptions { datasourcesOptional?: boolean; hasDataPageLink?: boolean; singleEntity?: boolean; + pageSize?: number; warnOnPageDataOverflow?: boolean; ignoreDataUpdateOnIntervalTick?: boolean; targetDeviceAliasIds?: Array; diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index bdbddffdcb..635e98d89c 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -97,6 +97,7 @@ export class WidgetSubscription implements IWidgetSubscription { hasDataPageLink: boolean; singleEntity: boolean; + pageSize: number; warnOnPageDataOverflow: boolean; ignoreDataUpdateOnIntervalTick: boolean; @@ -229,6 +230,7 @@ export class WidgetSubscription implements IWidgetSubscription { this.entityDataListeners = []; this.hasDataPageLink = options.hasDataPageLink; this.singleEntity = options.singleEntity; + this.pageSize = options.pageSize; this.warnOnPageDataOverflow = options.warnOnPageDataOverflow; this.ignoreDataUpdateOnIntervalTick = options.ignoreDataUpdateOnIntervalTick; this.datasourcePages = []; @@ -387,7 +389,7 @@ export class WidgetSubscription implements IWidgetSubscription { } ); } else { - this.ctx.aliasController.resolveDatasources(this.configuredDatasources, this.singleEntity).subscribe( + this.ctx.aliasController.resolveDatasources(this.configuredDatasources, this.singleEntity, this.pageSize).subscribe( (datasources) => { this.configuredDatasources = datasources; this.prepareDataSubscriptions().subscribe( @@ -1132,7 +1134,7 @@ export class WidgetSubscription implements IWidgetSubscription { } ); } else { - this.ctx.aliasController.resolveDatasources(this.configuredDatasources, this.singleEntity).subscribe( + this.ctx.aliasController.resolveDatasources(this.configuredDatasources, this.singleEntity, this.pageSize).subscribe( (datasources) => { this.configuredDatasources = datasources; this.prepareDataSubscriptions().subscribe( @@ -1271,7 +1273,7 @@ export class WidgetSubscription implements IWidgetSubscription { totalPages: pageData.totalPages }; if (datasource.type === DatasourceType.entity && - pageData.hasNext && pageLink.pageSize > 1) { + pageData.hasNext && !this.singleEntity) { if (this.warnOnPageDataOverflow) { const message = this.ctx.translate.instant('widget.data-overflow', {count: pageData.data.length, total: pageData.totalElements}); diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index b71f5a95ef..1b27367ece 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -1319,7 +1319,8 @@ export class EntityService { pageLink = deepClone(singleEntityDataPageLink); } else { nameFilter = subscriptionInfo.entityNamePrefix; - pageLink = deepClone(defaultEntityDataPageLink); + const pageSize = isDefinedAndNotNull(subscriptionInfo.pageSize) && subscriptionInfo.pageSize > 0 ? subscriptionInfo.pageSize : 1024; + pageLink = createDefaultEntityDataPageLink(pageSize); } datasource.entityFilter = { type: AliasFilterType.entityName, @@ -1333,7 +1334,8 @@ export class EntityService { entityType: subscriptionInfo.entityType, entityList: subscriptionInfo.entityIds }; - datasource.pageLink = deepClone(defaultEntityDataPageLink); + const pageSize = isDefinedAndNotNull(subscriptionInfo.pageSize) && subscriptionInfo.pageSize > 0 ? subscriptionInfo.pageSize : 1024; + datasource.pageLink = createDefaultEntityDataPageLink(pageSize); } } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts index d603848018..bccc8f394f 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts @@ -45,7 +45,7 @@ import { TranslateService } from '@ngx-translate/core'; import { UtilsService } from '@core/services/utils.service'; import { EntityDataPageLink } from '@shared/models/query/query.models'; import { providerClass } from '@home/components/widget/lib/maps/providers'; -import { isDefined, parseFunction } from '@core/utils'; +import { isDefined, isDefinedAndNotNull, parseFunction } from '@core/utils'; import L from 'leaflet'; import { forkJoin, Observable, of } from 'rxjs'; import { AttributeService } from '@core/http/attribute.service'; @@ -87,9 +87,13 @@ export class MapWidgetController implements MapWidgetInterface { this.map.saveMarkerLocation = this.setMarkerLocation.bind(this); this.map.savePolygonLocation = this.savePolygonLocation.bind(this); this.map.saveLocation = this.saveLocation.bind(this); + let pageSize = this.settings.mapPageSize; + if (isDefinedAndNotNull(this.ctx.widgetConfig.pageSize)) { + pageSize = Math.max(pageSize, this.ctx.widgetConfig.pageSize); + } this.pageLink = { page: 0, - pageSize: this.settings.mapPageSize, + pageSize, textSearch: null, dynamic: true }; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts index 411258d3af..d72c2798f4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts @@ -88,6 +88,7 @@ export class ImageMap extends LeafletMap { const imageUrlSubscriptionOptions: WidgetSubscriptionOptions = { datasources, hasDataPageLink: true, + singleEntity: true, useDashboardTimewindow: false, type: widgetType.latest, callbacks: { diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts index 54988775c3..daf2e40221 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/markdown-widget.component.ts @@ -26,7 +26,7 @@ import { fillDataPattern, flatFormattedData, formattedDataFormDatasourceData, - hashCode, + hashCode, isDefinedAndNotNull, isNotEmptyStr, parseFunction, processDataPattern, safeExecute @@ -83,9 +83,11 @@ export class MarkdownWidgetComponent extends PageComponent implements OnInit { cssParser.cssPreviewNamespace = this.markdownClass; cssParser.createStyleElement(this.markdownClass, cssString); } + const pageSize = isDefinedAndNotNull(this.ctx.widgetConfig.pageSize) && + this.ctx.widgetConfig.pageSize > 0 ? this.ctx.widgetConfig.pageSize : 16384; const pageLink: EntityDataPageLink = { page: 0, - pageSize: 16384, + pageSize, textSearch: null, dynamic: true }; diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html index b3df4de3be..b3ef13bbae 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html @@ -317,6 +317,14 @@ widget-config.data-settings +
+ + widget-config.data-page-size + + +
widget-config.units 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 20ec1d6340..db593e64f2 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 @@ -213,6 +213,7 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont widgetStyle: [null, []], widgetCss: [null, []], titleStyle: [null, []], + pageSize: [1024, [Validators.min(1), Validators.pattern(/^\d*$/)]], units: [null, []], decimals: [null, [Validators.min(0), Validators.max(15), Validators.pattern(/^\d*$/)]], noDataDisplayMessage: [null, []], @@ -420,6 +421,7 @@ export class WidgetConfigComponent extends PageComponent implements OnInit, Cont fontSize: '16px', fontWeight: 400 }, + pageSize: isDefined(config.pageSize) ? config.pageSize : 1024, units: config.units, decimals: config.decimals, noDataDisplayMessage: isDefined(config.noDataDisplayMessage) ? config.noDataDisplayMessage : '', diff --git a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts index da8fa8cbd0..11f168a3b0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/widget.component.ts @@ -977,7 +977,8 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI ignoreDataUpdateOnIntervalTick: this.typeParameters.ignoreDataUpdateOnIntervalTick, comparisonEnabled: comparisonSettings.comparisonEnabled, timeForComparison: comparisonSettings.timeForComparison, - comparisonCustomIntervalValue: comparisonSettings.comparisonCustomIntervalValue + comparisonCustomIntervalValue: comparisonSettings.comparisonCustomIntervalValue, + pageSize: this.widget.config.pageSize }; if (this.widget.type === widgetType.alarm) { options.alarmSource = deepClone(this.widget.config.alarmSource); diff --git a/ui-ngx/src/app/shared/models/widget.models.ts b/ui-ngx/src/app/shared/models/widget.models.ts index 3a7ef4426f..12167a2f18 100644 --- a/ui-ngx/src/app/shared/models/widget.models.ts +++ b/ui-ngx/src/app/shared/models/widget.models.ts @@ -554,6 +554,7 @@ export interface WidgetConfig { units?: string; decimals?: number; noDataDisplayMessage?: string; + pageSize?: number; actions?: {[actionSourceId: string]: Array}; settings?: WidgetSettings; alarmSource?: Datasource; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 904f5e2fa0..cf576aedbf 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3246,6 +3246,7 @@ "advanced-settings": "Advanced settings", "data-settings": "Data settings", "no-data-display-message": "\"No data to display\" alternative message", + "data-page-size": "Maximum entities per datasource", "settings-component-not-found": "Settings form component not found for selector '{{selector}}'" }, "widget-type": {