Browse Source

Map widget: add methods to check if aggregation enabled for latest data keys; check if timewindow should be displayed

pull/14685/head
Ekaterina Chantsova 11 months ago
parent
commit
fd195a5f81
  1. 10
      ui-ngx/src/app/modules/home/models/dashboard-component.models.ts
  2. 6
      ui-ngx/src/app/shared/models/widget/home-widgets/api-usage-model.definition.ts
  3. 47
      ui-ngx/src/app/shared/models/widget/maps/map-model.definition.ts
  4. 2
      ui-ngx/src/app/shared/models/widget/widget-model.definition.ts

10
ui-ngx/src/app/modules/home/models/dashboard-component.models.ts

@ -43,6 +43,7 @@ import { UtilsService } from '@core/services/utils.service';
import { TbPopoverComponent } from '@shared/components/popover.component'; import { TbPopoverComponent } from '@shared/components/popover.component';
import { ComponentStyle, iconStyle, textStyle } from '@shared/models/widget-settings.models'; import { ComponentStyle, iconStyle, textStyle } from '@shared/models/widget-settings.models';
import { TbContextMenuEvent } from '@shared/models/jquery-event.models'; import { TbContextMenuEvent } from '@shared/models/jquery-event.models';
import { widgetHasTimewindow } from '@shared/models/widget/widget-model.definition';
export interface WidgetsData { export interface WidgetsData {
widgets: Array<Widget>; widgets: Array<Widget>;
@ -616,14 +617,11 @@ export class DashboardWidget implements GridsterItem, IDashboardWidget {
this.dropShadow = isDefined(this.widget.config.dropShadow) ? this.widget.config.dropShadow : true; this.dropShadow = isDefined(this.widget.config.dropShadow) ? this.widget.config.dropShadow : true;
this.enableFullscreen = isDefined(this.widget.config.enableFullscreen) ? this.widget.config.enableFullscreen : true; this.enableFullscreen = isDefined(this.widget.config.enableFullscreen) ? this.widget.config.enableFullscreen : true;
let canHaveTimewindow = false; const canHaveTimewindow = widgetHasTimewindow(this.widget);
let onlyQuickInterval = false; let onlyQuickInterval = false;
let onlyHistoryTimewindow = false; let onlyHistoryTimewindow = false;
if (this.widget.type === widgetType.timeseries || this.widget.type === widgetType.alarm) { if (this.widget.type === widgetType.latest) {
canHaveTimewindow = true; onlyQuickInterval = datasourcesHasAggregation(this.widget.config.datasources);
} else if (this.widget.type === widgetType.latest) {
canHaveTimewindow = datasourcesHasAggregation(this.widget.config.datasources);
onlyQuickInterval = canHaveTimewindow;
if (canHaveTimewindow) { if (canHaveTimewindow) {
onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(this.widget.config.datasources); onlyHistoryTimewindow = datasourcesHasOnlyComparisonAggregation(this.widget.config.datasources);
} }

6
ui-ngx/src/app/shared/models/widget/home-widgets/api-usage-model.definition.ts

@ -72,6 +72,12 @@ export const ApiUsageModelDefinition: WidgetModelDefinition<ApiUsageDatasourcesI
}, },
hasTimewindow(): boolean { hasTimewindow(): boolean {
return false; return false;
},
datasourcesHasAggregation(): boolean {
return false;
},
datasourcesHasOnlyComparisonAggregation(): boolean {
return false;
} }
}; };

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

@ -17,7 +17,13 @@
import { EntityAliases, EntityAliasInfo, getEntityAliasId } from '@shared/models/alias.models'; import { EntityAliases, EntityAliasInfo, getEntityAliasId } from '@shared/models/alias.models';
import { FilterInfo, Filters, getFilterId } from '@shared/models/query/query.models'; import { FilterInfo, Filters, getFilterId } from '@shared/models/query/query.models';
import { Dashboard } from '@shared/models/dashboard.models'; import { Dashboard } from '@shared/models/dashboard.models';
import { Datasource, datasourcesHasAggregation, DatasourceType, Widget } from '@shared/models/widget.models'; import {
Datasource,
datasourcesHasAggregation,
datasourcesHasOnlyComparisonAggregation,
DatasourceType,
Widget
} from '@shared/models/widget.models';
import { import {
additionalMapDataSourcesToDatasources, additionalMapDataSourcesToDatasources,
BaseMapSettings, BaseMapSettings,
@ -132,21 +138,17 @@ export const MapModelDefinition: WidgetModelDefinition<MapDatasourcesInfo> = {
if (settings.trips?.length) { if (settings.trips?.length) {
return true; return true;
} else { } else {
const datasources: Datasource[] = []; const datasources: Datasource[] = getMapLatestDataLayersDatasources(settings);
if (settings.markers?.length) {
datasources.push(...getMapDataLayersDatasources(settings.markers, true, 'markers'));
}
if (settings.polygons?.length) {
datasources.push(...getMapDataLayersDatasources(settings.polygons, true, 'polygons'));
}
if (settings.circles?.length) {
datasources.push(...getMapDataLayersDatasources(settings.circles, true, 'circles'));
}
if (settings.additionalDataSources?.length) {
datasources.push(...additionalMapDataSourcesToDatasources(settings.additionalDataSources));
}
return datasourcesHasAggregation(datasources); return datasourcesHasAggregation(datasources);
} }
},
datasourcesHasAggregation(widget: Widget): boolean {
const datasources: Datasource[] = getMapLatestDataLayersDatasources(widget.config.settings as BaseMapSettings);
return datasourcesHasAggregation(datasources);
},
datasourcesHasOnlyComparisonAggregation(widget: Widget): boolean {
const datasources: Datasource[] = getMapLatestDataLayersDatasources(widget.config.settings as BaseMapSettings);
return datasourcesHasOnlyComparisonAggregation(datasources);
} }
}; };
@ -252,3 +254,20 @@ const getMapDataLayersDatasources = (settings: MapDataLayerSettings[],
}); });
return datasources; return datasources;
}; };
const getMapLatestDataLayersDatasources = (settings: BaseMapSettings): Datasource[] => {
const datasources: Datasource[] = [];
if (settings.markers?.length) {
datasources.push(...getMapDataLayersDatasources(settings.markers, true, 'markers'));
}
if (settings.polygons?.length) {
datasources.push(...getMapDataLayersDatasources(settings.polygons, true, 'polygons'));
}
if (settings.circles?.length) {
datasources.push(...getMapDataLayersDatasources(settings.circles, true, 'circles'));
}
if (settings.additionalDataSources?.length) {
datasources.push(...additionalMapDataSourcesToDatasources(settings.additionalDataSources));
}
return datasources;
};

2
ui-ngx/src/app/shared/models/widget/widget-model.definition.ts

@ -33,6 +33,8 @@ export interface WidgetModelDefinition<T = any> {
updateFromExportInfo(widget: Widget, entityAliases: EntityAliases, filters: Filters, info: T): void; updateFromExportInfo(widget: Widget, entityAliases: EntityAliases, filters: Filters, info: T): void;
datasources(widget: Widget): Datasource[]; datasources(widget: Widget): Datasource[];
hasTimewindow(widget: Widget): boolean; hasTimewindow(widget: Widget): boolean;
datasourcesHasAggregation(widget: Widget): boolean;
datasourcesHasOnlyComparisonAggregation(widget: Widget): boolean;
} }
const widgetModelRegistry: WidgetModelDefinition[] = [ const widgetModelRegistry: WidgetModelDefinition[] = [

Loading…
Cancel
Save