@esri/solution-simple-types 5.2.2 → 5.2.3

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