@esri/solution-simple-types 6.0.2-alpha.23 → 6.0.2-alpha.250423

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 (91) hide show
  1. package/package.json +3 -3
  2. package/dist/cjs/dashboard.d.ts +0 -93
  3. package/dist/cjs/dashboard.js +0 -351
  4. package/dist/cjs/dashboard.js.map +0 -1
  5. package/dist/cjs/helpers/convert-item-to-template.d.ts +0 -34
  6. package/dist/cjs/helpers/convert-item-to-template.js +0 -199
  7. package/dist/cjs/helpers/convert-item-to-template.js.map +0 -1
  8. package/dist/cjs/helpers/create-item-from-template.d.ts +0 -17
  9. package/dist/cjs/helpers/create-item-from-template.js +0 -145
  10. package/dist/cjs/helpers/create-item-from-template.js.map +0 -1
  11. package/dist/cjs/helpers/notebook-helpers.d.ts +0 -19
  12. package/dist/cjs/helpers/notebook-helpers.js +0 -25
  13. package/dist/cjs/helpers/notebook-helpers.js.map +0 -1
  14. package/dist/cjs/helpers/quickcapture-helpers.d.ts +0 -18
  15. package/dist/cjs/helpers/quickcapture-helpers.js +0 -23
  16. package/dist/cjs/helpers/quickcapture-helpers.js.map +0 -1
  17. package/dist/cjs/helpers/simple-type-helpers.d.ts +0 -18
  18. package/dist/cjs/helpers/simple-type-helpers.js +0 -23
  19. package/dist/cjs/helpers/simple-type-helpers.js.map +0 -1
  20. package/dist/cjs/helpers/update-notebook-data.d.ts +0 -17
  21. package/dist/cjs/helpers/update-notebook-data.js +0 -28
  22. package/dist/cjs/helpers/update-notebook-data.js.map +0 -1
  23. package/dist/cjs/index.d.ts +0 -27
  24. package/dist/cjs/index.js +0 -37
  25. package/dist/cjs/index.js.map +0 -1
  26. package/dist/cjs/notebook.d.ts +0 -73
  27. package/dist/cjs/notebook.js +0 -164
  28. package/dist/cjs/notebook.js.map +0 -1
  29. package/dist/cjs/oic.d.ts +0 -53
  30. package/dist/cjs/oic.js +0 -170
  31. package/dist/cjs/oic.js.map +0 -1
  32. package/dist/cjs/quickcapture.d.ts +0 -75
  33. package/dist/cjs/quickcapture.js +0 -143
  34. package/dist/cjs/quickcapture.js.map +0 -1
  35. package/dist/cjs/simple-types.d.ts +0 -56
  36. package/dist/cjs/simple-types.js +0 -94
  37. package/dist/cjs/simple-types.js.map +0 -1
  38. package/dist/cjs/webmap.d.ts +0 -102
  39. package/dist/cjs/webmap.js +0 -314
  40. package/dist/cjs/webmap.js.map +0 -1
  41. package/dist/cjs/webmappingapplication.d.ts +0 -176
  42. package/dist/cjs/webmappingapplication.js +0 -661
  43. package/dist/cjs/webmappingapplication.js.map +0 -1
  44. package/dist/cjs/workforce.d.ts +0 -34
  45. package/dist/cjs/workforce.js +0 -45
  46. package/dist/cjs/workforce.js.map +0 -1
  47. package/dist/esm/dashboard.d.ts +0 -93
  48. package/dist/esm/dashboard.js +0 -338
  49. package/dist/esm/dashboard.js.map +0 -1
  50. package/dist/esm/helpers/convert-item-to-template.d.ts +0 -34
  51. package/dist/esm/helpers/convert-item-to-template.js +0 -193
  52. package/dist/esm/helpers/convert-item-to-template.js.map +0 -1
  53. package/dist/esm/helpers/create-item-from-template.d.ts +0 -17
  54. package/dist/esm/helpers/create-item-from-template.js +0 -140
  55. package/dist/esm/helpers/create-item-from-template.js.map +0 -1
  56. package/dist/esm/helpers/notebook-helpers.d.ts +0 -19
  57. package/dist/esm/helpers/notebook-helpers.js +0 -21
  58. package/dist/esm/helpers/notebook-helpers.js.map +0 -1
  59. package/dist/esm/helpers/quickcapture-helpers.d.ts +0 -18
  60. package/dist/esm/helpers/quickcapture-helpers.js +0 -20
  61. package/dist/esm/helpers/quickcapture-helpers.js.map +0 -1
  62. package/dist/esm/helpers/simple-type-helpers.d.ts +0 -18
  63. package/dist/esm/helpers/simple-type-helpers.js +0 -20
  64. package/dist/esm/helpers/simple-type-helpers.js.map +0 -1
  65. package/dist/esm/helpers/update-notebook-data.d.ts +0 -17
  66. package/dist/esm/helpers/update-notebook-data.js +0 -24
  67. package/dist/esm/helpers/update-notebook-data.js.map +0 -1
  68. package/dist/esm/index.d.ts +0 -27
  69. package/dist/esm/index.js +0 -28
  70. package/dist/esm/index.js.map +0 -1
  71. package/dist/esm/notebook.d.ts +0 -73
  72. package/dist/esm/notebook.js +0 -153
  73. package/dist/esm/notebook.js.map +0 -1
  74. package/dist/esm/oic.d.ts +0 -53
  75. package/dist/esm/oic.js +0 -162
  76. package/dist/esm/oic.js.map +0 -1
  77. package/dist/esm/quickcapture.d.ts +0 -75
  78. package/dist/esm/quickcapture.js +0 -131
  79. package/dist/esm/quickcapture.js.map +0 -1
  80. package/dist/esm/simple-types.d.ts +0 -56
  81. package/dist/esm/simple-types.js +0 -86
  82. package/dist/esm/simple-types.js.map +0 -1
  83. package/dist/esm/webmap.d.ts +0 -102
  84. package/dist/esm/webmap.js +0 -301
  85. package/dist/esm/webmap.js.map +0 -1
  86. package/dist/esm/webmappingapplication.d.ts +0 -176
  87. package/dist/esm/webmappingapplication.js +0 -635
  88. package/dist/esm/webmappingapplication.js.map +0 -1
  89. package/dist/esm/workforce.d.ts +0 -34
  90. package/dist/esm/workforce.js +0 -39
  91. package/dist/esm/workforce.js.map +0 -1
