@esri/solution-simple-types 4.1.2 → 5.0.0

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