Browse Source

Merge pull request #15579 from ChantsovaEkaterina/bug/map-model-definition-missing-polylines

Map widget: fix data aggregation for additional data keys and import/export widget JSON for polylines layer
pull/15589/head
Vladyslav Prykhodko 5 months ago
committed by GitHub
parent
commit
af951945e1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 120
      ui-ngx/src/app/shared/models/widget/maps/map-model.definition.ts
  2. 6
      ui-ngx/src/app/shared/models/widget/maps/map.models.ts

120
ui-ngx/src/app/shared/models/widget/maps/map-model.definition.ts

@ -27,8 +27,10 @@ import {
import { import {
additionalMapDataSourcesToDatasources, additionalMapDataSourcesToDatasources,
BaseMapSettings, BaseMapSettings,
latestMapDataLayerTypes,
MapDataLayerSettings, MapDataLayerSettings,
MapDataLayerType, MapDataLayerType,
mapDataLayerTypes,
MapDataSourceSettings, MapDataSourceSettings,
mapDataSourceSettingsToDatasource, mapDataSourceSettingsToDatasource,
MapType MapType
@ -46,30 +48,21 @@ interface MapDataLayerDsInfo extends AliasFilterPair {
type ExportDataSourceInfo = {[dataLayerIndex: number]: MapDataLayerDsInfo}; type ExportDataSourceInfo = {[dataLayerIndex: number]: MapDataLayerDsInfo};
interface MapDatasourcesInfo { type MapDatasourcesInfo = {
trips?: ExportDataSourceInfo; [K in MapDataLayerType]?: ExportDataSourceInfo;
markers?: ExportDataSourceInfo; } & {
polygons?: ExportDataSourceInfo;
circles?: ExportDataSourceInfo;
additionalDataSources?: ExportDataSourceInfo; additionalDataSources?: ExportDataSourceInfo;
} };
export const MapModelDefinition: WidgetModelDefinition<MapDatasourcesInfo> = { export const MapModelDefinition: WidgetModelDefinition<MapDatasourcesInfo> = {
testWidget(widget: Widget): boolean { testWidget(widget: Widget): boolean {
if (widget?.config?.settings) { if (widget?.config?.settings) {
const settings = widget.config.settings; const settings = widget.config.settings;
if (settings.mapType && [MapType.image, MapType.geoMap].includes(settings.mapType)) { if (settings.mapType && [MapType.image, MapType.geoMap].includes(settings.mapType)) {
if (settings.trips && Array.isArray(settings.trips)) { for (const layerType of mapDataLayerTypes) {
return true; if (Array.isArray(settings[layerType])) {
} return true;
if (settings.markers && Array.isArray(settings.markers)) { }
return true;
}
if (settings.polygons && Array.isArray(settings.polygons)) {
return true;
}
if (settings.circles && Array.isArray(settings.circles)) {
return true;
} }
} }
} }
@ -78,17 +71,11 @@ export const MapModelDefinition: WidgetModelDefinition<MapDatasourcesInfo> = {
prepareExportInfo(dashboard: Dashboard, widget: Widget): MapDatasourcesInfo { prepareExportInfo(dashboard: Dashboard, widget: Widget): MapDatasourcesInfo {
const settings: BaseMapSettings = widget.config.settings as BaseMapSettings; const settings: BaseMapSettings = widget.config.settings as BaseMapSettings;
const info: MapDatasourcesInfo = {}; const info: MapDatasourcesInfo = {};
if (settings.trips?.length) { for (const layerType of mapDataLayerTypes) {
info.trips = prepareExportDataSourcesInfo(dashboard, settings.trips); const dataLayerSettings = settings[layerType];
} if (dataLayerSettings?.length) {
if (settings.markers?.length) { info[layerType] = prepareExportDataSourcesInfo(dashboard, dataLayerSettings);
info.markers = prepareExportDataSourcesInfo(dashboard, settings.markers); }
}
if (settings.polygons?.length) {
info.polygons = prepareExportDataSourcesInfo(dashboard, settings.polygons);
}
if (settings.circles?.length) {
info.circles = prepareExportDataSourcesInfo(dashboard, settings.circles);
} }
if (settings.additionalDataSources?.length) { if (settings.additionalDataSources?.length) {
info.additionalDataSources = prepareExportDataSourcesInfo(dashboard, settings.additionalDataSources); info.additionalDataSources = prepareExportDataSourcesInfo(dashboard, settings.additionalDataSources);
@ -96,59 +83,36 @@ export const MapModelDefinition: WidgetModelDefinition<MapDatasourcesInfo> = {
return info; return info;
}, },
updateFromExportInfo(widget: Widget, entityAliases: EntityAliases, filters: Filters, info: MapDatasourcesInfo): void { updateFromExportInfo(widget: Widget, entityAliases: EntityAliases, filters: Filters, info: MapDatasourcesInfo): void {
const settings: BaseMapSettings = widget.config.settings as BaseMapSettings; if (info && Object.keys(info).length) {
if (info?.trips) { const settings: BaseMapSettings = widget.config.settings as BaseMapSettings;
updateMapDatasourceFromExportInfo(entityAliases, filters, settings.trips, info.trips); for (const layerType of mapDataLayerTypes) {
} const layerInfo = info[layerType];
if (info?.markers) { const dataLayerSettings = settings[layerType];
updateMapDatasourceFromExportInfo(entityAliases, filters, settings.markers, info.markers); if (layerInfo && dataLayerSettings) {
} updateMapDatasourceFromExportInfo(entityAliases, filters, dataLayerSettings, layerInfo);
if (info?.polygons) { }
updateMapDatasourceFromExportInfo(entityAliases, filters, settings.polygons, info.polygons); }
} if (info.additionalDataSources) {
if (info?.circles) { updateMapDatasourceFromExportInfo(entityAliases, filters, settings.additionalDataSources, info.additionalDataSources);
updateMapDatasourceFromExportInfo(entityAliases, filters, settings.circles, info.circles); }
}
if (info?.additionalDataSources) {
updateMapDatasourceFromExportInfo(entityAliases, filters, settings.additionalDataSources, info.additionalDataSources);
} }
}, },
datasources(widget: Widget): Datasource[] { datasources(widget: Widget): Datasource[] {
const settings: BaseMapSettings = widget.config.settings as BaseMapSettings; return getMapDataLayersDatasources(widget.config.settings as BaseMapSettings, mapDataLayerTypes);
const datasources: Datasource[] = [];
if (settings.trips?.length) {
datasources.push(...getMapDataLayersDatasources(settings.trips));
}
if (settings.markers?.length) {
datasources.push(...getMapDataLayersDatasources(settings.markers));
}
if (settings.polygons?.length) {
datasources.push(...getMapDataLayersDatasources(settings.polygons));
}
if (settings.circles?.length) {
datasources.push(...getMapDataLayersDatasources(settings.circles));
}
if (settings.additionalDataSources?.length) {
datasources.push(...additionalMapDataSourcesToDatasources(settings.additionalDataSources));
}
return datasources;
}, },
hasTimewindow(widget: Widget): boolean { hasTimewindow(widget: Widget): boolean {
const settings: BaseMapSettings = widget.config.settings as BaseMapSettings; const settings: BaseMapSettings = widget.config.settings as BaseMapSettings;
if (settings.trips?.length) { const timeSeriesDataLayerTypes = mapDataLayerTypes.filter(t => !latestMapDataLayerTypes.includes(t));
if (timeSeriesDataLayerTypes.some(layerType => settings[layerType]?.length)) {
return true; return true;
} else {
const datasources: Datasource[] = getMapLatestDataLayersDatasources(settings);
return datasourcesHasAggregation(datasources);
} }
return datasourcesHasAggregation(getMapDataLayersDatasources(settings, latestMapDataLayerTypes, true));
}, },
datasourcesHasAggregation(widget: Widget): boolean { datasourcesHasAggregation(widget: Widget): boolean {
const datasources: Datasource[] = getMapLatestDataLayersDatasources(widget.config.settings as BaseMapSettings); return datasourcesHasAggregation(getMapDataLayersDatasources(widget.config.settings as BaseMapSettings, latestMapDataLayerTypes, true));
return datasourcesHasAggregation(datasources);
}, },
datasourcesHasOnlyComparisonAggregation(widget: Widget): boolean { datasourcesHasOnlyComparisonAggregation(widget: Widget): boolean {
const datasources: Datasource[] = getMapLatestDataLayersDatasources(widget.config.settings as BaseMapSettings); return datasourcesHasOnlyComparisonAggregation(getMapDataLayersDatasources(widget.config.settings as BaseMapSettings, latestMapDataLayerTypes, true));
return datasourcesHasOnlyComparisonAggregation(datasources);
} }
}; };
@ -236,7 +200,7 @@ const prepareAliasAndFilterPair = (dashboard: Dashboard, settings: MapDataSource
} }
} }
const getMapDataLayersDatasources = (settings: MapDataLayerSettings[], const getMapDataLayerDatasources = (settings: MapDataLayerSettings[],
includeDataKeys = false, dataLayerType?: MapDataLayerType): Datasource[] => { includeDataKeys = false, dataLayerType?: MapDataLayerType): Datasource[] => {
const datasources: Datasource[] = []; const datasources: Datasource[] = [];
settings.forEach((dsSettings) => { settings.forEach((dsSettings) => {
@ -255,16 +219,14 @@ const getMapDataLayersDatasources = (settings: MapDataLayerSettings[],
return datasources; return datasources;
}; };
const getMapLatestDataLayersDatasources = (settings: BaseMapSettings): Datasource[] => { const getMapDataLayersDatasources = (settings: BaseMapSettings,
layerTypes: readonly MapDataLayerType[], includeDataKeys = false): Datasource[] => {
const datasources: Datasource[] = []; const datasources: Datasource[] = [];
if (settings.markers?.length) { for (const layerType of layerTypes) {
datasources.push(...getMapDataLayersDatasources(settings.markers, true, 'markers')); const dataLayerSettings = settings[layerType];
} if (dataLayerSettings?.length) {
if (settings.polygons?.length) { datasources.push(...getMapDataLayerDatasources(dataLayerSettings, includeDataKeys, layerType));
datasources.push(...getMapDataLayersDatasources(settings.polygons, true, 'polygons')); }
}
if (settings.circles?.length) {
datasources.push(...getMapDataLayersDatasources(settings.circles, true, 'circles'));
} }
if (settings.additionalDataSources?.length) { if (settings.additionalDataSources?.length) {
datasources.push(...additionalMapDataSourcesToDatasources(settings.additionalDataSources)); datasources.push(...additionalMapDataSourcesToDatasources(settings.additionalDataSources));

6
ui-ngx/src/app/shared/models/widget/maps/map.models.ts

@ -200,9 +200,11 @@ export const defaultBaseDataLayerSettings = (mapType: MapType): Partial<MapDataL
} }
}) })
export type MapDataLayerType = 'trips' | 'markers' | 'polygons' | 'circles' | 'polylines'; export const mapDataLayerTypes = ['trips', 'markers', 'polygons', 'circles', 'polylines'] as const;
export const mapDataLayerTypes: MapDataLayerType[] = ['trips', 'markers', 'polygons', 'circles', 'polylines']; export type MapDataLayerType = typeof mapDataLayerTypes[number];
export const latestMapDataLayerTypes: MapDataLayerType[] = ['markers', 'polygons', 'circles', 'polylines'];
export const mapDataLayerValid = (dataLayer: MapDataLayerSettings, type: MapDataLayerType): boolean => { export const mapDataLayerValid = (dataLayer: MapDataLayerSettings, type: MapDataLayerType): boolean => {
if (!dataLayer.dsType || ![DatasourceType.function, DatasourceType.device, DatasourceType.entity].includes(dataLayer.dsType)) { if (!dataLayer.dsType || ![DatasourceType.function, DatasourceType.device, DatasourceType.entity].includes(dataLayer.dsType)) {

Loading…
Cancel
Save