@esri/solution-simple-types 4.1.2 → 5.0.1

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.
Files changed (69) hide show
  1. package/dist/cjs/dashboard.d.ts +93 -93
  2. package/dist/cjs/dashboard.js +352 -352
  3. package/dist/cjs/helpers/convert-item-to-template.d.ts +46 -46
  4. package/dist/cjs/helpers/convert-item-to-template.js +235 -209
  5. package/dist/cjs/helpers/convert-item-to-template.js.map +1 -1
  6. package/dist/cjs/helpers/create-item-from-template.d.ts +17 -17
  7. package/dist/cjs/helpers/create-item-from-template.js +153 -138
  8. package/dist/cjs/helpers/create-item-from-template.js.map +1 -1
  9. package/dist/cjs/helpers/notebook-helpers.d.ts +19 -19
  10. package/dist/cjs/helpers/notebook-helpers.js +24 -24
  11. package/dist/cjs/helpers/quickcapture-helpers.d.ts +18 -18
  12. package/dist/cjs/helpers/quickcapture-helpers.js +22 -22
  13. package/dist/cjs/helpers/simple-type-helpers.d.ts +18 -18
  14. package/dist/cjs/helpers/simple-type-helpers.js +22 -22
  15. package/dist/cjs/helpers/update-notebook-data.d.ts +17 -17
  16. package/dist/cjs/helpers/update-notebook-data.js +27 -27
  17. package/dist/cjs/index.d.ts +27 -27
  18. package/dist/cjs/index.js +36 -36
  19. package/dist/cjs/notebook.d.ts +66 -66
  20. package/dist/cjs/notebook.js +133 -133
  21. package/dist/cjs/oic.d.ts +53 -53
  22. package/dist/cjs/oic.js +170 -170
  23. package/dist/cjs/quickcapture.d.ts +76 -87
  24. package/dist/cjs/quickcapture.js +143 -192
  25. package/dist/cjs/quickcapture.js.map +1 -1
  26. package/dist/cjs/simple-types.d.ts +57 -57
  27. package/dist/cjs/simple-types.js +94 -94
  28. package/dist/cjs/webmap.d.ts +102 -102
  29. package/dist/cjs/webmap.js +325 -325
  30. package/dist/cjs/webmappingapplication.d.ts +176 -176
  31. package/dist/cjs/webmappingapplication.js +674 -674
  32. package/dist/cjs/webmappingapplication.js.map +1 -1
  33. package/dist/cjs/workforce.d.ts +34 -34
  34. package/dist/cjs/workforce.js +44 -44
  35. package/dist/esm/dashboard.d.ts +93 -93
  36. package/dist/esm/dashboard.js +339 -339
  37. package/dist/esm/helpers/convert-item-to-template.d.ts +46 -46
  38. package/dist/esm/helpers/convert-item-to-template.js +228 -202
  39. package/dist/esm/helpers/convert-item-to-template.js.map +1 -1
  40. package/dist/esm/helpers/create-item-from-template.d.ts +17 -17
  41. package/dist/esm/helpers/create-item-from-template.js +148 -133
  42. package/dist/esm/helpers/create-item-from-template.js.map +1 -1
  43. package/dist/esm/helpers/notebook-helpers.d.ts +19 -19
  44. package/dist/esm/helpers/notebook-helpers.js +20 -20
  45. package/dist/esm/helpers/quickcapture-helpers.d.ts +18 -18
  46. package/dist/esm/helpers/quickcapture-helpers.js +19 -19
  47. package/dist/esm/helpers/simple-type-helpers.d.ts +18 -18
  48. package/dist/esm/helpers/simple-type-helpers.js +19 -19
  49. package/dist/esm/helpers/update-notebook-data.d.ts +17 -17
  50. package/dist/esm/helpers/update-notebook-data.js +23 -23
  51. package/dist/esm/index.d.ts +27 -27
  52. package/dist/esm/index.js +27 -27
  53. package/dist/esm/notebook.d.ts +66 -66
  54. package/dist/esm/notebook.js +123 -123
  55. package/dist/esm/oic.d.ts +53 -53
  56. package/dist/esm/oic.js +162 -162
  57. package/dist/esm/quickcapture.d.ts +76 -87
  58. package/dist/esm/quickcapture.js +131 -179
  59. package/dist/esm/quickcapture.js.map +1 -1
  60. package/dist/esm/simple-types.d.ts +57 -57
  61. package/dist/esm/simple-types.js +86 -86
  62. package/dist/esm/webmap.d.ts +102 -102
  63. package/dist/esm/webmap.js +312 -312
  64. package/dist/esm/webmappingapplication.d.ts +176 -176
  65. package/dist/esm/webmappingapplication.js +648 -648
  66. package/dist/esm/webmappingapplication.js.map +1 -1
  67. package/dist/esm/workforce.d.ts +34 -34
  68. package/dist/esm/workforce.js +38 -38
  69. package/package.json +7 -7
