@openremote/or-dashboard-builder 1.3.0-snapshot.20250217182018 → 1.3.0-snapshot.20250218143028

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,7 +133,7 @@ export class ThresholdsPanel extends LitElement {
133
133
  <div id="thresholds-list" class="expanded-panel">
134
134
 
135
135
  <!-- Thresholds by number -->
136
- ${(this.valueType === 'number' || this.valueType === 'positiveInteger'
136
+ ${(this.valueType === 'number' || this.valueType === 'integer' || this.valueType === 'positiveInteger'
137
137
  || this.valueType === 'positiveNumber' || this.valueType === 'negativeInteger'
138
138
  || this.valueType === 'negativeNumber') ? html`
139
139
  ${(this.thresholds as [number, string][]).sort((x, y) => (x[0] < y[0]) ? -1 : 1).map((threshold, index) => {
@@ -9,7 +9,7 @@ import "../panels/assettypes-panel";
9
9
  import "../panels/thresholds-panel";
10
10
  import {LngLat} from "maplibre-gl"; // TODO: Replace this import
11
11
  import {when} from "lit/directives/when.js";
12
- import {AssetTypeSelectEvent, AssetTypesFilterConfig, AttributeNamesSelectEvent} from "../panels/assettypes-panel";
12
+ import {AssetIdsSelectEvent, AssetTypeSelectEvent, AssetAllOfTypeSwitchEvent, AssetTypesFilterConfig, AttributeNamesSelectEvent} from "../panels/assettypes-panel";
13
13
  import manager from "@openremote/core";
14
14
  import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";
15
15
  import {BoolColorsChangeEvent, ThresholdChangeEvent} from "../panels/thresholds-panel";
@@ -32,8 +32,13 @@ export class MapSettings extends AssetWidgetSettings {
32
32
  }
33
33
 
34
34
  protected render(): TemplateResult {
35
- const allowedValueTypes = ["boolean", "number", "positiveInteger", "positiveNumber", "negativeInteger", "negativeNumber", "text"];
35
+ const allowedValueTypes = ["boolean", "number", "integer", "positiveInteger", "positiveNumber", "negativeInteger", "negativeNumber", "text"];
36
36
  const config = {
37
+ assets: {
38
+ enabled: true,
39
+ multi: true,
40
+ allOfTypeOption: true
41
+ },
37
42
  attributes: {
38
43
  enabled: true,
39
44
  valueTypes: allowedValueTypes
@@ -71,7 +76,10 @@ export class MapSettings extends AssetWidgetSettings {
71
76
  <!-- Panel where Asset type and the selected attribute can be customized -->
72
77
  <settings-panel displayName="attributes" expanded="${true}">
73
78
  <assettypes-panel .assetType="${this.widgetConfig.assetType}" .attributeNames="${this.widgetConfig.attributeName}" .config="${config}"
79
+ .allOfType="${this.widgetConfig.allOfType}" .assetIds="${this.widgetConfig.assetIds}"
74
80
  @assettype-select="${(ev: AssetTypeSelectEvent) => this.onAssetTypeSelect(ev)}"
81
+ @alloftype-switch="${(ev: AssetAllOfTypeSwitchEvent) => this.onAssetAllOfTypeSwitch(ev)}"
82
+ @assetids-select="${(ev: AssetIdsSelectEvent) => this.onAssetIdsSelect(ev)}"
75
83
  @attributenames-select="${(ev: AttributeNamesSelectEvent) => this.onAttributeNameSelect(ev)}"
76
84
  ></assettypes-panel>
77
85
 
@@ -148,27 +156,50 @@ export class MapSettings extends AssetWidgetSettings {
148
156
  }
149
157
  }
150
158
 
159
+ protected onAssetAllOfTypeSwitch(ev: AssetAllOfTypeSwitchEvent) {
160
+ this.widgetConfig.allOfType = ev.detail as boolean;
161
+ this.notifyConfigUpdate();
162
+ }
163
+
164
+ protected onAssetIdsSelect(ev: AssetIdsSelectEvent) {
165
+ this.widgetConfig.assetIds = ev.detail as string[];
166
+ this.notifyConfigUpdate();
167
+ }
168
+
151
169
  protected async onAttributeNameSelect(ev: AttributeNamesSelectEvent) {
152
170
  const attrName = ev.detail as string;
153
171
  this.widgetConfig.attributeName = attrName;
154
- await manager.rest.api.AssetResource.queryAssets({
155
- realm: {
156
- name: manager.displayRealm
157
- },
158
- select: {
159
- attributes: [attrName, 'location']
160
- },
161
- types: [this.widgetConfig.assetType!],
162
- }).then(response => {
163
- this.widgetConfig.assetIds = response.data.map((a) => a.id!);
164
- this.widgetConfig.valueType = (response.data.length > 0) ? response.data[0].attributes![attrName].type : "text"; // sometimes no asset exists of that assetType, so using 'text' as fallback.
165
- }).catch((reason) => {
166
- console.error(reason);
167
- showSnackbar(undefined, "errorOccurred");
168
- });
169
-
170
- this.notifyConfigUpdate()
171
- }
172
+
173
+ const queryAssets = async (ids?: string[]) => {
174
+ try {
175
+ const response = await manager.rest.api.AssetResource.queryAssets({
176
+ realm: { name: manager.displayRealm },
177
+ select: { attributes: [attrName, 'location'] },
178
+ types: [this.widgetConfig.assetType!],
179
+ ids: ids
180
+ });
181
+ this.widgetConfig.assetIds = response.data.map((a) => a.id!);
182
+ this.widgetConfig.valueType = response.data.length ? response.data[0].attributes![attrName].type : "text";
183
+ if (!response.data[0].attributes![attrName].type) {
184
+ throw new TypeError("Data does not contain property 'attributes' or 'type'.")}
185
+ } catch (reason) {
186
+ console.error(reason);
187
+ if (reason instanceof TypeError) {
188
+ showSnackbar(undefined, "noAttributesToShow");
189
+ } else {
190
+ showSnackbar(undefined, "errorOccurred");
191
+ }
192
+ }
193
+ };
194
+
195
+ if (this.widgetConfig.allOfType) {
196
+ await queryAssets();
197
+ } else {
198
+ await queryAssets(this.widgetConfig.assetIds!);
199
+ }
200
+
201
+ this.notifyConfigUpdate();
202
+ }
172
203
 
173
204
  protected onShowLabelsToggle(ev: OrInputChangedEvent) {
174
205
  this.widgetConfig.showLabels = ev.detail.value;
@@ -3,7 +3,7 @@ import { customElement } from "lit/decorators.js";
3
3
  import {AssetWidgetSettings} from "../util/or-asset-widget";
4
4
  import {TableWidgetConfig} from "../widgets/table-widget";
5
5
  import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";
6
- import {AssetIdsSelectEvent, AssetTypeSelectEvent, AssetTypesFilterConfig, AttributeNamesSelectEvent} from "../panels/assettypes-panel";
6
+ import {AssetIdsSelectEvent, AssetTypeSelectEvent, AssetAllOfTypeSwitchEvent, AssetTypesFilterConfig, AttributeNamesSelectEvent} from "../panels/assettypes-panel";
7
7
 
8
8
  const styling = css`
9
9
  .customMwcInputContainer {
@@ -26,7 +26,8 @@ export class TableSettings extends AssetWidgetSettings {
26
26
  const config = {
27
27
  assets: {
28
28
  enabled: true,
29
- multi: true
29
+ multi: true,
30
+ allOfTypeOption: true
30
31
  },
31
32
  attributes: {
32
33
  enabled: true,
@@ -40,7 +41,9 @@ export class TableSettings extends AssetWidgetSettings {
40
41
  <div style="padding-bottom: 12px;">
41
42
  <assettypes-panel .assetType="${this.widgetConfig.assetType}" .config="${config}"
42
43
  .assetIds="${this.widgetConfig.assetIds}" .attributeNames="${this.widgetConfig.attributeNames}"
44
+ .allOfType="${this.widgetConfig.allOfType}"
43
45
  @assettype-select="${(ev: AssetTypeSelectEvent) => this.onAssetTypeSelect(ev)}"
46
+ @alloftype-switch="${(ev: AssetAllOfTypeSwitchEvent) => this.onAssetAllOfTypeSwitch(ev)}"
44
47
  @assetids-select="${(ev: AssetIdsSelectEvent) => this.onAssetIdsSelect(ev)}"
45
48
  @attributenames-select="${(ev: AttributeNamesSelectEvent) => this.onAttributesSelect(ev)}"
46
49
  ></assettypes-panel>
@@ -69,6 +72,11 @@ export class TableSettings extends AssetWidgetSettings {
69
72
  this.notifyConfigUpdate();
70
73
  }
71
74
 
75
+ protected onAssetAllOfTypeSwitch(ev: AssetAllOfTypeSwitchEvent) {
76
+ this.widgetConfig.allOfType = ev.detail as boolean;
77
+ this.notifyConfigUpdate();
78
+ }
79
+
72
80
  protected onAssetIdsSelect(ev: AssetIdsSelectEvent) {
73
81
  this.widgetConfig.assetIds = ev.detail as string[];
74
82
  this.notifyConfigUpdate();
@@ -38,6 +38,7 @@ export interface MapWidgetConfig extends WidgetConfig {
38
38
  max?: number,
39
39
  // Asset type related values
40
40
  assetType?: string,
41
+ allOfType?: boolean,
41
42
  valueType?: string,
42
43
  attributeName?: string,
43
44
  assetTypes: AssetDescriptor[],
@@ -56,6 +57,7 @@ function getDefaultWidgetConfig(): MapWidgetConfig {
56
57
  thresholds: [[0, "#4caf50"], [75, "#ff9800"], [90, "#ef5350"]],
57
58
  assetTypes: [],
58
59
  assetType: undefined,
60
+ allOfType: true,
59
61
  assetIds: [],
60
62
  attributes: [],
61
63
  } as MapWidgetConfig;
@@ -97,13 +99,39 @@ export class MapWidget extends OrAssetWidget {
97
99
  }
98
100
 
99
101
  protected async loadAssets() {
100
- if(this.widgetConfig.assetType && this.widgetConfig.attributeName) {
102
+ if(this.widgetConfig.assetType && this.widgetConfig.attributeName && this.widgetConfig.allOfType) {
101
103
  this.fetchAssetsByType([this.widgetConfig.assetType], this.widgetConfig.attributeName).then((assets) => {
102
104
  this.loadedAssets = assets;
103
105
  });
104
- }
106
+ } else if(this.widgetConfig.assetType && this.widgetConfig.attributeName && !this.widgetConfig.allOfType) {
107
+ this.fetchAssetsById([this.widgetConfig.assetType], this.widgetConfig.attributeName, this.widgetConfig.assetIds).then((assets) => {
108
+ this.loadedAssets = assets;
109
+ });
110
+ }
105
111
  }
106
112
 
113
+ protected async fetchAssetsById(assetTypes: string[], attributeName: string, assetIds: string[]) {
114
+ let assets: Asset[] = [];
115
+ await manager.rest.api.AssetResource.queryAssets({
116
+ realm: {
117
+ name:manager.displayRealm
118
+ },
119
+ select: {
120
+ attributes: [attributeName, 'location']
121
+ },
122
+ types: assetTypes,
123
+ ids: assetIds,
124
+
125
+ }).then(response => {
126
+ assets = response.data;
127
+ this.markers = {};
128
+ }).catch((reason) => {
129
+ console.error(reason);
130
+ showSnackbar(undefined, "errorOccurred");
131
+ });
132
+ return assets;
133
+ }
134
+
107
135
  protected async fetchAssetsByType(assetTypes: string[], attributeName: string) {
108
136
  let assets: Asset[] = [];
109
137
  await manager.rest.api.AssetResource.queryAssets({
@@ -13,6 +13,7 @@ import "@openremote/or-mwc-components/or-mwc-table";
13
13
 
14
14
  export interface TableWidgetConfig extends WidgetConfig {
15
15
  assetType?: string
16
+ allOfType?: boolean,
16
17
  assetIds: string[]
17
18
  attributeNames: string[],
18
19
  tableSize: number,
@@ -22,6 +23,7 @@ export interface TableWidgetConfig extends WidgetConfig {
22
23
  function getDefaultConfig(): TableWidgetConfig {
23
24
  return {
24
25
  assetType: undefined,
26
+ allOfType: true,
25
27
  assetIds: [],
26
28
  attributeNames: [],
27
29
  tableSize: 10,
@@ -80,16 +82,25 @@ export class TableWidget extends OrAssetWidget {
80
82
  /* --------------------------------------- */
81
83
 
82
84
  protected loadAssets() {
83
- if(this.widgetConfig.assetIds.find(id => !this.isAssetLoaded(id))) {
84
- this.queryAssets({
85
- ids: this.widgetConfig.assetIds,
86
- select: {
87
- attributes: this.widgetConfig.attributeNames
88
- }
89
- }).then((assets) => {
90
- this.loadedAssets = assets;
91
- })
92
- }
85
+ if(this.widgetConfig.allOfType) {
86
+ this.queryAssets({
87
+ types: [this.widgetConfig.assetType],
88
+ select: {
89
+ attributes: this.widgetConfig.attributeNames
90
+ }
91
+ }).then((assets) => {
92
+ this.loadedAssets = assets;
93
+ })
94
+ } else if(this.widgetConfig.assetIds.find(id => !this.isAssetLoaded(id))) {
95
+ this.queryAssets({
96
+ ids: this.widgetConfig.assetIds,
97
+ select: {
98
+ attributes: this.widgetConfig.attributeNames
99
+ }
100
+ }).then((assets) => {
101
+ this.loadedAssets = assets;
102
+ })
103
+ }
93
104
  }
94
105
 
95
106
  protected getColumns(attributeNames: string[]): TableColumn[] {