@esri/solution-simple-types 1.1.2 → 1.2.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.
- package/dist/esm/dashboard.d.ts +0 -1
- package/dist/esm/dashboard.js +55 -56
- package/dist/esm/dashboard.js.map +1 -1
- package/dist/esm/helpers/convert-item-to-template.d.ts +3 -2
- package/dist/esm/helpers/convert-item-to-template.js +35 -37
- package/dist/esm/helpers/convert-item-to-template.js.map +1 -1
- package/dist/esm/helpers/create-item-from-template.js +33 -41
- package/dist/esm/helpers/create-item-from-template.js.map +1 -1
- package/dist/esm/helpers/update-notebook-data.js +1 -1
- package/dist/esm/helpers/update-notebook-data.js.map +1 -1
- package/dist/esm/notebook.d.ts +3 -2
- package/dist/esm/notebook.js +16 -15
- package/dist/esm/notebook.js.map +1 -1
- package/dist/esm/oic.d.ts +3 -2
- package/dist/esm/oic.js +30 -29
- package/dist/esm/oic.js.map +1 -1
- package/dist/esm/quickcapture.d.ts +3 -2
- package/dist/esm/quickcapture.js +22 -21
- package/dist/esm/quickcapture.js.map +1 -1
- package/dist/esm/simple-types.d.ts +3 -2
- package/dist/esm/simple-types.js +4 -3
- package/dist/esm/simple-types.js.map +1 -1
- package/dist/esm/webmap.d.ts +3 -2
- package/dist/esm/webmap.js +39 -39
- package/dist/esm/webmap.js.map +1 -1
- package/dist/esm/webmappingapplication.d.ts +3 -2
- package/dist/esm/webmappingapplication.js +126 -128
- package/dist/esm/webmappingapplication.js.map +1 -1
- package/dist/esm/workforce.d.ts +3 -2
- package/dist/esm/workforce.js +4 -3
- package/dist/esm/workforce.js.map +1 -1
- package/dist/node/dashboard.d.ts +0 -1
- package/dist/node/dashboard.js +56 -57
- package/dist/node/dashboard.js.map +1 -1
- package/dist/node/helpers/convert-item-to-template.d.ts +3 -2
- package/dist/node/helpers/convert-item-to-template.js +43 -45
- package/dist/node/helpers/convert-item-to-template.js.map +1 -1
- package/dist/node/helpers/create-item-from-template.js +37 -45
- package/dist/node/helpers/create-item-from-template.js.map +1 -1
- package/dist/node/helpers/notebook-helpers.js +3 -3
- package/dist/node/helpers/notebook-helpers.js.map +1 -1
- package/dist/node/helpers/quickcapture-helpers.js +2 -2
- package/dist/node/helpers/quickcapture-helpers.js.map +1 -1
- package/dist/node/helpers/simple-type-helpers.js +2 -2
- package/dist/node/helpers/simple-type-helpers.js.map +1 -1
- package/dist/node/helpers/update-notebook-data.js +2 -2
- package/dist/node/helpers/update-notebook-data.js.map +1 -1
- package/dist/node/index.js +6 -6
- package/dist/node/index.js.map +1 -1
- package/dist/node/notebook.d.ts +3 -2
- package/dist/node/notebook.js +18 -17
- package/dist/node/notebook.js.map +1 -1
- package/dist/node/oic.d.ts +3 -2
- package/dist/node/oic.js +31 -30
- package/dist/node/oic.js.map +1 -1
- package/dist/node/quickcapture.d.ts +3 -2
- package/dist/node/quickcapture.js +24 -23
- package/dist/node/quickcapture.js.map +1 -1
- package/dist/node/simple-types.d.ts +3 -2
- package/dist/node/simple-types.js +9 -8
- package/dist/node/simple-types.js.map +1 -1
- package/dist/node/webmap.d.ts +3 -2
- package/dist/node/webmap.js +40 -40
- package/dist/node/webmap.js.map +1 -1
- package/dist/node/webmappingapplication.d.ts +3 -2
- package/dist/node/webmappingapplication.js +127 -129
- package/dist/node/webmappingapplication.js.map +1 -1
- package/dist/node/workforce.d.ts +3 -2
- package/dist/node/workforce.js +5 -4
- package/dist/node/workforce.js.map +1 -1
- package/dist/umd/dashboard.d.ts +0 -1
- package/dist/umd/helpers/convert-item-to-template.d.ts +3 -2
- package/dist/umd/notebook.d.ts +3 -2
- package/dist/umd/oic.d.ts +3 -2
- package/dist/umd/quickcapture.d.ts +3 -2
- package/dist/umd/simple-types.d.ts +3 -2
- package/dist/umd/simple-types.umd.js +2142 -2152
- package/dist/umd/simple-types.umd.js.map +1 -1
- package/dist/umd/simple-types.umd.min.js +3 -3
- package/dist/umd/simple-types.umd.min.js.map +1 -1
- package/dist/umd/webmap.d.ts +3 -2
- package/dist/umd/webmappingapplication.d.ts +3 -2
- package/dist/umd/workforce.d.ts +3 -2
- package/package.json +23 -23
|
@@ -19,20 +19,21 @@ import * as common from "@esri/solution-common";
|
|
|
19
19
|
* Converts a web mapping application item into a template.
|
|
20
20
|
*
|
|
21
21
|
* @param itemInfo Info about the item
|
|
22
|
-
* @param
|
|
22
|
+
* @param destAuthentication Credentials for requests to the destination organization
|
|
23
|
+
* @param srcAuthentication Credentials for requests to source items
|
|
23
24
|
* @return A promise that will resolve when the template has been created
|
|
24
25
|
*/
|
|
25
|
-
export function convertItemToTemplate(itemTemplate,
|
|
26
|
-
return new Promise(
|
|
26
|
+
export function convertItemToTemplate(itemTemplate, destAuthentication, srcAuthentication) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
27
28
|
// Remove org base URL and app id, e.g.,
|
|
28
29
|
// http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21
|
|
29
30
|
// to
|
|
30
31
|
// <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}
|
|
31
32
|
// Need to add placeholder server name because otherwise AGOL makes URL null
|
|
32
|
-
|
|
33
|
+
let portalUrl = "";
|
|
33
34
|
if (itemTemplate.item.url) {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const templatizedUrl = itemTemplate.item.url;
|
|
36
|
+
const iSep = templatizedUrl.indexOf("//");
|
|
36
37
|
itemTemplate.item.url =
|
|
37
38
|
common.placeholder(common.SERVER_NAME) + // add placeholder server name
|
|
38
39
|
templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2), templatizedUrl.lastIndexOf("=") + 1) +
|
|
@@ -60,37 +61,37 @@ export function convertItemToTemplate(itemTemplate, authentication) {
|
|
|
60
61
|
"data.httpProxy.url"
|
|
61
62
|
], common.placeholder(common.SERVER_NAME));
|
|
62
63
|
common.setProp(itemTemplate, "data.geometryService", common.placeholder(common.GEOMETRY_SERVER_NAME));
|
|
63
|
-
templatizeDatasources(itemTemplate,
|
|
64
|
-
templatizeWidgets(itemTemplate,
|
|
65
|
-
templatizeWidgets(_itemTemplate,
|
|
66
|
-
templatizeValues(updatedItemTemplate,
|
|
64
|
+
templatizeDatasources(itemTemplate, srcAuthentication, portalUrl).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 => {
|
|
67
68
|
resolve(_updatedItemTemplate);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
69
|
+
}, e => reject(common.fail(e)));
|
|
70
|
+
}, e => reject(common.fail(e)));
|
|
71
|
+
}, e => reject(common.fail(e)));
|
|
72
|
+
}, e => reject(common.fail(e)));
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
export function templatizeDatasources(itemTemplate, authentication, portalUrl) {
|
|
75
|
-
return new Promise(
|
|
76
|
-
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const dataSources = common.getProp(itemTemplate, "data.dataSource.dataSources");
|
|
77
78
|
if (dataSources && Object.keys(dataSources).length > 0) {
|
|
78
|
-
|
|
79
|
-
Object.keys(dataSources).forEach(
|
|
80
|
-
|
|
79
|
+
const pendingRequests = new Array();
|
|
80
|
+
Object.keys(dataSources).forEach(k => {
|
|
81
|
+
const ds = dataSources[k];
|
|
81
82
|
common.setProp(ds, "portalUrl", common.placeholder(common.SERVER_NAME));
|
|
82
|
-
|
|
83
|
+
const itemId = common.getProp(ds, "itemId");
|
|
83
84
|
if (common.getProp(ds, "url")) {
|
|
84
85
|
if (itemId) {
|
|
85
|
-
|
|
86
|
+
const layerId = ds.url.substr(ds.url.lastIndexOf("/") + 1);
|
|
86
87
|
ds.itemId = common.templatizeTerm(itemId, itemId, ".layer" + layerId + ".itemId");
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
handleServiceRequests(
|
|
89
|
+
const urlResults = findUrls(ds.url, portalUrl, [], [], authentication);
|
|
90
|
+
pendingRequests.push(new Promise((resolveReq, rejectReq) => {
|
|
91
|
+
handleServiceRequests(urlResults.serviceRequests, urlResults.requestUrls, urlResults.testString).then(response => {
|
|
91
92
|
ds.url = response;
|
|
92
93
|
resolveReq();
|
|
93
|
-
},
|
|
94
|
+
}, e => rejectReq(common.fail(e)));
|
|
94
95
|
}));
|
|
95
96
|
}
|
|
96
97
|
else {
|
|
@@ -99,40 +100,39 @@ export function templatizeDatasources(itemTemplate, authentication, portalUrl) {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
});
|
|
102
|
-
Promise.all(
|
|
103
|
+
Promise.all(pendingRequests).then(() => resolve(itemTemplate), e => reject(common.fail(e)));
|
|
103
104
|
}
|
|
104
105
|
else {
|
|
105
106
|
resolve(itemTemplate);
|
|
106
107
|
}
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
export function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen) {
|
|
110
|
-
|
|
111
|
-
return new Promise(function (resolve, reject) {
|
|
110
|
+
export function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen = false) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
112
|
// update widgets
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
widgets.forEach(
|
|
113
|
+
const widgets = common.getProp(itemTemplate, widgetPath) || [];
|
|
114
|
+
let serviceRequests = [];
|
|
115
|
+
let requestUrls = [];
|
|
116
|
+
widgets.forEach(widget => {
|
|
117
117
|
/* istanbul ignore else */
|
|
118
118
|
if (!isOnScreen && common.getProp(widget, "icon")) {
|
|
119
119
|
setValues(widget, ["icon"], common.placeholder(common.SERVER_NAME));
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
const config = widget.config;
|
|
122
122
|
if (config) {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
const sConfig = JSON.stringify(config);
|
|
124
|
+
const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
|
|
125
125
|
widget.config = JSON.parse(urlResults.testString);
|
|
126
126
|
serviceRequests = urlResults.serviceRequests;
|
|
127
127
|
requestUrls = urlResults.requestUrls;
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
if (serviceRequests.length > 0) {
|
|
131
|
-
|
|
132
|
-
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(
|
|
131
|
+
const sWidgets = JSON.stringify(widgets);
|
|
132
|
+
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
|
|
133
133
|
common.setProp(itemTemplate, widgetPath, JSON.parse(response));
|
|
134
134
|
resolve(itemTemplate);
|
|
135
|
-
},
|
|
135
|
+
}, e => reject(common.fail(e)));
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
138
|
resolve(itemTemplate);
|
|
@@ -140,27 +140,27 @@ export function templatizeWidgets(itemTemplate, authentication, portalUrl, widge
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
export function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
|
|
143
|
-
return new Promise(
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
144
|
// update properties of values collection for web app templates
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
let values = common.getProp(itemTemplate, widgetPath);
|
|
146
|
+
let serviceRequests = [];
|
|
147
|
+
let requestUrls = [];
|
|
148
148
|
if (values) {
|
|
149
149
|
if (common.getProp(values, "icon")) {
|
|
150
150
|
setValues(values, ["icon"], common.placeholder(common.SERVER_NAME));
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
const sConfig = JSON.stringify(values);
|
|
153
|
+
const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
|
|
154
154
|
values = JSON.parse(urlResults.testString);
|
|
155
155
|
serviceRequests = urlResults.serviceRequests;
|
|
156
156
|
requestUrls = urlResults.requestUrls;
|
|
157
157
|
}
|
|
158
158
|
if (serviceRequests.length > 0) {
|
|
159
|
-
|
|
160
|
-
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(
|
|
159
|
+
const sWidgets = JSON.stringify(values);
|
|
160
|
+
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
|
|
161
161
|
common.setProp(itemTemplate, widgetPath, JSON.parse(response));
|
|
162
162
|
resolve(itemTemplate);
|
|
163
|
-
},
|
|
163
|
+
}, e => reject(common.fail(e)));
|
|
164
164
|
}
|
|
165
165
|
else {
|
|
166
166
|
resolve(itemTemplate);
|
|
@@ -168,24 +168,24 @@ export function templatizeValues(itemTemplate, authentication, portalUrl, widget
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
export function handleServiceRequests(serviceRequests, requestUrls, objString) {
|
|
171
|
-
return new Promise(
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
172
|
if (serviceRequests && serviceRequests.length > 0) {
|
|
173
|
-
|
|
174
|
-
Promise.all(serviceRequests).then(
|
|
175
|
-
serviceResponses.forEach(
|
|
173
|
+
let i = 0;
|
|
174
|
+
Promise.all(serviceRequests).then(serviceResponses => {
|
|
175
|
+
serviceResponses.forEach(serviceResponse => {
|
|
176
176
|
if (common.getProp(serviceResponse, "serviceItemId")) {
|
|
177
|
-
|
|
177
|
+
const serviceTemplate = "{{" +
|
|
178
178
|
serviceResponse.serviceItemId +
|
|
179
179
|
(serviceResponse.hasOwnProperty("id")
|
|
180
180
|
? ".layer" + serviceResponse.id
|
|
181
181
|
: "") +
|
|
182
182
|
".url}}";
|
|
183
|
-
objString = replaceUrl(objString, requestUrls[
|
|
183
|
+
objString = replaceUrl(objString, requestUrls[i], serviceTemplate, true);
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
i++;
|
|
186
186
|
});
|
|
187
187
|
resolve(objString);
|
|
188
|
-
},
|
|
188
|
+
}, e => reject(common.fail(e)));
|
|
189
189
|
}
|
|
190
190
|
else {
|
|
191
191
|
resolve(objString);
|
|
@@ -193,14 +193,14 @@ export function handleServiceRequests(serviceRequests, requestUrls, objString) {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
export function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentication) {
|
|
196
|
-
|
|
196
|
+
const options = {
|
|
197
197
|
f: "json",
|
|
198
198
|
authentication: authentication
|
|
199
199
|
};
|
|
200
200
|
// test for URLs
|
|
201
|
-
|
|
201
|
+
const results = testString.match(/(\bhttps?:\/\/[-A-Z0-9/._]*)/gim);
|
|
202
202
|
if (results && results.length) {
|
|
203
|
-
results.forEach(
|
|
203
|
+
results.forEach((url) => {
|
|
204
204
|
if (url.indexOf("NAServer") > -1) {
|
|
205
205
|
testString = replaceUrl(testString, url, common.placeholder(common.NA_SERVER_NAME));
|
|
206
206
|
}
|
|
@@ -219,9 +219,9 @@ export function findUrls(testString, portalUrl, requestUrls, serviceRequests, au
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
return {
|
|
222
|
-
testString
|
|
223
|
-
requestUrls
|
|
224
|
-
serviceRequests
|
|
222
|
+
testString,
|
|
223
|
+
requestUrls,
|
|
224
|
+
serviceRequests
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
@@ -235,23 +235,22 @@ export function findUrls(testString, portalUrl, requestUrls, serviceRequests, au
|
|
|
235
235
|
*
|
|
236
236
|
* @returns the obj with any instances of the url replaced
|
|
237
237
|
*/
|
|
238
|
-
export function replaceUrl(obj, url, newUrl, validateFullUrl) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
|
|
238
|
+
export function replaceUrl(obj, url, newUrl, validateFullUrl = false) {
|
|
239
|
+
const enforceFullUrl = validateFullUrl && obj.indexOf('"') > -1;
|
|
240
|
+
const re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
|
|
242
241
|
return obj.replace(re, enforceFullUrl ? '"' + newUrl + '"' : newUrl);
|
|
243
242
|
}
|
|
244
243
|
export function setValues(itemTemplate, paths, base) {
|
|
245
|
-
paths.forEach(
|
|
246
|
-
|
|
244
|
+
paths.forEach(path => {
|
|
245
|
+
const url = common.getProp(itemTemplate, path);
|
|
247
246
|
if (url) {
|
|
248
|
-
|
|
247
|
+
const subString = url.substring(url.indexOf("/", url.indexOf("//") + 2));
|
|
249
248
|
common.setProp(itemTemplate, path, subString !== url ? base + subString : base);
|
|
250
249
|
}
|
|
251
250
|
});
|
|
252
251
|
}
|
|
253
252
|
export function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDictionary, destinationAuthentication) {
|
|
254
|
-
return new Promise(
|
|
253
|
+
return new Promise(resolve => {
|
|
255
254
|
// If this is a Web AppBuilder application, we will create a Code Attachment for downloading
|
|
256
255
|
if (common.hasAnyKeyword(originalTemplate, [
|
|
257
256
|
"WAB2D",
|
|
@@ -259,13 +258,13 @@ export function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, template
|
|
|
259
258
|
"Web AppBuilder"
|
|
260
259
|
])) {
|
|
261
260
|
// Update item so properties like appItemId can now be set now that we know the new apps ID
|
|
262
|
-
|
|
261
|
+
const updateOptions = {
|
|
263
262
|
id: newlyCreatedItem.itemId,
|
|
264
263
|
url: newlyCreatedItem.item.url,
|
|
265
264
|
data: newlyCreatedItem.data
|
|
266
265
|
};
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
const updateDef = common.updateItem(updateOptions, destinationAuthentication);
|
|
267
|
+
const itemInfo = {
|
|
269
268
|
tags: originalTemplate.item.tags,
|
|
270
269
|
title: originalTemplate.item.title,
|
|
271
270
|
type: "Code Attachment",
|
|
@@ -277,8 +276,8 @@ export function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, template
|
|
|
277
276
|
newlyCreatedItem.itemId +
|
|
278
277
|
"/package"
|
|
279
278
|
};
|
|
280
|
-
|
|
281
|
-
Promise.all([updateDef, createItemWithDataDef]).then(
|
|
279
|
+
const createItemWithDataDef = common.createItemWithData(itemInfo, {}, destinationAuthentication, templateDictionary.folderId);
|
|
280
|
+
Promise.all([updateDef, createItemWithDataDef]).then(() => resolve(null), () => resolve(null));
|
|
282
281
|
}
|
|
283
282
|
else {
|
|
284
283
|
// Otherwise, nothing extra needed
|
|
@@ -295,7 +294,7 @@ export function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, template
|
|
|
295
294
|
* @protected
|
|
296
295
|
*/
|
|
297
296
|
export function _extractDependencies(model) {
|
|
298
|
-
|
|
297
|
+
let processor = _getGenericWebAppDependencies;
|
|
299
298
|
/*
|
|
300
299
|
if (common.hasTypeKeyword(model, "Story Map")) {
|
|
301
300
|
processor = getStoryMapDependencies;
|
|
@@ -310,19 +309,19 @@ export function _extractDependencies(model) {
|
|
|
310
309
|
* Generic Web App Dependencies
|
|
311
310
|
*/
|
|
312
311
|
export function _getGenericWebAppDependencies(model) {
|
|
313
|
-
|
|
312
|
+
const props = ["data.values.webmap", "data.values.group"];
|
|
314
313
|
return common.getProps(model, props);
|
|
315
314
|
}
|
|
316
315
|
export function _getWABDependencies(model) {
|
|
317
|
-
|
|
318
|
-
|
|
316
|
+
const deps = [];
|
|
317
|
+
const v = common.getProp(model, "data.map.itemId");
|
|
319
318
|
if (v) {
|
|
320
319
|
deps.push(v);
|
|
321
320
|
}
|
|
322
|
-
|
|
321
|
+
const dataSources = common.getProp(model, "data.dataSource.dataSources");
|
|
323
322
|
if (dataSources) {
|
|
324
|
-
Object.keys(dataSources).forEach(
|
|
325
|
-
|
|
323
|
+
Object.keys(dataSources).forEach(k => {
|
|
324
|
+
const ds = dataSources[k];
|
|
326
325
|
if (ds.itemId) {
|
|
327
326
|
deps.push(ds.itemId);
|
|
328
327
|
}
|
|
@@ -338,8 +337,8 @@ export function _getWABDependencies(model) {
|
|
|
338
337
|
* @protected
|
|
339
338
|
*/
|
|
340
339
|
export function _templatizeIdPaths(itemTemplate, paths) {
|
|
341
|
-
paths.forEach(
|
|
342
|
-
|
|
340
|
+
paths.forEach(path => {
|
|
341
|
+
const id = common.getProp(itemTemplate, path);
|
|
343
342
|
_templatizeIdPath(itemTemplate, path, id);
|
|
344
343
|
});
|
|
345
344
|
}
|
|
@@ -363,27 +362,27 @@ export function _templatizeIdPath(itemTemplate, path, id) {
|
|
|
363
362
|
*/
|
|
364
363
|
export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
|
|
365
364
|
// handle datasources common for WAB apps
|
|
366
|
-
|
|
365
|
+
const dataSources = common.getProp(solutionTemplate, "data.dataSource.dataSources");
|
|
367
366
|
if (dataSources && Object.keys(dataSources).length > 0) {
|
|
368
|
-
Object.keys(dataSources).forEach(
|
|
369
|
-
|
|
367
|
+
Object.keys(dataSources).forEach(k => {
|
|
368
|
+
const ds = dataSources[k];
|
|
370
369
|
dataSources[k] = _templatizeObject(ds, datasourceInfos);
|
|
371
370
|
});
|
|
372
371
|
common.setProp(solutionTemplate, "data.dataSource.dataSources", dataSources);
|
|
373
372
|
}
|
|
374
373
|
// handle widgets common for WAB apps
|
|
375
|
-
|
|
374
|
+
const paths = [
|
|
376
375
|
"data.widgetPool.widgets",
|
|
377
376
|
"data.widgetOnScreen.widgets"
|
|
378
377
|
];
|
|
379
|
-
paths.forEach(
|
|
380
|
-
|
|
378
|
+
paths.forEach(path => {
|
|
379
|
+
const widgets = common.getProp(solutionTemplate, path);
|
|
381
380
|
if (widgets) {
|
|
382
381
|
common.setProp(solutionTemplate, path, _templatizeObjectArray(widgets, datasourceInfos));
|
|
383
382
|
}
|
|
384
383
|
});
|
|
385
384
|
// handle values common for web app templates
|
|
386
|
-
|
|
385
|
+
const values = common.getProp(solutionTemplate, "data.values");
|
|
387
386
|
if (values) {
|
|
388
387
|
common.setProp(solutionTemplate, "data.values", _templatizeObject(values, datasourceInfos));
|
|
389
388
|
}
|
|
@@ -396,11 +395,10 @@ export function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
|
|
|
396
395
|
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
397
396
|
* @returns The dataSource with templatized field references
|
|
398
397
|
*/
|
|
399
|
-
export function _templatizeObject(obj, datasourceInfos, templatizeKeys) {
|
|
400
|
-
if (templatizeKeys === void 0) { templatizeKeys = false; }
|
|
398
|
+
export function _templatizeObject(obj, datasourceInfos, templatizeKeys = false) {
|
|
401
399
|
obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);
|
|
402
|
-
|
|
403
|
-
replaceOrder.forEach(
|
|
400
|
+
const replaceOrder = _getReplaceOrder(obj, datasourceInfos);
|
|
401
|
+
replaceOrder.forEach(ds => {
|
|
404
402
|
obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
|
|
405
403
|
});
|
|
406
404
|
return obj;
|
|
@@ -413,11 +411,11 @@ export function _templatizeObject(obj, datasourceInfos, templatizeKeys) {
|
|
|
413
411
|
* @returns The widgets with templatized field references
|
|
414
412
|
*/
|
|
415
413
|
export function _templatizeObjectArray(objects, datasourceInfos) {
|
|
416
|
-
|
|
417
|
-
return objects.map(
|
|
414
|
+
const updateKeyObjects = ["SmartEditor", "Screening"];
|
|
415
|
+
return objects.map(obj => {
|
|
418
416
|
// only templatize the config and lower
|
|
419
417
|
if (obj.config) {
|
|
420
|
-
|
|
418
|
+
const templatizeKeys = updateKeyObjects.indexOf(obj.name) > -1;
|
|
421
419
|
obj.config = _templatizeObject(obj.config, datasourceInfos, templatizeKeys);
|
|
422
420
|
}
|
|
423
421
|
return obj;
|
|
@@ -433,10 +431,10 @@ export function _templatizeObjectArray(objects, datasourceInfos) {
|
|
|
433
431
|
* @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id
|
|
434
432
|
*/
|
|
435
433
|
export function _getReplaceOrder(obj, datasourceInfos) {
|
|
436
|
-
|
|
434
|
+
const objString = JSON.stringify(obj);
|
|
437
435
|
// If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.
|
|
438
|
-
|
|
439
|
-
return _datasourceInfos.sort(
|
|
436
|
+
const _datasourceInfos = datasourceInfos.filter(ds => _getSortOrder(ds, objString) < 4);
|
|
437
|
+
return _datasourceInfos.sort((a, b) => {
|
|
440
438
|
return _getSortOrder(a, objString) - _getSortOrder(b, objString);
|
|
441
439
|
});
|
|
442
440
|
}
|
|
@@ -449,12 +447,12 @@ export function _getReplaceOrder(obj, datasourceInfos) {
|
|
|
449
447
|
* @returns The prioritized order for testing
|
|
450
448
|
*/
|
|
451
449
|
export function _getSortOrder(datasourceInfo, testString) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
450
|
+
const url = datasourceInfo.url;
|
|
451
|
+
const itemId = datasourceInfo.itemId;
|
|
452
|
+
const layerId = datasourceInfo.layerId;
|
|
455
453
|
// if we have the url and the layerID and its found prioritize it first
|
|
456
454
|
// else if we find the maps layer id prioritze it first
|
|
457
|
-
|
|
455
|
+
let layerUrlTest;
|
|
458
456
|
if (url && !isNaN(layerId)) {
|
|
459
457
|
layerUrlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
|
|
460
458
|
}
|
|
@@ -462,8 +460,8 @@ export function _getSortOrder(datasourceInfo, testString) {
|
|
|
462
460
|
return 1;
|
|
463
461
|
}
|
|
464
462
|
else if (datasourceInfo.ids.length > 0) {
|
|
465
|
-
if (datasourceInfo.ids.some(
|
|
466
|
-
|
|
463
|
+
if (datasourceInfo.ids.some(id => {
|
|
464
|
+
const layerMapIdTest = new RegExp(id, "gm");
|
|
467
465
|
return layerMapIdTest.test(testString);
|
|
468
466
|
})) {
|
|
469
467
|
return 1;
|
|
@@ -472,14 +470,14 @@ export function _getSortOrder(datasourceInfo, testString) {
|
|
|
472
470
|
// if neither full layer url or map layer id are found...check to see if we can
|
|
473
471
|
// find the base service url
|
|
474
472
|
if (url) {
|
|
475
|
-
|
|
473
|
+
const serviceUrlTest = new RegExp(url, "gm");
|
|
476
474
|
if (serviceUrlTest.test(testString)) {
|
|
477
475
|
return 2;
|
|
478
476
|
}
|
|
479
477
|
}
|
|
480
478
|
// if none of the above see if we can find an AGOL item id reference
|
|
481
479
|
if (itemId) {
|
|
482
|
-
|
|
480
|
+
const itemIdTest = new RegExp(itemId, "gm");
|
|
483
481
|
if (itemIdTest.test(testString)) {
|
|
484
482
|
return 3;
|
|
485
483
|
}
|
|
@@ -497,16 +495,16 @@ export function _getSortOrder(datasourceInfo, testString) {
|
|
|
497
495
|
* @returns An updated instance of the dataSource or widget with as many field references templatized as possible.
|
|
498
496
|
*/
|
|
499
497
|
export function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
498
|
+
const objString = JSON.stringify(obj);
|
|
499
|
+
const hasDatasources = datasourceInfos.filter(ds => {
|
|
500
|
+
let urlTest;
|
|
503
501
|
if (ds.url && !isNaN(ds.layerId)) {
|
|
504
502
|
urlTest = new RegExp(ds.url.replace(/[.]/, ".layer" + ds.layerId + "."), "gm");
|
|
505
503
|
}
|
|
506
|
-
|
|
504
|
+
let hasMapLayerId = false;
|
|
507
505
|
if (ds.ids.length > 0) {
|
|
508
|
-
hasMapLayerId = ds.ids.some(
|
|
509
|
-
|
|
506
|
+
hasMapLayerId = ds.ids.some(id => {
|
|
507
|
+
const idTest = new RegExp(id, "gm");
|
|
510
508
|
return idTest.test(objString);
|
|
511
509
|
});
|
|
512
510
|
}
|
|
@@ -515,12 +513,12 @@ export function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
|
|
|
515
513
|
}
|
|
516
514
|
});
|
|
517
515
|
if (hasDatasources.length > 0) {
|
|
518
|
-
hasDatasources.forEach(
|
|
516
|
+
hasDatasources.forEach(ds => {
|
|
519
517
|
// specific url reference is the most common
|
|
520
518
|
obj = _templatizeParentByURL(obj, ds, templatizeKeys);
|
|
521
519
|
if (ds.ids.length > 0) {
|
|
522
520
|
// the second most common is to use the layerId from the webmap
|
|
523
|
-
ds.ids.forEach(
|
|
521
|
+
ds.ids.forEach(id => {
|
|
524
522
|
obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);
|
|
525
523
|
});
|
|
526
524
|
}
|
|
@@ -538,20 +536,20 @@ export function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
|
|
|
538
536
|
* @returns The updated instance of the object with as many field references templatized as possible
|
|
539
537
|
*/
|
|
540
538
|
export function _templatizeParentByURL(obj, ds, templatizeKeys) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
539
|
+
let clone = {};
|
|
540
|
+
const url = ds.url;
|
|
541
|
+
const layerId = ds.layerId;
|
|
542
|
+
let urlTest;
|
|
545
543
|
if (url && !isNaN(layerId)) {
|
|
546
544
|
urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
|
|
547
545
|
}
|
|
548
546
|
if (Array.isArray(obj)) {
|
|
549
|
-
clone = obj.map(
|
|
547
|
+
clone = obj.map(c => {
|
|
550
548
|
return _templatizeParentByURL(c, ds, templatizeKeys);
|
|
551
549
|
});
|
|
552
550
|
}
|
|
553
551
|
else if (typeof obj === "object") {
|
|
554
|
-
for (
|
|
552
|
+
for (const i in obj) {
|
|
555
553
|
if (obj[i] != null && typeof obj[i] === "object") {
|
|
556
554
|
clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
|
|
557
555
|
}
|
|
@@ -579,21 +577,21 @@ export function _templatizeParentByURL(obj, ds, templatizeKeys) {
|
|
|
579
577
|
* @returns The updated instance of the object with as many field references templatized as possible
|
|
580
578
|
*/
|
|
581
579
|
export function _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys) {
|
|
582
|
-
|
|
583
|
-
|
|
580
|
+
let clone = {};
|
|
581
|
+
const idTest = new RegExp(id, "gm");
|
|
584
582
|
if (Array.isArray(obj)) {
|
|
585
|
-
clone = obj.map(
|
|
583
|
+
clone = obj.map(c => {
|
|
586
584
|
return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);
|
|
587
585
|
});
|
|
588
586
|
}
|
|
589
587
|
else if (typeof obj === "object") {
|
|
590
|
-
for (
|
|
588
|
+
for (const i in obj) {
|
|
591
589
|
if (obj[i] !== null) {
|
|
592
590
|
// In some web application templates they store a stringified version of an object that can
|
|
593
591
|
// contain multiple layer references at a very high level on the main values collection.
|
|
594
592
|
// This was causing many other more typical layer references to be set incorrectly as the first
|
|
595
593
|
// layerId found in this high level string would be used against the main object.
|
|
596
|
-
|
|
594
|
+
let parsedProp;
|
|
597
595
|
try {
|
|
598
596
|
parsedProp = JSON.parse(obj[i]);
|
|
599
597
|
}
|