@@ -1,340 +1,340 @@
1
- /** @license
2
- * Copyright 2018 Esri
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import * as common from "@esri/solution-common";
17
- /**
18
- * Converts a dashboard item to a template.
19
- *
20
- * @param itemTemplate Template for the dashboard item
21
- * @param templateDictionary Hash of key details used for variable replacement
22
- * @returns templatized itemTemplate
23
- */
24
- export function convertItemToTemplate(itemTemplate, templateDictionary) {
25
- return _extractDependencies(itemTemplate, templateDictionary);
26
- }
27
- /**
28
- * Templatizes all itemIds and updates the dependency array
29
- *
30
- * @param itemTemplate Template for the dashboard item
31
- * @param templateDictionary Hash of key details used for variable replacement
32
- * @returns The updated itemTemplate
33
- * @private
34
- */
35
- export function _extractDependencies(itemTemplate, templateDictionary) {
36
- // get dependencies from any
37
- const updatePaths = [
38
- "data.desktopView.header",
39
- "data.desktopView.headerPanel.selectors",
40
- "data.desktopView.leftPanel.selectors",
41
- "data.desktopView.sidebar",
42
- "data.desktopView.urlParameters",
43
- "data.desktopView.widgets",
44
- "data.header",
45
- "data.headerPanel.selectors",
46
- "data.leftPanel.selectors",
47
- "data.mobileView.header",
48
- "data.mobileView.headerPanel.selectors",
49
- "data.mobileView.leftPanel.selectors",
50
- "data.mobileView.sidebar",
51
- "data.mobileView.urlParameters",
52
- "data.mobileView.widgets",
53
- "data.sidebar",
54
- "data.urlParameters",
55
- "data.widgets"
56
- ];
57
- updatePaths.forEach(path => {
58
- const objs = common.getProp(itemTemplate, path);
59
- if (Array.isArray(objs)) {
60
- objs.forEach(obj => {
61
- /* istanbul ignore else */
62
- if (obj.type === "mapWidget") {
63
- /* istanbul ignore else */
64
- if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {
65
- itemTemplate.dependencies.push(obj.itemId);
66
- }
67
- obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, ".itemId");
68
- }
69
- /* istanbul ignore else */
70
- if (Array.isArray(obj.datasets)) {
71
- _getDatasourceDependencies(obj, itemTemplate, templateDictionary);
72
- }
73
- });
74
- }
75
- });
76
- return itemTemplate;
77
- }
78
- /**
79
- * Templatize datasource itemIds and update the dependency array
80
- *
81
- * @param obj A widget, selector, or urlParameter that contains a datasets collection
82
- * @param itemTemplate Template for the dashboard item
83
- * @param templateDictionary Hash of key details used for variable replacement
84
- * @private
85
- */
86
- export function _getDatasourceDependencies(obj, itemTemplate, templateDictionary) {
87
- obj.datasets.forEach((dataset) => {
88
- // when the datasource has an itemId it's an external datasource except if the datasource type is "arcadeDataSource"
89
- const dataSourceType = common.getProp(dataset, "dataSource.type");
90
- if (dataSourceType !== "arcadeDataSource") {
91
- const itemId = common.getProp(dataset, "dataSource.itemId");
92
- if (itemId) {
93
- if (itemTemplate.dependencies.indexOf(itemId) < 0) {
94
- itemTemplate.dependencies.push(itemId);
95
- }
96
- const layerId = common.getProp(dataset, "dataSource.layerId");
97
- common.cacheLayerInfo(layerId?.toString(), itemId, "", templateDictionary);
98
- dataset.dataSource.itemId = common.templatizeTerm(itemId, itemId, ".itemId");
99
- }
100
- }
101
- });
102
- }
103
- /**
104
- * Templatize field references for datasources and widgets.
105
- *
106
- * @param solutionTemplate The solution item template
107
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
108
- * @returns The solutionTemplate with templatized field references
109
- */
110
- export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
111
- const updatePaths = [
112
- "data.desktopView.header",
113
- "data.desktopView.headerPanel.selectors",
114
- "data.desktopView.leftPanel.selectors",
115
- "data.desktopView.sidebar",
116
- "data.desktopView.urlParameters",
117
- "data.desktopView.widgets",
118
- "data.header",
119
- "data.headerPanel.selectors",
120
- "data.leftPanel.selectors",
121
- "data.mobileView.header",
122
- "data.mobileView.headerPanel.selectors",
123
- "data.mobileView.leftPanel.selectors",
124
- "data.mobileView.sidebar",
125
- "data.mobileView.urlParameters",
126
- "data.mobileView.widgets",
127
- "data.sidebar",
128
- "data.urlParameters",
129
- "data.widgets"
130
- ];
131
- // dashboards reference datasets from other widgets
132
- // add reference IDs to the appropriate datasourceInfos
133
- updatePaths.forEach(path => {
134
- const objs = common.getProp(solutionTemplate, path);
135
- _updateDatasourceReferences(objs, datasourceInfos);
136
- });
137
- // after we know the potential references go ahead and templatize
138
- updatePaths.forEach(path => {
139
- _templatize(solutionTemplate, path, datasourceInfos);
140
- });
141
- return solutionTemplate;
142
- }
143
- /**
144
- * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references
145
- *
146
- * @param objs Thes can be widgets, selectors, or urlParameters
147
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
148
- * @private
149
- */
150
- export function _updateDatasourceReferences(objs, datasourceInfos) {
151
- // objects can be events or widgets
152
- /* istanbul ignore else */
153
- if (objs && Array.isArray(objs)) {
154
- objs.forEach(obj => {
155
- if (Array.isArray(obj.datasets)) {
156
- obj.datasets.forEach((dataset) => {
157
- // when the datasource has an itemId it's an external datasource
158
- const itemId = common.cleanItemId(common.getProp(dataset, "dataSource.itemId"));
159
- if (itemId) {
160
- const layerId = common.cleanLayerId(common.getProp(dataset, "dataSource.layerId"));
161
- datasourceInfos.some(ds => {
162
- if (ds.itemId === itemId && ds.layerId === layerId) {
163
- _updateReferences(ds, obj.id);
164
- return true;
165
- }
166
- else {
167
- return false;
168
- }
169
- });
170
- }
171
- else {
172
- // add placeholder for map layer datasource info so we can know the items that reference them
173
- // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname
174
- const id = common.getProp(dataset, "dataSource.id");
175
- if (id) {
176
- const dashboardLayerId = id.split("#")[1];
177
- datasourceInfos.some(ds => {
178
- if (ds.ids.indexOf(dashboardLayerId) > -1) {
179
- _updateReferences(ds, obj.id);
180
- return true;
181
- }
182
- else {
183
- return false;
184
- }
185
- });
186
- }
187
- }
188
- });
189
- }
190
- });
191
- }
192
- }
193
- /**
194
- * Templatize all datasets and/or events for the objects at the given path
195
- *
196
- * @param itemTemplate Template for the dashboard item
197
- * @param path A property path to an array of objects that could contain datasets or events
198
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
199
- * @private
200
- */
201
- export function _templatize(itemTemplate, path, datasourceInfos) {
202
- const obj = common.getProp(itemTemplate, path);
203
- /* istanbul ignore else */
204
- if (obj) {
205
- common.setProp(itemTemplate, path, _templatizeByDatasource(obj, datasourceInfos));
206
- }
207
- }
208
- /**
209
- * For any service dataset datasource templatize all field references
210
- *
211
- * @param objs A list of objects that can contain field references
212
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
213
- * @returns An updated list of objects with templatized field references
214
- * @private
215
- */
216
- export function _templatizeByDatasource(objs, datasourceInfos) {
217
- if (Array.isArray(objs)) {
218
- return objs.map(obj => {
219
- let _obj = obj;
220
- if (Array.isArray(_obj.events)) {
221
- // Events can be associated with datasets but they can also be associated with a target
222
- // In some cases an event will have a source and a target.
223
- // Handle these specifically first to ensure that it has the correct layer reference
224
- _obj.events = _obj.events.map((event) => {
225
- const _event = event;
226
- /* istanbul ignore else */
227
- if (Array.isArray(_event.actions)) {
228
- _event.actions = _event.actions.map((action) => {
229
- const _action = action;
230
- if (_action.fieldMap &&
231
- _action.targetId &&
232
- _action.targetId.indexOf("#") > -1) {
233
- const datasourceInfo = _getDatasourceInfo(_action, datasourceInfos);
234
- /* istanbul ignore else */
235
- if (datasourceInfo) {
236
- const fields = common.getProp(datasourceInfo, "fields");
237
- const basePath = common.getProp(datasourceInfo, "basePath");
238
- /* istanbul ignore else */
239
- if (Array.isArray(fields) && basePath) {
240
- _action.fieldMap = _action.fieldMap.map((m) => {
241
- const _m = m;
242
- _m.targetName = common.templatizeFieldReferences(_m.targetName, fields, basePath);
243
- return _m;
244
- });
245
- }
246
- }
247
- }
248
- return _action;
249
- });
250
- }
251
- return _event;
252
- });
253
- }
254
- if (Array.isArray(_obj.datasets)) {
255
- _obj.datasets = _obj.datasets.map((dataset) => {
256
- let _dataset = dataset;
257
- if (_dataset.type === "serviceDataset") {
258
- const datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);
259
- /* istanbul ignore else */
260
- if (datasourceInfo) {
261
- const fields = common.getProp(datasourceInfo, "fields");
262
- const basePath = common.getProp(datasourceInfo, "basePath");
263
- /* istanbul ignore else */
264
- if (Array.isArray(fields) && basePath) {
265
- _obj = common.templatizeFieldReferences(_obj, fields, basePath);
266
- _dataset = common.templatizeFieldReferences(_dataset, fields, basePath);
267
- }
268
- }
269
- }
270
- return _dataset;
271
- });
272
- return _obj;
273
- }
274
- else
275
- return _obj;
276
- });
277
- }
278
- else {
279
- return objs;
280
- }
281
- }
282
- /**
283
- * Find the appropriate datasource info object from the datasourceInfo collection
284
- *
285
- * @param obj Can be a Dataset or an event
286
- * @param datasourceInfos A list of objects that contain key details about the datasources from the application
287
- * @returns The supporting datasource info for the given object
288
- * @private
289
- */
290
- export function _getDatasourceInfo(obj, datasourceInfos) {
291
- let info;
292
- // the datasource will have an id property when it's referencing a map layer
293
- // the fields collection will already be defined
294
- const id = common.getProp(obj, "dataSource.id") || common.getProp(obj, "targetId");
295
- if (id) {
296
- const dashboardLayerId = id.split("#")[1];
297
- if (!datasourceInfos.some(di => {
298
- info = di.ids.indexOf(dashboardLayerId) > -1 ? di : info;
299
- return di.ids.indexOf(dashboardLayerId) > -1;
300
- })) {
301
- // in some cases the id will not contain a layer name...it will have the dashboard id for another widget
302
- // in that case lookup the datasource from referenced widget
303
- const dashboardWidgetId = id.split("#")[0];
304
- datasourceInfos.some(di => {
305
- const references = di.references || [];
306
- const hasRef = references.indexOf(dashboardWidgetId) > -1;
307
- info = hasRef ? di : info;
308
- return hasRef;
309
- });
310
- }
311
- }
312
- else {
313
- // otherwise match the itemId and the layerId to get the correct fields and path
314
- const itemId = common.cleanItemId(common.getProp(obj, "dataSource.itemId"));
315
- const layerId = common.cleanLayerId(common.getProp(obj, "dataSource.layerId"));
316
- /* istanbul ignore else */
317
- if (itemId) {
318
- datasourceInfos.some(di => {
319
- const matches = itemId === di.itemId && layerId === di.layerId;
320
- info = matches ? di : info;
321
- return matches;
322
- });
323
- }
324
- }
325
- return info;
326
- }
327
- /**
328
- * Verifies if the datasource info contains the given id and adds it if not
329
- *
330
- * @param ds The datasource info to add the reference to
331
- * @param id The id from dashboard object, commonly another widget
332
- * @private
333
- */
334
- export function _updateReferences(ds, id) {
335
- ds.references = Array.isArray(ds.references) ? ds.references : [];
336
- if (ds.references.indexOf(id) < 0) {
337
- ds.references.push(id);
338
- }
339
- }
1
+ /** @license
2
+ * Copyright 2018 Esri
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import * as common from "@esri/solution-common";
17
+ /**
18
+ * Converts a dashboard item to a template.
19
+ *
20
+ * @param itemTemplate Template for the dashboard item
21
+ * @param templateDictionary Hash of key details used for variable replacement
22
+ * @returns templatized itemTemplate
23
+ */
24
+ export function convertItemToTemplate(itemTemplate, templateDictionary) {
25
+ return _extractDependencies(itemTemplate, templateDictionary);
26
+ }
27
+ /**
28
+ * Templatizes all itemIds and updates the dependency array
29
+ *
30
+ * @param itemTemplate Template for the dashboard item
31
+ * @param templateDictionary Hash of key details used for variable replacement
32
+ * @returns The updated itemTemplate
33
+ * @private
34
+ */
35
+ export function _extractDependencies(itemTemplate, templateDictionary) {
36
+ // get dependencies from any
37
+ const updatePaths = [
38
+ "data.desktopView.header",
39
+ "data.desktopView.headerPanel.selectors",
40
+ "data.desktopView.leftPanel.selectors",
41
+ "data.desktopView.sidebar",
42
+ "data.desktopView.urlParameters",
43
+ "data.desktopView.widgets",
44
+ "data.header",
45
+ "data.headerPanel.selectors",
46
+ "data.leftPanel.selectors",
47
+ "data.mobileView.header",
48
+ "data.mobileView.headerPanel.selectors",
49
+ "data.mobileView.leftPanel.selectors",
50
+ "data.mobileView.sidebar",
51
+ "data.mobileView.urlParameters",
52
+ "data.mobileView.widgets",
53
+ "data.sidebar",
54
+ "data.urlParameters",
55
+ "data.widgets"
56
+ ];
57
+ updatePaths.forEach(path => {
58
+ const objs = common.getProp(itemTemplate, path);
59
+ if (Array.isArray(objs)) {
60
+ objs.forEach(obj => {
61
+ /* istanbul ignore else */
62
+ if (obj.type === "mapWidget") {
63
+ /* istanbul ignore else */
64
+ if (itemTemplate.dependencies.indexOf(obj.itemId) < 0) {
65
+ itemTemplate.dependencies.push(obj.itemId);
66
+ }
67
+ obj.itemId = common.templatizeTerm(obj.itemId, obj.itemId, ".itemId");
68
+ }
69
+ /* istanbul ignore else */
70
+ if (Array.isArray(obj.datasets)) {
71
+ _getDatasourceDependencies(obj, itemTemplate, templateDictionary);
72
+ }
73
+ });
74
+ }
75
+ });
76
+ return itemTemplate;
77
+ }
78
+ /**
79
+ * Templatize datasource itemIds and update the dependency array
80
+ *
81
+ * @param obj A widget, selector, or urlParameter that contains a datasets collection
82
+ * @param itemTemplate Template for the dashboard item
83
+ * @param templateDictionary Hash of key details used for variable replacement
84
+ * @private
85
+ */
86
+ export function _getDatasourceDependencies(obj, itemTemplate, templateDictionary) {
87
+ obj.datasets.forEach((dataset) => {
88
+ // when the datasource has an itemId it's an external datasource except if the datasource type is "arcadeDataSource"
89
+ const dataSourceType = common.getProp(dataset, "dataSource.type");
90
+ if (dataSourceType !== "arcadeDataSource") {
91
+ const itemId = common.getProp(dataset, "dataSource.itemId");
92
+ if (itemId) {
93
+ if (itemTemplate.dependencies.indexOf(itemId) < 0) {
94
+ itemTemplate.dependencies.push(itemId);
95
+ }
96
+ const layerId = common.getProp(dataset, "dataSource.layerId");
97
+ common.cacheLayerInfo(layerId?.toString(), itemId, "", templateDictionary);
98
+ dataset.dataSource.itemId = common.templatizeTerm(itemId, itemId, ".itemId");
99
+ }
100
+ }
101
+ });
102
+ }
103
+ /**
104
+ * Templatize field references for datasources and widgets.
105
+ *
106
+ * @param solutionTemplate The solution item template
107
+ * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
108
+ * @returns The solutionTemplate with templatized field references
109
+ */
110
+ export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
111
+ const updatePaths = [
112
+ "data.desktopView.header",
113
+ "data.desktopView.headerPanel.selectors",
114
+ "data.desktopView.leftPanel.selectors",
115
+ "data.desktopView.sidebar",
116
+ "data.desktopView.urlParameters",
117
+ "data.desktopView.widgets",
118
+ "data.header",
119
+ "data.headerPanel.selectors",
120
+ "data.leftPanel.selectors",
121
+ "data.mobileView.header",
122
+ "data.mobileView.headerPanel.selectors",
123
+ "data.mobileView.leftPanel.selectors",
124
+ "data.mobileView.sidebar",
125
+ "data.mobileView.urlParameters",
126
+ "data.mobileView.widgets",
127
+ "data.sidebar",
128
+ "data.urlParameters",
129
+ "data.widgets"
130
+ ];
131
+ // dashboards reference datasets from other widgets
132
+ // add reference IDs to the appropriate datasourceInfos
133
+ updatePaths.forEach(path => {
134
+ const objs = common.getProp(solutionTemplate, path);
135
+ _updateDatasourceReferences(objs, datasourceInfos);
136
+ });
137
+ // after we know the potential references go ahead and templatize
138
+ updatePaths.forEach(path => {
139
+ _templatize(solutionTemplate, path, datasourceInfos);
140
+ });
141
+ return solutionTemplate;
142
+ }
143
+ /**
144
+ * Add all dataset ids to the appropriate datasource info object so we can navigate any relative references
145
+ *
146
+ * @param objs Thes can be widgets, selectors, or urlParameters
147
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
148
+ * @private
149
+ */
150
+ export function _updateDatasourceReferences(objs, datasourceInfos) {
151
+ // objects can be events or widgets
152
+ /* istanbul ignore else */
153
+ if (objs && Array.isArray(objs)) {
154
+ objs.forEach(obj => {
155
+ if (Array.isArray(obj.datasets)) {
156
+ obj.datasets.forEach((dataset) => {
157
+ // when the datasource has an itemId it's an external datasource
158
+ const itemId = common.cleanItemId(common.getProp(dataset, "dataSource.itemId"));
159
+ if (itemId) {
160
+ const layerId = common.cleanLayerId(common.getProp(dataset, "dataSource.layerId"));
161
+ datasourceInfos.some(ds => {
162
+ if (ds.itemId === itemId && ds.layerId === layerId) {
163
+ _updateReferences(ds, obj.id);
164
+ return true;
165
+ }
166
+ else {
167
+ return false;
168
+ }
169
+ });
170
+ }
171
+ else {
172
+ // add placeholder for map layer datasource info so we can know the items that reference them
173
+ // needed when item field reference are derived from another widgets datasource eg. <dashboardWidgetId>#datasetname
174
+ const id = common.getProp(dataset, "dataSource.id");
175
+ if (id) {
176
+ const dashboardLayerId = id.split("#")[1];
177
+ datasourceInfos.some(ds => {
178
+ if (ds.ids.indexOf(dashboardLayerId) > -1) {
179
+ _updateReferences(ds, obj.id);
180
+ return true;
181
+ }
182
+ else {
183
+ return false;
184
+ }
185
+ });
186
+ }
187
+ }
188
+ });
189
+ }
190
+ });
191
+ }
192
+ }
193
+ /**
194
+ * Templatize all datasets and/or events for the objects at the given path
195
+ *
196
+ * @param itemTemplate Template for the dashboard item
197
+ * @param path A property path to an array of objects that could contain datasets or events
198
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
199
+ * @private
200
+ */
201
+ export function _templatize(itemTemplate, path, datasourceInfos) {
202
+ const obj = common.getProp(itemTemplate, path);
203
+ /* istanbul ignore else */
204
+ if (obj) {
205
+ common.setProp(itemTemplate, path, _templatizeByDatasource(obj, datasourceInfos));
206
+ }
207
+ }
208
+ /**
209
+ * For any service dataset datasource templatize all field references
210
+ *
211
+ * @param objs A list of objects that can contain field references
212
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
213
+ * @returns An updated list of objects with templatized field references
214
+ * @private
215
+ */
216
+ export function _templatizeByDatasource(objs, datasourceInfos) {
217
+ if (Array.isArray(objs)) {
218
+ return objs.map(obj => {
219
+ let _obj = obj;
220
+ if (Array.isArray(_obj.events)) {
221
+ // Events can be associated with datasets but they can also be associated with a target
222
+ // In some cases an event will have a source and a target.
223
+ // Handle these specifically first to ensure that it has the correct layer reference
224
+ _obj.events = _obj.events.map((event) => {
225
+ const _event = event;
226
+ /* istanbul ignore else */
227
+ if (Array.isArray(_event.actions)) {
228
+ _event.actions = _event.actions.map((action) => {
229
+ const _action = action;
230
+ if (_action.fieldMap &&
231
+ _action.targetId &&
232
+ _action.targetId.indexOf("#") > -1) {
233
+ const datasourceInfo = _getDatasourceInfo(_action, datasourceInfos);
234
+ /* istanbul ignore else */
235
+ if (datasourceInfo) {
236
+ const fields = common.getProp(datasourceInfo, "fields");
237
+ const basePath = common.getProp(datasourceInfo, "basePath");
238
+ /* istanbul ignore else */
239
+ if (Array.isArray(fields) && basePath) {
240
+ _action.fieldMap = _action.fieldMap.map((m) => {
241
+ const _m = m;
242
+ _m.targetName = common.templatizeFieldReferences(_m.targetName, fields, basePath);
243
+ return _m;
244
+ });
245
+ }
246
+ }
247
+ }
248
+ return _action;
249
+ });
250
+ }
251
+ return _event;
252
+ });
253
+ }
254
+ if (Array.isArray(_obj.datasets)) {
255
+ _obj.datasets = _obj.datasets.map((dataset) => {
256
+ let _dataset = dataset;
257
+ if (_dataset.type === "serviceDataset") {
258
+ const datasourceInfo = _getDatasourceInfo(dataset, datasourceInfos);
259
+ /* istanbul ignore else */
260
+ if (datasourceInfo) {
261
+ const fields = common.getProp(datasourceInfo, "fields");
262
+ const basePath = common.getProp(datasourceInfo, "basePath");
263
+ /* istanbul ignore else */
264
+ if (Array.isArray(fields) && basePath) {
265
+ _obj = common.templatizeFieldReferences(_obj, fields, basePath);
266
+ _dataset = common.templatizeFieldReferences(_dataset, fields, basePath);
267
+ }
268
+ }
269
+ }
270
+ return _dataset;
271
+ });
272
+ return _obj;
273
+ }
274
+ else
275
+ return _obj;
276
+ });
277
+ }
278
+ else {
279
+ return objs;
280
+ }
281
+ }
282
+ /**
283
+ * Find the appropriate datasource info object from the datasourceInfo collection
284
+ *
285
+ * @param obj Can be a Dataset or an event
286
+ * @param datasourceInfos A list of objects that contain key details about the datasources from the application
287
+ * @returns The supporting datasource info for the given object
288
+ * @private
289
+ */
290
+ export function _getDatasourceInfo(obj, datasourceInfos) {
291
+ let info;
292
+ // the datasource will have an id property when it's referencing a map layer
293
+ // the fields collection will already be defined
294
+ const id = common.getProp(obj, "dataSource.id") || common.getProp(obj, "targetId");
295
+ if (id) {
296
+ const dashboardLayerId = id.split("#")[1];
297
+ if (!datasourceInfos.some(di => {
298
+ info = di.ids.indexOf(dashboardLayerId) > -1 ? di : info;
299
+ return di.ids.indexOf(dashboardLayerId) > -1;
300
+ })) {
301
+ // in some cases the id will not contain a layer name...it will have the dashboard id for another widget
302
+ // in that case lookup the datasource from referenced widget
303
+ const dashboardWidgetId = id.split("#")[0];
304
+ datasourceInfos.some(di => {
305
+ const references = di.references || [];
306
+ const hasRef = references.indexOf(dashboardWidgetId) > -1;
307
+ info = hasRef ? di : info;
308
+ return hasRef;
309
+ });
310
+ }
311
+ }
312
+ else {
313
+ // otherwise match the itemId and the layerId to get the correct fields and path
314
+ const itemId = common.cleanItemId(common.getProp(obj, "dataSource.itemId"));
315
+ const layerId = common.cleanLayerId(common.getProp(obj, "dataSource.layerId"));
316
+ /* istanbul ignore else */
317
+ if (itemId) {
318
+ datasourceInfos.some(di => {
319
+ const matches = itemId === di.itemId && layerId === di.layerId;
320
+ info = matches ? di : info;
321
+ return matches;
322
+ });
323
+ }
324
+ }
325
+ return info;
326
+ }
327
+ /**
328
+ * Verifies if the datasource info contains the given id and adds it if not
329
+ *
330
+ * @param ds The datasource info to add the reference to
331
+ * @param id The id from dashboard object, commonly another widget
332
+ * @private
333
+ */
334
+ export function _updateReferences(ds, id) {
335
+ ds.references = Array.isArray(ds.references) ? ds.references : [];
336
+ if (ds.references.indexOf(id) < 0) {
337
+ ds.references.push(id);
338
+ }
339
+ }
340
340
  //# sourceMappingURL=dashboard.js.map