@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
|
@@ -16,26 +16,27 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
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
|
-
|
|
19
|
+
const common = require("@esri/solution-common");
|
|
20
20
|
// ------------------------------------------------------------------------------------------------------------------ //
|
|
21
21
|
/**
|
|
22
22
|
* Converts a web mapping application item into a template.
|
|
23
23
|
*
|
|
24
24
|
* @param itemInfo Info about the item
|
|
25
|
-
* @param
|
|
25
|
+
* @param destAuthentication Credentials for requests to the destination organization
|
|
26
|
+
* @param srcAuthentication Credentials for requests to source items
|
|
26
27
|
* @return A promise that will resolve when the template has been created
|
|
27
28
|
*/
|
|
28
|
-
function convertItemToTemplate(itemTemplate,
|
|
29
|
-
return new Promise(
|
|
29
|
+
function convertItemToTemplate(itemTemplate, destAuthentication, srcAuthentication) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
30
31
|
// Remove org base URL and app id, e.g.,
|
|
31
32
|
// http://anOrg.maps.arcgis.com/apps/CrowdsourcePolling/index.html?appid=6fc5992522d34a6b5ce80d17835eea21
|
|
32
33
|
// to
|
|
33
34
|
// <placeholder(SERVER_NAME)>/apps/CrowdsourcePolling/index.html?appid={{<itemId>.id}}
|
|
34
35
|
// Need to add placeholder server name because otherwise AGOL makes URL null
|
|
35
|
-
|
|
36
|
+
let portalUrl = "";
|
|
36
37
|
if (itemTemplate.item.url) {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const templatizedUrl = itemTemplate.item.url;
|
|
39
|
+
const iSep = templatizedUrl.indexOf("//");
|
|
39
40
|
itemTemplate.item.url =
|
|
40
41
|
common.placeholder(common.SERVER_NAME) + // add placeholder server name
|
|
41
42
|
templatizedUrl.substring(templatizedUrl.indexOf("/", iSep + 2), templatizedUrl.lastIndexOf("=") + 1) +
|
|
@@ -63,38 +64,38 @@ function convertItemToTemplate(itemTemplate, authentication) {
|
|
|
63
64
|
"data.httpProxy.url"
|
|
64
65
|
], common.placeholder(common.SERVER_NAME));
|
|
65
66
|
common.setProp(itemTemplate, "data.geometryService", common.placeholder(common.GEOMETRY_SERVER_NAME));
|
|
66
|
-
templatizeDatasources(itemTemplate,
|
|
67
|
-
templatizeWidgets(itemTemplate,
|
|
68
|
-
templatizeWidgets(_itemTemplate,
|
|
69
|
-
templatizeValues(updatedItemTemplate,
|
|
67
|
+
templatizeDatasources(itemTemplate, srcAuthentication, portalUrl).then(() => {
|
|
68
|
+
templatizeWidgets(itemTemplate, srcAuthentication, portalUrl, "data.widgetPool.widgets").then(_itemTemplate => {
|
|
69
|
+
templatizeWidgets(_itemTemplate, srcAuthentication, portalUrl, "data.widgetOnScreen.widgets", true).then(updatedItemTemplate => {
|
|
70
|
+
templatizeValues(updatedItemTemplate, srcAuthentication, portalUrl, "data.values").then(_updatedItemTemplate => {
|
|
70
71
|
resolve(_updatedItemTemplate);
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
72
|
+
}, e => reject(common.fail(e)));
|
|
73
|
+
}, e => reject(common.fail(e)));
|
|
74
|
+
}, e => reject(common.fail(e)));
|
|
75
|
+
}, e => reject(common.fail(e)));
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
exports.convertItemToTemplate = convertItemToTemplate;
|
|
78
79
|
function templatizeDatasources(itemTemplate, authentication, portalUrl) {
|
|
79
|
-
return new Promise(
|
|
80
|
-
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const dataSources = common.getProp(itemTemplate, "data.dataSource.dataSources");
|
|
81
82
|
if (dataSources && Object.keys(dataSources).length > 0) {
|
|
82
|
-
|
|
83
|
-
Object.keys(dataSources).forEach(
|
|
84
|
-
|
|
83
|
+
const pendingRequests = new Array();
|
|
84
|
+
Object.keys(dataSources).forEach(k => {
|
|
85
|
+
const ds = dataSources[k];
|
|
85
86
|
common.setProp(ds, "portalUrl", common.placeholder(common.SERVER_NAME));
|
|
86
|
-
|
|
87
|
+
const itemId = common.getProp(ds, "itemId");
|
|
87
88
|
if (common.getProp(ds, "url")) {
|
|
88
89
|
if (itemId) {
|
|
89
|
-
|
|
90
|
+
const layerId = ds.url.substr(ds.url.lastIndexOf("/") + 1);
|
|
90
91
|
ds.itemId = common.templatizeTerm(itemId, itemId, ".layer" + layerId + ".itemId");
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
handleServiceRequests(
|
|
93
|
+
const urlResults = findUrls(ds.url, portalUrl, [], [], authentication);
|
|
94
|
+
pendingRequests.push(new Promise((resolveReq, rejectReq) => {
|
|
95
|
+
handleServiceRequests(urlResults.serviceRequests, urlResults.requestUrls, urlResults.testString).then(response => {
|
|
95
96
|
ds.url = response;
|
|
96
97
|
resolveReq();
|
|
97
|
-
},
|
|
98
|
+
}, e => rejectReq(common.fail(e)));
|
|
98
99
|
}));
|
|
99
100
|
}
|
|
100
101
|
else {
|
|
@@ -103,7 +104,7 @@ function templatizeDatasources(itemTemplate, authentication, portalUrl) {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
});
|
|
106
|
-
Promise.all(
|
|
107
|
+
Promise.all(pendingRequests).then(() => resolve(itemTemplate), e => reject(common.fail(e)));
|
|
107
108
|
}
|
|
108
109
|
else {
|
|
109
110
|
resolve(itemTemplate);
|
|
@@ -111,33 +112,32 @@ function templatizeDatasources(itemTemplate, authentication, portalUrl) {
|
|
|
111
112
|
});
|
|
112
113
|
}
|
|
113
114
|
exports.templatizeDatasources = templatizeDatasources;
|
|
114
|
-
function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen) {
|
|
115
|
-
|
|
116
|
-
return new Promise(function (resolve, reject) {
|
|
115
|
+
function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath, isOnScreen = false) {
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
117
|
// update widgets
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
widgets.forEach(
|
|
118
|
+
const widgets = common.getProp(itemTemplate, widgetPath) || [];
|
|
119
|
+
let serviceRequests = [];
|
|
120
|
+
let requestUrls = [];
|
|
121
|
+
widgets.forEach(widget => {
|
|
122
122
|
/* istanbul ignore else */
|
|
123
123
|
if (!isOnScreen && common.getProp(widget, "icon")) {
|
|
124
124
|
setValues(widget, ["icon"], common.placeholder(common.SERVER_NAME));
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
const config = widget.config;
|
|
127
127
|
if (config) {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const sConfig = JSON.stringify(config);
|
|
129
|
+
const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
|
|
130
130
|
widget.config = JSON.parse(urlResults.testString);
|
|
131
131
|
serviceRequests = urlResults.serviceRequests;
|
|
132
132
|
requestUrls = urlResults.requestUrls;
|
|
133
133
|
}
|
|
134
134
|
});
|
|
135
135
|
if (serviceRequests.length > 0) {
|
|
136
|
-
|
|
137
|
-
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(
|
|
136
|
+
const sWidgets = JSON.stringify(widgets);
|
|
137
|
+
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
|
|
138
138
|
common.setProp(itemTemplate, widgetPath, JSON.parse(response));
|
|
139
139
|
resolve(itemTemplate);
|
|
140
|
-
},
|
|
140
|
+
}, e => reject(common.fail(e)));
|
|
141
141
|
}
|
|
142
142
|
else {
|
|
143
143
|
resolve(itemTemplate);
|
|
@@ -146,27 +146,27 @@ function templatizeWidgets(itemTemplate, authentication, portalUrl, widgetPath,
|
|
|
146
146
|
}
|
|
147
147
|
exports.templatizeWidgets = templatizeWidgets;
|
|
148
148
|
function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
|
|
149
|
-
return new Promise(
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
150
|
// update properties of values collection for web app templates
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
let values = common.getProp(itemTemplate, widgetPath);
|
|
152
|
+
let serviceRequests = [];
|
|
153
|
+
let requestUrls = [];
|
|
154
154
|
if (values) {
|
|
155
155
|
if (common.getProp(values, "icon")) {
|
|
156
156
|
setValues(values, ["icon"], common.placeholder(common.SERVER_NAME));
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const sConfig = JSON.stringify(values);
|
|
159
|
+
const urlResults = findUrls(sConfig, portalUrl, requestUrls, serviceRequests, authentication);
|
|
160
160
|
values = JSON.parse(urlResults.testString);
|
|
161
161
|
serviceRequests = urlResults.serviceRequests;
|
|
162
162
|
requestUrls = urlResults.requestUrls;
|
|
163
163
|
}
|
|
164
164
|
if (serviceRequests.length > 0) {
|
|
165
|
-
|
|
166
|
-
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(
|
|
165
|
+
const sWidgets = JSON.stringify(values);
|
|
166
|
+
handleServiceRequests(serviceRequests, requestUrls, sWidgets).then(response => {
|
|
167
167
|
common.setProp(itemTemplate, widgetPath, JSON.parse(response));
|
|
168
168
|
resolve(itemTemplate);
|
|
169
|
-
},
|
|
169
|
+
}, e => reject(common.fail(e)));
|
|
170
170
|
}
|
|
171
171
|
else {
|
|
172
172
|
resolve(itemTemplate);
|
|
@@ -175,24 +175,24 @@ function templatizeValues(itemTemplate, authentication, portalUrl, widgetPath) {
|
|
|
175
175
|
}
|
|
176
176
|
exports.templatizeValues = templatizeValues;
|
|
177
177
|
function handleServiceRequests(serviceRequests, requestUrls, objString) {
|
|
178
|
-
return new Promise(
|
|
178
|
+
return new Promise((resolve, reject) => {
|
|
179
179
|
if (serviceRequests && serviceRequests.length > 0) {
|
|
180
|
-
|
|
181
|
-
Promise.all(serviceRequests).then(
|
|
182
|
-
serviceResponses.forEach(
|
|
180
|
+
let i = 0;
|
|
181
|
+
Promise.all(serviceRequests).then(serviceResponses => {
|
|
182
|
+
serviceResponses.forEach(serviceResponse => {
|
|
183
183
|
if (common.getProp(serviceResponse, "serviceItemId")) {
|
|
184
|
-
|
|
184
|
+
const serviceTemplate = "{{" +
|
|
185
185
|
serviceResponse.serviceItemId +
|
|
186
186
|
(serviceResponse.hasOwnProperty("id")
|
|
187
187
|
? ".layer" + serviceResponse.id
|
|
188
188
|
: "") +
|
|
189
189
|
".url}}";
|
|
190
|
-
objString = replaceUrl(objString, requestUrls[
|
|
190
|
+
objString = replaceUrl(objString, requestUrls[i], serviceTemplate, true);
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
i++;
|
|
193
193
|
});
|
|
194
194
|
resolve(objString);
|
|
195
|
-
},
|
|
195
|
+
}, e => reject(common.fail(e)));
|
|
196
196
|
}
|
|
197
197
|
else {
|
|
198
198
|
resolve(objString);
|
|
@@ -201,14 +201,14 @@ function handleServiceRequests(serviceRequests, requestUrls, objString) {
|
|
|
201
201
|
}
|
|
202
202
|
exports.handleServiceRequests = handleServiceRequests;
|
|
203
203
|
function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentication) {
|
|
204
|
-
|
|
204
|
+
const options = {
|
|
205
205
|
f: "json",
|
|
206
206
|
authentication: authentication
|
|
207
207
|
};
|
|
208
208
|
// test for URLs
|
|
209
|
-
|
|
209
|
+
const results = testString.match(/(\bhttps?:\/\/[-A-Z0-9/._]*)/gim);
|
|
210
210
|
if (results && results.length) {
|
|
211
|
-
results.forEach(
|
|
211
|
+
results.forEach((url) => {
|
|
212
212
|
if (url.indexOf("NAServer") > -1) {
|
|
213
213
|
testString = replaceUrl(testString, url, common.placeholder(common.NA_SERVER_NAME));
|
|
214
214
|
}
|
|
@@ -227,9 +227,9 @@ function findUrls(testString, portalUrl, requestUrls, serviceRequests, authentic
|
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
229
|
return {
|
|
230
|
-
testString
|
|
231
|
-
requestUrls
|
|
232
|
-
serviceRequests
|
|
230
|
+
testString,
|
|
231
|
+
requestUrls,
|
|
232
|
+
serviceRequests
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
exports.findUrls = findUrls;
|
|
@@ -244,25 +244,24 @@ exports.findUrls = findUrls;
|
|
|
244
244
|
*
|
|
245
245
|
* @returns the obj with any instances of the url replaced
|
|
246
246
|
*/
|
|
247
|
-
function replaceUrl(obj, url, newUrl, validateFullUrl) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
var re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
|
|
247
|
+
function replaceUrl(obj, url, newUrl, validateFullUrl = false) {
|
|
248
|
+
const enforceFullUrl = validateFullUrl && obj.indexOf('"') > -1;
|
|
249
|
+
const re = new RegExp(enforceFullUrl ? '"' + url + '"' : url, "gmi");
|
|
251
250
|
return obj.replace(re, enforceFullUrl ? '"' + newUrl + '"' : newUrl);
|
|
252
251
|
}
|
|
253
252
|
exports.replaceUrl = replaceUrl;
|
|
254
253
|
function setValues(itemTemplate, paths, base) {
|
|
255
|
-
paths.forEach(
|
|
256
|
-
|
|
254
|
+
paths.forEach(path => {
|
|
255
|
+
const url = common.getProp(itemTemplate, path);
|
|
257
256
|
if (url) {
|
|
258
|
-
|
|
257
|
+
const subString = url.substring(url.indexOf("/", url.indexOf("//") + 2));
|
|
259
258
|
common.setProp(itemTemplate, path, subString !== url ? base + subString : base);
|
|
260
259
|
}
|
|
261
260
|
});
|
|
262
261
|
}
|
|
263
262
|
exports.setValues = setValues;
|
|
264
263
|
function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDictionary, destinationAuthentication) {
|
|
265
|
-
return new Promise(
|
|
264
|
+
return new Promise(resolve => {
|
|
266
265
|
// If this is a Web AppBuilder application, we will create a Code Attachment for downloading
|
|
267
266
|
if (common.hasAnyKeyword(originalTemplate, [
|
|
268
267
|
"WAB2D",
|
|
@@ -270,13 +269,13 @@ function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDiction
|
|
|
270
269
|
"Web AppBuilder"
|
|
271
270
|
])) {
|
|
272
271
|
// Update item so properties like appItemId can now be set now that we know the new apps ID
|
|
273
|
-
|
|
272
|
+
const updateOptions = {
|
|
274
273
|
id: newlyCreatedItem.itemId,
|
|
275
274
|
url: newlyCreatedItem.item.url,
|
|
276
275
|
data: newlyCreatedItem.data
|
|
277
276
|
};
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
const updateDef = common.updateItem(updateOptions, destinationAuthentication);
|
|
278
|
+
const itemInfo = {
|
|
280
279
|
tags: originalTemplate.item.tags,
|
|
281
280
|
title: originalTemplate.item.title,
|
|
282
281
|
type: "Code Attachment",
|
|
@@ -288,8 +287,8 @@ function fineTuneCreatedItem(originalTemplate, newlyCreatedItem, templateDiction
|
|
|
288
287
|
newlyCreatedItem.itemId +
|
|
289
288
|
"/package"
|
|
290
289
|
};
|
|
291
|
-
|
|
292
|
-
Promise.all([updateDef, createItemWithDataDef]).then(
|
|
290
|
+
const createItemWithDataDef = common.createItemWithData(itemInfo, {}, destinationAuthentication, templateDictionary.folderId);
|
|
291
|
+
Promise.all([updateDef, createItemWithDataDef]).then(() => resolve(null), () => resolve(null));
|
|
293
292
|
}
|
|
294
293
|
else {
|
|
295
294
|
// Otherwise, nothing extra needed
|
|
@@ -307,7 +306,7 @@ exports.fineTuneCreatedItem = fineTuneCreatedItem;
|
|
|
307
306
|
* @protected
|
|
308
307
|
*/
|
|
309
308
|
function _extractDependencies(model) {
|
|
310
|
-
|
|
309
|
+
let processor = _getGenericWebAppDependencies;
|
|
311
310
|
/*
|
|
312
311
|
if (common.hasTypeKeyword(model, "Story Map")) {
|
|
313
312
|
processor = getStoryMapDependencies;
|
|
@@ -323,20 +322,20 @@ exports._extractDependencies = _extractDependencies;
|
|
|
323
322
|
* Generic Web App Dependencies
|
|
324
323
|
*/
|
|
325
324
|
function _getGenericWebAppDependencies(model) {
|
|
326
|
-
|
|
325
|
+
const props = ["data.values.webmap", "data.values.group"];
|
|
327
326
|
return common.getProps(model, props);
|
|
328
327
|
}
|
|
329
328
|
exports._getGenericWebAppDependencies = _getGenericWebAppDependencies;
|
|
330
329
|
function _getWABDependencies(model) {
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
const deps = [];
|
|
331
|
+
const v = common.getProp(model, "data.map.itemId");
|
|
333
332
|
if (v) {
|
|
334
333
|
deps.push(v);
|
|
335
334
|
}
|
|
336
|
-
|
|
335
|
+
const dataSources = common.getProp(model, "data.dataSource.dataSources");
|
|
337
336
|
if (dataSources) {
|
|
338
|
-
Object.keys(dataSources).forEach(
|
|
339
|
-
|
|
337
|
+
Object.keys(dataSources).forEach(k => {
|
|
338
|
+
const ds = dataSources[k];
|
|
340
339
|
if (ds.itemId) {
|
|
341
340
|
deps.push(ds.itemId);
|
|
342
341
|
}
|
|
@@ -353,8 +352,8 @@ exports._getWABDependencies = _getWABDependencies;
|
|
|
353
352
|
* @protected
|
|
354
353
|
*/
|
|
355
354
|
function _templatizeIdPaths(itemTemplate, paths) {
|
|
356
|
-
paths.forEach(
|
|
357
|
-
|
|
355
|
+
paths.forEach(path => {
|
|
356
|
+
const id = common.getProp(itemTemplate, path);
|
|
358
357
|
_templatizeIdPath(itemTemplate, path, id);
|
|
359
358
|
});
|
|
360
359
|
}
|
|
@@ -380,27 +379,27 @@ exports._templatizeIdPath = _templatizeIdPath;
|
|
|
380
379
|
*/
|
|
381
380
|
function postProcessFieldReferences(solutionTemplate, datasourceInfos) {
|
|
382
381
|
// handle datasources common for WAB apps
|
|
383
|
-
|
|
382
|
+
const dataSources = common.getProp(solutionTemplate, "data.dataSource.dataSources");
|
|
384
383
|
if (dataSources && Object.keys(dataSources).length > 0) {
|
|
385
|
-
Object.keys(dataSources).forEach(
|
|
386
|
-
|
|
384
|
+
Object.keys(dataSources).forEach(k => {
|
|
385
|
+
const ds = dataSources[k];
|
|
387
386
|
dataSources[k] = _templatizeObject(ds, datasourceInfos);
|
|
388
387
|
});
|
|
389
388
|
common.setProp(solutionTemplate, "data.dataSource.dataSources", dataSources);
|
|
390
389
|
}
|
|
391
390
|
// handle widgets common for WAB apps
|
|
392
|
-
|
|
391
|
+
const paths = [
|
|
393
392
|
"data.widgetPool.widgets",
|
|
394
393
|
"data.widgetOnScreen.widgets"
|
|
395
394
|
];
|
|
396
|
-
paths.forEach(
|
|
397
|
-
|
|
395
|
+
paths.forEach(path => {
|
|
396
|
+
const widgets = common.getProp(solutionTemplate, path);
|
|
398
397
|
if (widgets) {
|
|
399
398
|
common.setProp(solutionTemplate, path, _templatizeObjectArray(widgets, datasourceInfos));
|
|
400
399
|
}
|
|
401
400
|
});
|
|
402
401
|
// handle values common for web app templates
|
|
403
|
-
|
|
402
|
+
const values = common.getProp(solutionTemplate, "data.values");
|
|
404
403
|
if (values) {
|
|
405
404
|
common.setProp(solutionTemplate, "data.values", _templatizeObject(values, datasourceInfos));
|
|
406
405
|
}
|
|
@@ -414,11 +413,10 @@ exports.postProcessFieldReferences = postProcessFieldReferences;
|
|
|
414
413
|
* @param datasourceInfos A list of datasource info objects that contain key values to templatize field references
|
|
415
414
|
* @returns The dataSource with templatized field references
|
|
416
415
|
*/
|
|
417
|
-
function _templatizeObject(obj, datasourceInfos, templatizeKeys) {
|
|
418
|
-
if (templatizeKeys === void 0) { templatizeKeys = false; }
|
|
416
|
+
function _templatizeObject(obj, datasourceInfos, templatizeKeys = false) {
|
|
419
417
|
obj = _prioritizedTests(obj, datasourceInfos, templatizeKeys);
|
|
420
|
-
|
|
421
|
-
replaceOrder.forEach(
|
|
418
|
+
const replaceOrder = _getReplaceOrder(obj, datasourceInfos);
|
|
419
|
+
replaceOrder.forEach(ds => {
|
|
422
420
|
obj = common.templatizeFieldReferences(obj, ds.fields, ds.basePath, templatizeKeys);
|
|
423
421
|
});
|
|
424
422
|
return obj;
|
|
@@ -432,11 +430,11 @@ exports._templatizeObject = _templatizeObject;
|
|
|
432
430
|
* @returns The widgets with templatized field references
|
|
433
431
|
*/
|
|
434
432
|
function _templatizeObjectArray(objects, datasourceInfos) {
|
|
435
|
-
|
|
436
|
-
return objects.map(
|
|
433
|
+
const updateKeyObjects = ["SmartEditor", "Screening"];
|
|
434
|
+
return objects.map(obj => {
|
|
437
435
|
// only templatize the config and lower
|
|
438
436
|
if (obj.config) {
|
|
439
|
-
|
|
437
|
+
const templatizeKeys = updateKeyObjects.indexOf(obj.name) > -1;
|
|
440
438
|
obj.config = _templatizeObject(obj.config, datasourceInfos, templatizeKeys);
|
|
441
439
|
}
|
|
442
440
|
return obj;
|
|
@@ -453,10 +451,10 @@ exports._templatizeObjectArray = _templatizeObjectArray;
|
|
|
453
451
|
* @returns A list of datasourceInfo objects sorted based on the presence of a layers url or id
|
|
454
452
|
*/
|
|
455
453
|
function _getReplaceOrder(obj, datasourceInfos) {
|
|
456
|
-
|
|
454
|
+
const objString = JSON.stringify(obj);
|
|
457
455
|
// If we don't find any layer url, web map layer id, service url, agol itemId then remove the datasource.
|
|
458
|
-
|
|
459
|
-
return _datasourceInfos.sort(
|
|
456
|
+
const _datasourceInfos = datasourceInfos.filter(ds => _getSortOrder(ds, objString) < 4);
|
|
457
|
+
return _datasourceInfos.sort((a, b) => {
|
|
460
458
|
return _getSortOrder(a, objString) - _getSortOrder(b, objString);
|
|
461
459
|
});
|
|
462
460
|
}
|
|
@@ -470,12 +468,12 @@ exports._getReplaceOrder = _getReplaceOrder;
|
|
|
470
468
|
* @returns The prioritized order for testing
|
|
471
469
|
*/
|
|
472
470
|
function _getSortOrder(datasourceInfo, testString) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
471
|
+
const url = datasourceInfo.url;
|
|
472
|
+
const itemId = datasourceInfo.itemId;
|
|
473
|
+
const layerId = datasourceInfo.layerId;
|
|
476
474
|
// if we have the url and the layerID and its found prioritize it first
|
|
477
475
|
// else if we find the maps layer id prioritze it first
|
|
478
|
-
|
|
476
|
+
let layerUrlTest;
|
|
479
477
|
if (url && !isNaN(layerId)) {
|
|
480
478
|
layerUrlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
|
|
481
479
|
}
|
|
@@ -483,8 +481,8 @@ function _getSortOrder(datasourceInfo, testString) {
|
|
|
483
481
|
return 1;
|
|
484
482
|
}
|
|
485
483
|
else if (datasourceInfo.ids.length > 0) {
|
|
486
|
-
if (datasourceInfo.ids.some(
|
|
487
|
-
|
|
484
|
+
if (datasourceInfo.ids.some(id => {
|
|
485
|
+
const layerMapIdTest = new RegExp(id, "gm");
|
|
488
486
|
return layerMapIdTest.test(testString);
|
|
489
487
|
})) {
|
|
490
488
|
return 1;
|
|
@@ -493,14 +491,14 @@ function _getSortOrder(datasourceInfo, testString) {
|
|
|
493
491
|
// if neither full layer url or map layer id are found...check to see if we can
|
|
494
492
|
// find the base service url
|
|
495
493
|
if (url) {
|
|
496
|
-
|
|
494
|
+
const serviceUrlTest = new RegExp(url, "gm");
|
|
497
495
|
if (serviceUrlTest.test(testString)) {
|
|
498
496
|
return 2;
|
|
499
497
|
}
|
|
500
498
|
}
|
|
501
499
|
// if none of the above see if we can find an AGOL item id reference
|
|
502
500
|
if (itemId) {
|
|
503
|
-
|
|
501
|
+
const itemIdTest = new RegExp(itemId, "gm");
|
|
504
502
|
if (itemIdTest.test(testString)) {
|
|
505
503
|
return 3;
|
|
506
504
|
}
|
|
@@ -519,16 +517,16 @@ exports._getSortOrder = _getSortOrder;
|
|
|
519
517
|
* @returns An updated instance of the dataSource or widget with as many field references templatized as possible.
|
|
520
518
|
*/
|
|
521
519
|
function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
520
|
+
const objString = JSON.stringify(obj);
|
|
521
|
+
const hasDatasources = datasourceInfos.filter(ds => {
|
|
522
|
+
let urlTest;
|
|
525
523
|
if (ds.url && !isNaN(ds.layerId)) {
|
|
526
524
|
urlTest = new RegExp(ds.url.replace(/[.]/, ".layer" + ds.layerId + "."), "gm");
|
|
527
525
|
}
|
|
528
|
-
|
|
526
|
+
let hasMapLayerId = false;
|
|
529
527
|
if (ds.ids.length > 0) {
|
|
530
|
-
hasMapLayerId = ds.ids.some(
|
|
531
|
-
|
|
528
|
+
hasMapLayerId = ds.ids.some(id => {
|
|
529
|
+
const idTest = new RegExp(id, "gm");
|
|
532
530
|
return idTest.test(objString);
|
|
533
531
|
});
|
|
534
532
|
}
|
|
@@ -537,12 +535,12 @@ function _prioritizedTests(obj, datasourceInfos, templatizeKeys) {
|
|
|
537
535
|
}
|
|
538
536
|
});
|
|
539
537
|
if (hasDatasources.length > 0) {
|
|
540
|
-
hasDatasources.forEach(
|
|
538
|
+
hasDatasources.forEach(ds => {
|
|
541
539
|
// specific url reference is the most common
|
|
542
540
|
obj = _templatizeParentByURL(obj, ds, templatizeKeys);
|
|
543
541
|
if (ds.ids.length > 0) {
|
|
544
542
|
// the second most common is to use the layerId from the webmap
|
|
545
|
-
ds.ids.forEach(
|
|
543
|
+
ds.ids.forEach(id => {
|
|
546
544
|
obj = _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys);
|
|
547
545
|
});
|
|
548
546
|
}
|
|
@@ -561,20 +559,20 @@ exports._prioritizedTests = _prioritizedTests;
|
|
|
561
559
|
* @returns The updated instance of the object with as many field references templatized as possible
|
|
562
560
|
*/
|
|
563
561
|
function _templatizeParentByURL(obj, ds, templatizeKeys) {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
562
|
+
let clone = {};
|
|
563
|
+
const url = ds.url;
|
|
564
|
+
const layerId = ds.layerId;
|
|
565
|
+
let urlTest;
|
|
568
566
|
if (url && !isNaN(layerId)) {
|
|
569
567
|
urlTest = new RegExp(url.replace(/[.]/, ".layer" + layerId + "."), "gm");
|
|
570
568
|
}
|
|
571
569
|
if (Array.isArray(obj)) {
|
|
572
|
-
clone = obj.map(
|
|
570
|
+
clone = obj.map(c => {
|
|
573
571
|
return _templatizeParentByURL(c, ds, templatizeKeys);
|
|
574
572
|
});
|
|
575
573
|
}
|
|
576
574
|
else if (typeof obj === "object") {
|
|
577
|
-
for (
|
|
575
|
+
for (const i in obj) {
|
|
578
576
|
if (obj[i] != null && typeof obj[i] === "object") {
|
|
579
577
|
clone[i] = _templatizeParentByURL(obj[i], ds, templatizeKeys);
|
|
580
578
|
}
|
|
@@ -603,21 +601,21 @@ exports._templatizeParentByURL = _templatizeParentByURL;
|
|
|
603
601
|
* @returns The updated instance of the object with as many field references templatized as possible
|
|
604
602
|
*/
|
|
605
603
|
function _templatizeParentByWebMapLayerId(obj, ds, id, templatizeKeys) {
|
|
606
|
-
|
|
607
|
-
|
|
604
|
+
let clone = {};
|
|
605
|
+
const idTest = new RegExp(id, "gm");
|
|
608
606
|
if (Array.isArray(obj)) {
|
|
609
|
-
clone = obj.map(
|
|
607
|
+
clone = obj.map(c => {
|
|
610
608
|
return _templatizeParentByWebMapLayerId(c, ds, id, templatizeKeys);
|
|
611
609
|
});
|
|
612
610
|
}
|
|
613
611
|
else if (typeof obj === "object") {
|
|
614
|
-
for (
|
|
612
|
+
for (const i in obj) {
|
|
615
613
|
if (obj[i] !== null) {
|
|
616
614
|
// In some web application templates they store a stringified version of an object that can
|
|
617
615
|
// contain multiple layer references at a very high level on the main values collection.
|
|
618
616
|
// This was causing many other more typical layer references to be set incorrectly as the first
|
|
619
617
|
// layerId found in this high level string would be used against the main object.
|
|
620
|
-
|
|
618
|
+
let parsedProp;
|
|
621
619
|
try {
|
|
622
620
|
parsedProp = JSON.parse(obj[i]);
|
|
623
621
|
}
|