@@ -1,661 +0,0 @@
1
- "use strict";
2
- /** @license
3
- * Copyright 2020 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._templatizeParentByWebMapLayerId = exports._templatizeParentByURL = exports._prioritizedTests = exports._getSortOrder = exports._getReplaceOrder = exports._templatizeObjectArray = exports._templatizeObject = exports.postProcessFieldReferences = exports._templatizeIdPath = exports._templatizeIdPaths = exports._getWABDependencies = exports._getGenericWebAppDependencies = exports._extractDependencies = exports.fineTuneCreatedItem = exports.setValues = exports.replaceUrl = exports.findUrls = exports.handleServiceRequests = exports.templatizeValues = exports.templatizeWidgets = exports.templatizeDatasources = exports.convertItemToTemplate = void 0;
19
- const tslib_1 = require("tslib");
20
- const common = tslib_1.__importStar(require("@esri/solution-common"));
21
- // ------------------------------------------------------------------------------------------------------------------ //
22
- /**
23
- * Converts a web mapping application item into a template.
24
- *
25
- * @param itemInfo Info about the item
26
- * @param destAuthentication Credentials for requests to the destination organization
27
- * @param srcAuthentication Credentials for requests to source items
28
- * @param templateDictionary Hash of key details used for variable replacement
29
- * @returns A promise that will resolve when the template has been created
30
- */
31
- function convertItemToTemplate(itemTemplate, destAuthentication, srcAuthentication, templateDictionary) {
32
- return new Promise((resolve, reject) => {
33
- // Remove org base URL and app id, e.g.,
34
- // http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21
35
- // to
36
- // <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}
37
- // Need to add placeholder server name because otherwise AGOL makes URL null
38
- let portalUrl = "";
39
- if (itemTemplate.item.url) {
40
- const templatizedUrl = itemTemplate.item.url;
41
- const iSep = templatizedUrl.indexOf("//");
42
- itemTemplate.item.url =
43
- common.placeholder(common.SERVER_NAME) + // add placeholder server name
44
- templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2), templatizedUrl.lastIndexOf("=") + 1) +
45
- itemTemplate.item.id; // templatized id
46
- portalUrl = templatizedUrl.replace(templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2)), "");
47
- }
48
- // Extract dependencies
49
- itemTemplate.dependencies = _extractDependencies(itemTemplate);
50
- // Set the folder
51
- common.setProp(itemTemplate, "data.folderId", "{{folderId}}");
52
- // Set the map or group after we've extracted them as dependencies
53
- _templatizeIdPaths(itemTemplate, [
54
- "data.map.itemId",
55
- "data.map.appProxy.mapItemId",
56
- "data.values.webmap",
57
- "data.values.group",
58
- ]);
59
- // force the appItemId to be pulled directly from the template item
60
- // this is to address solution.js #124
61
- _templatizeIdPath(itemTemplate, "data.appItemId", itemTemplate.itemId);
62
- setValues(itemTemplate, ["data.logo", "data.map.portalUrl", "data.portalUrl", "data.httpProxy.url"], common.placeholder(common.SERVER_NAME));
63
- common.setProp(itemTemplate, "data.geometryService", common.placeholder(common.GEOMETRY_SERVER_NAME));
64
- templatizeDatasources(itemTemplate, srcAuthentication, portalUrl, templateDictionary).then(() => {
65
- templatizeWidgets(itemTemplate, srcAuthentication, portalUrl, "data.widgetPool.widgets").then((_itemTemplate) => {
66
- templatizeWidgets(_itemTemplate, srcAuthentication, portalUrl, "data.widgetOnScreen.widgets", true).then((updatedItemTemplate) => {
67
- templatizeValues(updatedItemTemplate, srcAuthentication, portalUrl, "data.values").then((_updatedItemTemplate) => {
68
- resolve(_updatedItemTemplate);
69
- }, (e) => reject(common.fail(e)));
70
- }, (e) => reject(common.fail(e)));
71
- }, (e) => reject(common.fail(e)));
72
- }, (e) => reject(common.fail(e)));
73
- });
74
- }
75
- exports.convertItemToTemplate = convertItemToTemplate;
76
- /**
77
- * Converts web mapping application datasources to variables for deployment
78
- *
79
- * @param itemTemplate The solution item template
80
- * @param authentication Credentials for requests
81
- * @param portalUrl Rest Url of the portal to perform the search
82
- * @param templateDictionary Hash of key details used for variable replacement
83
- * @returns A promise that will resolve with the created template
84
- */
85
- function templatizeDatasources(itemTemplate, authentication, portalUrl, templateDictionary) {
86
- return new Promise((resolve, reject) => {
87
- const dataSources = common.getProp(itemTemplate, "data.dataSource.dataSources");
88
- if (dataSources && Object.keys(dataSources).length > 0) {
89
- const pendingRequests = new Array();
90
- Object.keys(dataSources).forEach((k) => {
91
- const ds = dataSources[k];
92
- common.setProp(ds, "portalUrl", common.placeholder(common.SERVER_NAME));
93
- const itemId = common.getProp(ds, "itemId");
94
- if (common.getProp(ds, "url")) {
95
- if (itemId) {
96
- const layerId = ds.url.substr(ds.url.lastIndexOf("/") + 1);
97
- common.cacheLayerInfo(layerId.toString(), itemId, ds.url, templateDictionary);
98
- ds.itemId = common.templatizeTerm(itemId, itemId, ".layer" + layerId + ".itemId");
99
- }
100
- const urlResults = findUrls(ds.url, portalUrl, [], [], authentication);
101
- pendingRequests.push(new Promise((resolveReq, rejectReq) => {
102
- handleServiceRequests(urlResults.serviceRequests, urlResults.requestUrls, urlResults.testString).then((response) => {
103
- ds.url = response;
104
- resolveReq();
105
- }, (e) => rejectReq(common.fail(e)));
106
- }));
107
- }
108
- else {
109
- if (itemId) {
110
- ds.itemId = common.templatizeTerm(itemId, itemId, ".itemId");
111
- }
112
- }
113
- });
114
- Promise.all(pendingRequests).then(() => resolve(itemTemplate), (e) => reject(common.fail(e)));
115
- }
116
- else {
117
- resolve(itemTemplate);
118
- }
119
- });
120
- }
121
- exports.templatizeDatasources = templatizeDatasources;
122
- function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen = false) {
123
- return new Promise((resolve, reject) => {
124
- // update widgets
125
- const widgets = common.getProp(itemTemplate, widgetPath) || [];
126
- let serviceRequests = [];
127
- let requestUrls = [];
128
- widgets.forEach((widget) => {
129
- /* istanbul ignore else */
130
- if (!isOnScreen && common.getProp(widget, "icon")) {
131
- setValues(widget, ["icon"], common.placeholder(common.SERVER_NAME));
132
- }
133
- const config = widget.config;
134
- if (config) {
135
- const sConfig = JSON.stringify(config);
136
- const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
137
- widget.config = JSON.parse(urlResults.testString);
138
- serviceRequests = urlResults.serviceRequests;
139
- requestUrls = urlResults.requestUrls;
140
- }
141
- });
142
- if (serviceRequests.length > 0) {
143
- const sWidgets = JSON.stringify(widgets);
144
- handleServiceRequests(serviceRequests, requestUrls, sWidgets).then((response) => {
145
- common.setProp(itemTemplate, widgetPath, JSON.parse(response));
146
- resolve(itemTemplate);
147
- }, (e) => reject(common.fail(e)));
148
- }
149
- else {
150
- resolve(itemTemplate);
151
- }
152
- });
153
- }
154
- exports.templatizeWidgets = templatizeWidgets;
155
- function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
156
- return new Promise((resolve, reject) => {
157
- // update properties of values collection for web app templates
158
- let values = common.getProp(itemTemplate, widgetPath);
159
- let serviceRequests = [];
160
- let requestUrls = [];
161
- if (values) {
162
- if (common.getProp(values, "icon")) {
163
- setValues(values, ["icon"], common.placeholder(common.SERVER_NAME));
164
- }
165
- const sConfig = JSON.stringify(values);
166
- const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
167
- values = JSON.parse(urlResults.testString);
168
- serviceRequests = urlResults.serviceRequests;
169
- requestUrls = urlResults.requestUrls;
170
- }
171
- if (serviceRequests.length > 0) {
172
- const sWidgets = JSON.stringify(values);
173
- handleServiceRequests(serviceRequests, requestUrls, sWidgets).then((response) => {
174
- common.setProp(itemTemplate, widgetPath, JSON.parse(response));
175
- resolve(itemTemplate);
176
- }, (e) => reject(common.fail(e)));
177
- }
178
- else {
179
- resolve(itemTemplate);
180
- }
181
- });
182
- }
183
- exports.templatizeValues = templatizeValues;
184
- function handleServiceRequests(serviceRequests, requestUrls, objString) {
185
- return new Promise((resolve, reject) => {
186
- if (serviceRequests && serviceRequests.length > 0) {
187
- let i = 0;
188
- Promise.all(serviceRequests).then((serviceResponses) => {
189
- serviceResponses.forEach((serviceResponse) => {
190
- if (common.getProp(serviceResponse, "serviceItemId")) {
191
- const serviceTemplate = "{{" +
192
- serviceResponse.serviceItemId +
193
- (serviceResponse.hasOwnProperty("id") ? ".layer" + serviceResponse.id : "") +
194
- ".url}}";
195
- objString = replaceUrl(objString, requestUrls[i], serviceTemplate, true);
196
- }
197
- i++;
198
- });
199
- resolve(objString);
200
- }, (e) => reject(common.fail(e)));
201
- }
202
- else {
203
- resolve(objString);
204
- }
205
- });
206
- }
207
- exports.handleServiceRequests = handleServiceRequests;
208
- function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentication) {
209
- const options = {
210
- f: "json",
211
- authentication: authentication,
212
- };
213
- // test for URLs
214
- const results = testString.match(/(\bhttps?:\/\/[-A-Z0-9/._]*)/gim);
215
- if (results && results.length) {
216
- results.forEach((url) => {
217
- if (url.indexOf("NAServer") > -1) {
218
- testString = replaceUrl(testString, url, common.placeholder(common.NA_SERVER_NAME));
219
- }
220
- else if (url.indexOf("GeocodeServer") > -1) {
221
- testString = replaceUrl(testString, url, common.placeholder(common.GEOCODE_SERVER_NAME));
222
- }
223
- else if (portalUrl && url.indexOf(portalUrl) > -1) {
224
- testString = replaceUrl(testString, portalUrl, common.placeholder(common.SERVER_NAME));
225
- }
226
- else if (url.indexOf("FeatureServer") > -1) {
227
- if (requestUrls.indexOf(url) === -1) {
228
- requestUrls.push(url);
229
- serviceRequests.push(common.request(url, options));
230
- }
231
- }
232
- });
233
- }
234
- return {
235
- testString,
236
- requestUrls,
237
- serviceRequests,
238
- };
239
- }
240
- exports.findUrls = findUrls;
241
- /**
242
- * Replace url with templatized url value
243
- *
244
- * @param obj can be a single url string or a stringified JSON object
245
- * @param url the current url we are testing for
246
- * @param newUrl the templatized url
247
- * @param validateFullUrl should only replace url when we have a full match.
248
- * This property is only relevant when the obj is a stringified JSON object.
249
- *
250
- * @returns the obj with any instances of the url replaced
251
- */
252
- function replaceUrl(obj, url, newUrl, validateFullUrl = false) {
253
- const enforceFullUrl = validateFullUrl && obj.indexOf('"') > -1;
254
- const re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
255
- return obj.replace(re, enforceFullUrl ? '"' + newUrl + '"' : newUrl);
256
- }
257
- exports.replaceUrl = replaceUrl;
258
- function setValues(itemTemplate, paths, base) {
259
- paths.forEach((path) => {
260
- const url = common.getProp(itemTemplate, path);
261
- if (url) {
262
- const subString = url.substring(url.indexOf("/", url.indexOf("//") + 2));
263
- common.setProp(itemTemplate, path, subString !== url ? base + subString : base);
264
- }
265
- });
266
- }
267
- exports.setValues = setValues;
268
- function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDictionary, destinationAuthentication) {
269
- return new Promise((resolve) => {
270
- // If this is a Web AppBuilder application, we will create a Code Attachment for downloading
271
- if (common.hasAnyKeyword(originalTemplate, ["WAB2D", "WAB3D", "Web AppBuilder"])) {
272
- // Update item so properties like appItemId can now be set now that we know the new apps ID
273
- const updateOptions = {
274
- id: newlyCreatedItem.itemId,
275
- url: newlyCreatedItem.item.url,
276
- data: newlyCreatedItem.data,
277
- };
278
- const updateDef = common.updateItem(updateOptions, destinationAuthentication);
279
- const itemInfo = {
280
- tags: originalTemplate.item.tags,
281
- title: originalTemplate.item.title,
282
- type: "Code Attachment",
283
- typeKeywords: ["Code", "Javascript", "Web Mapping Application"],
284
- relationshipType: "WMA2Code",
285
- originItemId: newlyCreatedItem.itemId,
286
- url: common.checkUrlPathTermination(common.replaceInTemplate(common.placeholder(common.SERVER_NAME), templateDictionary)) +
287
- "sharing/rest/content/items/" +
288
- newlyCreatedItem.itemId +
289
- "/package",
290
- };
291
- const createItemWithDataDef = common.createItemWithData(itemInfo, {}, destinationAuthentication, templateDictionary.folderId);
292
- Promise.all([updateDef, createItemWithDataDef]).then(() => resolve(null), () => resolve(null));
293
- }
294
- else {
295
- // Otherwise, nothing extra needed
296
- resolve(null);
297
- }
298
- });
299
- }
300
- exports.fineTuneCreatedItem = fineTuneCreatedItem;
301
- // ------------------------------------------------------------------------------------------------------------------ //
302
- /**
303
- * Gets the ids of the dependencies of an AGOL webapp item.
304
- *
305
- * @param fullItem A webapp item whose dependencies are sought
306
- * @returns A promise that will resolve with list of dependent ids
307
- * @private
308
- */
309
- function _extractDependencies(model) {
310
- let processor = _getGenericWebAppDependencies;
311
- /*
312
- if (common.hasTypeKeyword(model, "Story Map")) {
313
- processor = getStoryMapDependencies;
314
- }
315
- */
316
- if (common.hasAnyKeyword(model, ["WAB2D", "WAB3D", "Web AppBuilder"])) {
317
- processor = _getWABDependencies;
318
- }
319
- return processor(model);
320
- }
321
- exports._extractDependencies = _extractDependencies;
322
- /**
323
- * Generic Web App Dependencies
324
- *
325
- * @private
326
- */
327
- function _getGenericWebAppDependencies(model) {
328
- const props = ["data.values.webmap", "data.values.group"];
329
- return common.getProps(model, props);
330
- }
331
- exports._getGenericWebAppDependencies = _getGenericWebAppDependencies;
332
- //TODO: function doc
333
- function _getWABDependencies(model) {
334
- const deps = [];
335
- const v = common.getProp(model, "data.map.itemId");
336
- if (v) {
337
- deps.push(v);
338
- }
339
- const dataSources = common.getProp(model, "data.dataSource.dataSources");
340
- if (dataSources) {
341
- Object.keys(dataSources).forEach((k) => {
342
- const ds = dataSources[k];
343
- if (ds.itemId) {
344
- deps.push(ds.itemId);
345
- }
346
- });
347
- }
348
- return deps;
349
- }
350
- exports._getWABDependencies = _getWABDependencies;
351
- /**
352
- * Templatizes id properties for the paths provided
353
- *
354
- * @param itemTemplate The solution item template
355
- * @param paths A list of property paths that contain ids
356
- * @private
357
- */
358
- function _templatizeIdPaths(itemTemplate, paths) {
359
- paths.forEach((path) => {
360
- const id = common.getProp(itemTemplate, path);
361
- _templatizeIdPath(itemTemplate, path, id);
362
- });
363
- }
364
- exports._templatizeIdPaths = _templatizeIdPaths;
365
- /**
366
- * Templatizes id property for the path provided
367
- *
368
- * @param itemTemplate The solution item template
369
- * @param path A path to an id property
370
- * @param id The base id to use when templatizing
371
- * @private
372
- */
373
- function _templatizeIdPath(itemTemplate, path, id) {
374
- common.setProp(itemTemplate, path, common.templatizeTerm(id, id, ".itemId"));
375
- }
376
- exports._templatizeIdPath = _templatizeIdPath;
377
- /**
378
- * Templatize field references for datasources and widgets.
379
- *
380
- * @param solutionTemplate The solution item template
381
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
382
- * @returns The solutionTemplate with templatized field references
383
- */
384
- function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
385
- // handle datasources common for WAB apps
386
- const dataSources = common.getProp(solutionTemplate, "data.dataSource.dataSources");
387
- if (dataSources && Object.keys(dataSources).length > 0) {
388
- Object.keys(dataSources).forEach((k) => {
389
- const ds = dataSources[k];
390
- dataSources[k] = _templatizeObject(ds, datasourceInfos);
391
- });
392
- common.setProp(solutionTemplate, "data.dataSource.dataSources", dataSources);
393
- }
394
- // handle widgets common for WAB apps
395
- const paths = ["data.widgetPool.widgets", "data.widgetOnScreen.widgets"];
396
- paths.forEach((path) => {
397
- const widgets = common.getProp(solutionTemplate, path);
398
- if (widgets) {
399
- common.setProp(solutionTemplate, path, _templatizeObjectArray(widgets, datasourceInfos));
400
- }
401
- });
402
- // handle values common for web app templates
403
- const values = common.getProp(solutionTemplate, "data.values");
404
- if (values) {
405
- common.setProp(solutionTemplate, "data.values", _templatizeObject(values, datasourceInfos));
406
- }
407
- return solutionTemplate;
408
- }
409
- exports.postProcessFieldReferences = postProcessFieldReferences;
410
- /**
411
- * Templatize field references for given dataSource from the web application.
412
- *
413
- * @param obj The dataSource or widget object from the web application.
414
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
415
- * @returns The dataSource with templatized field references
416
- * @private
417
- */
418
- function _templatizeObject(obj, datasourceInfos, templatizeKeys = false) {
419
- obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);
420
- const replaceOrder = _getReplaceOrder(obj, datasourceInfos);
421
- replaceOrder.forEach((ds) => {
422
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
423
- });
424
- return obj;
425
- }
426
- exports._templatizeObject = _templatizeObject;
427
- /**
428
- * Templatize field references from an array of various objects from the web application.
429
- *
430
- * @param objects A list of widgets or objects from the web application that may contain field references.
431
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
432
- * @returns The widgets with templatized field references
433
- * @private
434
- */
435
- function _templatizeObjectArray(objects, datasourceInfos) {
436
- const updateKeyObjects = ["SmartEditor", "Screening"];
437
- return objects.map((obj) => {
438
- // only templatize the config and lower
439
- if (obj.config) {
440
- const templatizeKeys = updateKeyObjects.indexOf(obj.name) > -1;
441
- obj.config = _templatizeObject(obj.config, datasourceInfos, templatizeKeys);
442
- }
443
- return obj;
444
- });
445
- }
446
- exports._templatizeObjectArray = _templatizeObjectArray;
447
- /**
448
- * Gets an order for testing wit the various datasource info objects against the widget or dataSource.
449
- * A widget or dataSource that contain a layers url or webmap layer id are more likely
450
- * to have field references from that layer.
451
- *
452
- * @param obj The dataSource or widget object from the web application.
453
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
454
- * @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id
455
- * @private
456
- */
457
- function _getReplaceOrder(obj, datasourceInfos) {
458
- const objString = JSON.stringify(obj);
459
- // If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.
460
- const _datasourceInfos = datasourceInfos.filter((ds) => _getSortOrder(ds, objString) < 4);
461
- return _datasourceInfos.sort((a, b) => {
462
- return _getSortOrder(a, objString) - _getSortOrder(b, objString);
463
- });
464
- }
465
- exports._getReplaceOrder = _getReplaceOrder;
466
- /**
467
- * Determine an order for checking field names against a dataSource or widget.
468
- * Sort order preference is set in this order: layer url, web map layer id, service url, agol itemId
469
- *
470
- * @param datasourceInfo The datasource object with key properties about the service.
471
- * @param testString A stringified version of a widget or dataSource
472
- * @returns The prioritized order for testing
473
- * @private
474
- */
475
- function _getSortOrder(datasourceInfo, testString) {
476
- const url = datasourceInfo.url;
477
- const itemId = datasourceInfo.itemId;
478
- const layerId = datasourceInfo.layerId;
479
- // if we have the url and the layerID and its found prioritize it first
480
- // else if we find the maps layer id prioritze it first
481
- let layerUrlTest;
482
- if (url && !isNaN(layerId)) {
483
- layerUrlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
484
- }
485
- if (layerUrlTest && layerUrlTest.test(testString)) {
486
- return 1;
487
- }
488
- else if (datasourceInfo.ids.length > 0) {
489
- if (datasourceInfo.ids.some((id) => {
490
- const layerMapIdTest = new RegExp(id, "gm");
491
- return layerMapIdTest.test(testString);
492
- })) {
493
- return 1;
494
- }
495
- }
496
- // if neither full layer url or map layer id are found...check to see if we can
497
- // find the base service url
498
- if (url) {
499
- const serviceUrlTest = new RegExp(url, "gm");
500
- if (serviceUrlTest.test(testString)) {
501
- return 2;
502
- }
503
- }
504
- // if none of the above see if we can find an AGOL item id reference
505
- if (itemId) {
506
- const itemIdTest = new RegExp(itemId, "gm");
507
- if (itemIdTest.test(testString)) {
508
- return 3;
509
- }
510
- }
511
- return 4;
512
- }
513
- exports._getSortOrder = _getSortOrder;
514
- /**
515
- * These tests will run prior to the tests associated with the higher level tests based on sort order.
516
- * The tests work more like cloning an object where we go through and review each individual property.
517
- * If we find a url or webmap layer id we will templatize the parent object that contains this property.
518
- * Many widgets will store one of these two properties in an object that will also contain various field references.
519
- *
520
- * @param obj The dataSource or widget object from the application
521
- * @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
522
- * @returns An updated instance of the dataSource or widget with as many field references templatized as possible.
523
- * @private
524
- */
525
- function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
526
- const objString = JSON.stringify(obj);
527
- const hasDatasources = datasourceInfos.filter((ds) => {
528
- let urlTest;
529
- if (ds.url && !isNaN(ds.layerId)) {
530
- urlTest = new RegExp(ds.url.replace(/[.]/, ".layer" + ds.layerId + "."), "gm");
531
- }
532
- let hasMapLayerId = false;
533
- if (ds.ids.length > 0) {
534
- hasMapLayerId = ds.ids.some((id) => {
535
- const idTest = new RegExp(id, "gm");
536
- return idTest.test(objString);
537
- });
538
- }
539
- if (hasMapLayerId || (urlTest && urlTest.test(objString))) {
540
- return ds;
541
- }
542
- });
543
- if (hasDatasources.length > 0) {
544
- hasDatasources.forEach((ds) => {
545
- // specific url reference is the most common
546
- obj = _templatizeParentByURL(obj, ds, templatizeKeys);
547
- if (ds.ids.length > 0) {
548
- // the second most common is to use the layerId from the webmap
549
- ds.ids.forEach((id) => {
550
- obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);
551
- });
552
- }
553
- });
554
- }
555
- return obj;
556
- }
557
- exports._prioritizedTests = _prioritizedTests;
558
- /**
559
- * This is very close to common.cloneObject but will test if an object
560
- * has one of the datasource urls as a property. If it finds one it will
561
- * templatize it's parent based on the fields from that datasource
562
- *
563
- * @param obj The dataSource or widget object from the application
564
- * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
565
- * @returns The updated instance of the object with as many field references templatized as possible
566
- * @private
567
- */
568
- function _templatizeParentByURL(obj, ds, templatizeKeys) {
569
- let clone = {};
570
- const url = ds.url;
571
- const layerId = ds.layerId;
572
- let urlTest;
573
- if (url && !isNaN(layerId)) {
574
- urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
575
- }
576
- if (Array.isArray(obj)) {
577
- clone = obj.map((c) => {
578
- return _templatizeParentByURL(c, ds, templatizeKeys);
579
- });
580
- }
581
- else if (typeof obj === "object") {
582
- for (const i in obj) {
583
- if (obj[i] != null && typeof obj[i] === "object") {
584
- clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
585
- }
586
- else {
587
- if (urlTest && urlTest.test(obj[i])) {
588
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
589
- }
590
- clone[i] = obj[i];
591
- }
592
- }
593
- }
594
- else {
595
- clone = obj;
596
- }
597
- return clone;
598
- }
599
- exports._templatizeParentByURL = _templatizeParentByURL;
600
- /**
601
- * This is very close to common.cloneObject but will test if an object
602
- * has one of the datasource webmap layer ids as a property. If it finds one it will
603
- * templatize it's parent based on the fields from that datasource.
604
- *
605
- * @param obj The dataSource or widget object from the application
606
- * @param ds A datasourceInfo object to use for testing against the current dataSource or widget
607
- * @param id A webmap layer id to test with.
608
- * @returns The updated instance of the object with as many field references templatized as possible
609
- * @private
610
- */
611
- function _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys) {
612
- let clone = {};
613
- const idTest = new RegExp(id, "gm");
614
- if (Array.isArray(obj)) {
615
- clone = obj.map((c) => {
616
- return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);
617
- });
618
- }
619
- else if (typeof obj === "object") {
620
- for (const i in obj) {
621
- if (obj[i] !== null) {
622
- // In some web application templates they store a stringified version of an object that can
623
- // contain multiple layer references at a very high level on the main values collection.
624
- // This was causing many other more typical layer references to be set incorrectly as the first
625
- // layerId found in this high level string would be used against the main object.
626
- let parsedProp;
627
- try {
628
- parsedProp = JSON.parse(obj[i]);
629
- }
630
- catch (error) {
631
- parsedProp = undefined;
632
- }
633
- if (parsedProp && typeof parsedProp === "object") {
634
- clone[i] = JSON.stringify(_templatizeParentByWebMapLayerId(parsedProp, ds, id, templatizeKeys));
635
- }
636
- else if (typeof obj[i] === "object") {
637
- // some widgets store the layerId as a key to a collection of details that contain field references
638
- if (idTest.test(i) && templatizeKeys) {
639
- obj[i] = common.templatizeFieldReferences(obj[i], ds.fields, ds.basePath, templatizeKeys);
640
- }
641
- clone[i] = _templatizeParentByWebMapLayerId(obj[i], ds, id, templatizeKeys);
642
- }
643
- else {
644
- if (idTest.test(obj[i])) {
645
- obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
646
- }
647
- clone[i] = obj[i];
648
- }
649
- }
650
- else {
651
- clone[i] = obj[i];
652
- }
653
- }
654
- }
655
- else {
656
- clone = obj;
657
- }
658
- return clone;
659
- }
660
- exports._templatizeParentByWebMapLayerId = _templatizeParentByWebMapLayerId;
661
- //# sourceMappingURL=webmappingapplication.js.map