-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApplicationBase.js
660 lines (660 loc) · 36.4 KB
/
ApplicationBase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
Copyright 2017 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
define(["require", "exports", "./support/configParser", "esri/core/promiseUtils", "esri/identity/IdentityManager", "esri/identity/OAuthInfo", "esri/portal/Portal", "esri/portal/PortalItem", "esri/portal/PortalQueryParams", "esri/config", "esri/intl"], function (require, exports, configParser_1, promiseUtils_1, IdentityManager_1, OAuthInfo_1, Portal_1, PortalItem_1, PortalQueryParams_1, config_1, intl_1) {
"use strict";
IdentityManager_1 = __importDefault(IdentityManager_1);
OAuthInfo_1 = __importDefault(OAuthInfo_1);
Portal_1 = __importDefault(Portal_1);
PortalItem_1 = __importDefault(PortalItem_1);
PortalQueryParams_1 = __importDefault(PortalQueryParams_1);
config_1 = __importDefault(config_1);
var defaultConfig = {
portalUrl: "https://www.arcgis.com",
helperServices: {
geometry: {},
printTask: {},
elevationSync: {},
geocode: []
}
};
var defaultSettings = {
group: {},
portal: {},
urlParams: [],
webMap: {},
webScene: {}
};
var ApplicationBase = /** @class */ (function () {
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
function ApplicationBase(options) {
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
//----------------------------------
// settings
//----------------------------------
this.settings = defaultSettings;
//----------------------------------
// config
//----------------------------------
this.config = defaultConfig;
//----------------------------------
// results
//----------------------------------
this.results = {};
//----------------------------------
// portal
//----------------------------------
this.portal = null;
//----------------------------------
// direction
//----------------------------------
this.direction = null;
//----------------------------------
// locale
//----------------------------------
this.locale = intl_1.getLocale();
//----------------------------------
// units
//----------------------------------
this.units = null;
this.invalidContentOrigin = false;
var config = options.config, settings = options.settings;
var applicationConfig = typeof config === "string"
? JSON.parse(config)
: config;
var applicationBaseSettings = typeof settings === "string"
? JSON.parse(settings)
: settings;
var configMixin = __assign(__assign({}, defaultConfig), applicationConfig);
var settingsMixin = __assign(__assign({}, defaultSettings), applicationBaseSettings);
this._mixinSettingsDefaults(settingsMixin);
this.config = configParser_1.parseConfig(configMixin);
this.settings = settingsMixin;
}
//--------------------------------------------------------------------------
//
// Public Methods
//
//--------------------------------------------------------------------------
ApplicationBase.prototype.queryGroupItems = function (groupId, itemParams, portal) {
return __awaiter(this, void 0, void 0, function () {
var defaultGroup, paramOptions, params, result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!portal || !groupId) {
portal = this.portal;
}
defaultGroup = this.settings.group.default;
groupId = this._getDefaultId(groupId, defaultGroup);
paramOptions = __assign({ query: "group:\"" + groupId + "\" AND -type:\"Code Attachment\"", sortField: "modified", sortOrder: "desc", num: 9, start: 1 }, itemParams);
params = new PortalQueryParams_1.default(paramOptions);
return [4 /*yield*/, portal.queryItems(params)];
case 1:
result = _a.sent();
return [2 /*return*/, result];
}
});
});
};
ApplicationBase.prototype.load = function () {
return __awaiter(this, void 0, void 0, function () {
var settings, groupSettings, portalSettings, webMapSettings, websceneSettings, urlParamsSettings, isEsri, urlParams, esriPortalUrl, _a, portalUrl, proxyUrl, oauthappid, appid, sharingUrl, loadApplicationItem, checkAppAccess, fetchApplicationData, loadPortal;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
settings = this.settings;
groupSettings = settings.group, portalSettings = settings.portal, webMapSettings = settings.webMap, websceneSettings = settings.webScene, urlParamsSettings = settings.urlParams;
return [4 /*yield*/, this._isEnvironmentEsri()];
case 1:
isEsri = _b.sent();
urlParams = configParser_1.parseConfig(this._getUrlParamValues(urlParamsSettings));
this.results.urlParams = urlParams;
this.config = this._mixinAllConfigs({
config: this.config,
url: urlParams
});
if (isEsri) {
esriPortalUrl = this._getEsriEnvironmentPortalUrl();
this.config.portalUrl = esriPortalUrl;
this.config.proxyUrl = this._getEsriEnvironmentProxyUrl(esriPortalUrl);
}
_a = this.config, portalUrl = _a.portalUrl, proxyUrl = _a.proxyUrl, oauthappid = _a.oauthappid, appid = _a.appid;
this._setPortalUrl(portalUrl);
this._setProxyUrl(proxyUrl);
this._registerOauthInfos(oauthappid, portalUrl);
sharingUrl = portalUrl + "/sharing";
loadApplicationItem = appid ? this._loadItem(appid) : promiseUtils_1.resolve();
checkAppAccess = IdentityManager_1.default.checkAppAccess(sharingUrl, oauthappid)
.catch(function (response) { return response; })
.then(function (response) {
return response;
});
fetchApplicationData = appid
? loadApplicationItem.then(function (itemInfo) {
return itemInfo instanceof PortalItem_1.default
? itemInfo.fetchData()
: undefined;
})
: promiseUtils_1.resolve();
loadPortal = portalSettings.fetch ? new Portal_1.default().load() : promiseUtils_1.resolve();
return [2 /*return*/, promiseUtils_1.eachAlways([
loadApplicationItem,
fetchApplicationData,
loadPortal,
checkAppAccess
])
.catch(function (applicationArgs) { return applicationArgs; })
.then(function (applicationArgs) {
var _a, _b;
var applicationItemResponse = applicationArgs[0], applicationDataResponse = applicationArgs[1], portalResponse = applicationArgs[2], checkAppAccessResponse = applicationArgs[3];
var applicationItem = applicationItemResponse
? applicationItemResponse.value
: null;
var applicationData = applicationDataResponse
? applicationDataResponse.value
: null;
var appAccess = checkAppAccessResponse
? checkAppAccessResponse.value
: null;
if (applicationItem &&
applicationItem.access &&
applicationItem.access !== "public") {
// do we have permission to access app
if (appAccess &&
appAccess.name &&
appAccess.name === "identity-manager:not-authorized") {
//identity-manager:not-authorized, identity-manager:not-authenticated, identity-manager:invalid-request
return promiseUtils_1.reject(appAccess.name);
}
}
else if (applicationItemResponse.error) {
return promiseUtils_1.reject(applicationItemResponse.error);
}
// user not signed in and contentOrigin is other.
// If app is within an iframe ignore all of this
var withinFrame = window.location !== window.parent.location;
if (((_a = applicationItem === null || applicationItem === void 0 ? void 0 : applicationItem.sourceJSON) === null || _a === void 0 ? void 0 : _a.contentOrigin) === "other" && !withinFrame) {
if ((appAccess === null || appAccess === void 0 ? void 0 : appAccess.credential) === undefined) {
_this.invalidContentOrigin = true;
}
}
_this.results.applicationItem = applicationItemResponse;
_this.results.applicationData = applicationDataResponse;
var applicationConfig = configParser_1.parseConfig(applicationData
? applicationData.values
: null);
var portal = portalResponse ? portalResponse.value : null;
_this.portal = portal;
// Detect IE 11 and older
_this.isIE = _this._detectIE();
// Update the culture if there is a url param
_this.locale = ((_b = _this.config) === null || _b === void 0 ? void 0 : _b.locale) || intl_1.getLocale();
intl_1.setLocale(_this.locale);
_this.direction = intl_1.prefersRTL(_this.locale) ? "rtl" : "ltr";
_this.units = _this._getUnits(portal);
_this.config = _this._mixinAllConfigs({
config: _this.config,
url: urlParams,
application: applicationConfig
});
_this._setGeometryService(_this.config, portal);
var _c = _this.config, webmap = _c.webmap, webscene = _c.webscene, group = _c.group, draft = _c.draft;
var webMapPromises = [];
var webScenePromises = [];
var groupInfoPromises = [];
var groupItemsPromises = [];
var isWebMapEnabled = webMapSettings.fetch && webmap;
var isWebSceneEnabled = websceneSettings.fetch && webscene;
var isGroupInfoEnabled = groupSettings.fetchInfo && group;
var isGroupItemsEnabled = groupSettings.fetchItems && group;
var itemParams = groupSettings.itemParams;
var defaultWebMap = webMapSettings.default;
var defaultWebScene = websceneSettings.default;
var defaultGroup = groupSettings.default;
var fetchMultipleWebmaps = webMapSettings.fetchMultiple;
var fetchMultipleWebscenes = websceneSettings.fetchMultiple;
var fetchMultipleGroups = groupSettings.fetchMultiple;
var withinConfigExperience = _this._isWithinConfigurationExperience();
if (isWebMapEnabled) {
var maps = (withinConfigExperience && (draft === null || draft === void 0 ? void 0 : draft.webmap)) ? [draft.webmap, webmap] : webmap;
var webMaps = _this._getPropertyArray(maps);
var allowedWebmaps = _this._limitItemSize(webMaps, fetchMultipleWebmaps);
allowedWebmaps.forEach(function (id) {
var webMapId = _this._getDefaultId(id, defaultWebMap);
webMapPromises.push(_this._loadItem(webMapId));
});
}
if (isWebSceneEnabled) {
var scenes = withinConfigExperience && (draft === null || draft === void 0 ? void 0 : draft.webscene) ? [draft.webscene, webscene] : webscene;
var webScenes = _this._getPropertyArray(scenes);
var allowedWebsenes = _this._limitItemSize(webScenes, fetchMultipleWebscenes);
allowedWebsenes.forEach(function (id) {
var webSceneId = _this._getDefaultId(id, defaultWebScene);
webScenePromises.push(_this._loadItem(webSceneId));
});
}
if (isGroupInfoEnabled) {
var draftGroups = withinConfigExperience && (draft === null || draft === void 0 ? void 0 : draft.group) ? [draft.group, group] : group;
var groups = _this._getPropertyArray(draftGroups);
var allowedGroups = _this._limitItemSize(groups, fetchMultipleGroups);
allowedGroups.forEach(function (id) {
var groupId = _this._getDefaultId(id, defaultGroup);
groupInfoPromises.push(_this._queryGroupInfo(groupId, portal));
});
}
if (isGroupItemsEnabled) {
var groups = _this._getPropertyArray(group);
groups.forEach(function (id) {
groupItemsPromises.push(_this.queryGroupItems(id, itemParams, portal));
});
}
var promises = {
webMap: webMapPromises ? promiseUtils_1.eachAlways(webMapPromises) : promiseUtils_1.resolve(),
webScene: webScenePromises ? promiseUtils_1.eachAlways(webScenePromises) : promiseUtils_1.resolve(),
groupInfo: groupInfoPromises
? promiseUtils_1.eachAlways(groupInfoPromises)
: promiseUtils_1.resolve(),
groupItems: groupItemsPromises
? promiseUtils_1.eachAlways(groupItemsPromises)
: promiseUtils_1.resolve()
};
return promiseUtils_1.eachAlways(promises)
.catch(function (itemArgs) { return itemArgs; })
.then(function (itemArgs) {
var webMapResponses = itemArgs.webMap.value;
var webSceneResponses = itemArgs.webScene.value;
var groupInfoResponses = itemArgs.groupInfo.value;
var groupItemsResponses = itemArgs.groupItems.value;
var itemInfo = applicationItem ? applicationItem.itemInfo : null;
_this._overwriteItemsExtent(webMapResponses, itemInfo);
_this._overwriteItemsExtent(webSceneResponses, itemInfo);
_this.results.webMapItems = webMapResponses;
_this.results.webSceneItems = webSceneResponses;
_this.results.groupInfos = groupInfoResponses;
_this.results.groupItems = groupItemsResponses;
// Check and see if we need to evaluate group,maps,scenes
if (!(appAccess === null || appAccess === void 0 ? void 0 : appAccess.credential) && _this.invalidContentOrigin) {
return promiseUtils_1.reject({
appUrl: _this._getAppUrl(),
error: "application:origin-other"
});
}
return _this;
});
})];
}
});
});
};
//--------------------------------------------------------------------------
//
// Private Methods
//
//--------------------------------------------------------------------------
ApplicationBase.prototype._mixinSettingsDefaults = function (settings) {
var userGroupSettings = settings.group;
var userPortalSettings = settings.portal;
var userWebmapSettings = settings.webMap;
var userWebsceneSettings = settings.webScene;
var itemParams = {
sortField: "modified",
sortOrder: "desc",
num: 9,
start: 0
};
settings.group = __assign({ default: "908dd46e749d4565a17d2b646ace7b1a", fetchInfo: true, fetchItems: true, fetchMultiple: true, itemParams: itemParams }, userGroupSettings);
settings.portal = __assign({ fetch: true }, userPortalSettings);
settings.webMap = __assign({ default: "1970c1995b8f44749f4b9b6e81b5ba45", fetch: true, fetchMultiple: true }, userWebmapSettings);
settings.webScene = __assign({ default: "e8f078ba0c1546b6a6e0727f877742a5", fetch: true, fetchMultiple: true }, userWebsceneSettings);
};
ApplicationBase.prototype._limitItemSize = function (items, allowMultiple) {
var firstItem = items[0];
return allowMultiple ? items : firstItem ? [firstItem] : [];
};
ApplicationBase.prototype._getPropertyArray = function (property) {
if (typeof property === "string") {
return property.split(",");
}
if (Array.isArray(property)) {
return property;
}
return [];
};
ApplicationBase.prototype._getEsriEnvironmentPortalUrl = function () {
var pathname = location.pathname;
var esriAppsPath = "/apps/";
var esriHomePath = "/home/";
var esriAppsPathIndex = pathname.indexOf(esriAppsPath);
var esriHomePathIndex = pathname.indexOf(esriHomePath);
var isEsriAppsPath = esriAppsPathIndex !== -1;
var isEsriHomePath = esriHomePathIndex !== -1;
var appLocationIndex = isEsriAppsPath
? esriAppsPathIndex
: isEsriHomePath
? esriHomePathIndex
: undefined;
if (appLocationIndex === undefined) {
return;
}
var portalInstance = pathname.substr(0, appLocationIndex);
var host = location.host;
return "https://" + host + portalInstance;
};
ApplicationBase.prototype._getEsriEnvironmentProxyUrl = function (portalUrl) {
if (!portalUrl) {
return;
}
return portalUrl + "/sharing/proxy";
};
ApplicationBase.prototype._isEnvironmentEsri = function () {
return __awaiter(this, void 0, void 0, function () {
var urlBase, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
urlBase = window.location.origin;
_a = urlBase.indexOf("arcgis.com") !== -1;
if (_a) return [3 /*break*/, 2];
return [4 /*yield*/, this._isPortalServer()];
case 1:
_a = (_b.sent());
_b.label = 2;
case 2: return [2 /*return*/, _a]; // AGO || ArcGIS Portal
}
});
});
};
ApplicationBase.prototype._isPortalServer = function () {
return __awaiter(this, void 0, void 0, function () {
var testingUrl, res, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
testingUrl = this._getEsriEnvironmentPortalUrl() + "/sharing/rest/info";
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, fetch(testingUrl, {
method: 'HEAD'
})];
case 2:
res = _a.sent();
return [2 /*return*/, res.ok];
case 3:
err_1 = _a.sent();
return [2 /*return*/, false];
case 4: return [2 /*return*/];
}
});
});
};
ApplicationBase.prototype._getUnits = function (portal) {
var USRegion = "US";
var USLocale = "en-us";
var user = portal.user;
var userRegion = user && user.region;
var userUnits = user && user.units;
var responseUnits = portal.units;
var responseRegion = portal.region;
var ipCountryCode = portal.ipCntryCode;
var isEnglishUnits = userRegion === USRegion ||
(userRegion && responseRegion === USRegion) ||
(userRegion && !responseRegion) ||
(!user && ipCountryCode === USRegion) ||
(!user && !ipCountryCode && this.locale === USLocale);
var units = userUnits
? userUnits
: responseUnits
? responseUnits
: isEnglishUnits
? "english"
: "metric";
return units;
};
ApplicationBase.prototype._detectIE = function () {
return /*@cc_on!@*/ false || !!document['documentMode'];
};
ApplicationBase.prototype._queryGroupInfo = function (groupId, portal) {
return __awaiter(this, void 0, void 0, function () {
var params;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
params = new PortalQueryParams_1.default({
query: "id:\"" + groupId + "\""
});
return [4 /*yield*/, portal.queryGroups(params)];
case 1: return [2 /*return*/, (_a.sent())];
}
});
});
};
ApplicationBase.prototype._loadItem = function (id) {
var item = new PortalItem_1.default({
id: id
});
return item.load();
};
ApplicationBase.prototype._overwriteItemsExtent = function (responses, applicationItem) {
var _this = this;
if (!responses) {
return;
}
responses.forEach(function (response) {
var value = response.value;
if (value) {
_this._overwriteItemExtent(value, applicationItem);
}
});
};
ApplicationBase.prototype._overwriteItemExtent = function (item, applicationItem) {
if (!item || !applicationItem) {
return;
}
var applicationExtent = applicationItem.extent;
item.extent = applicationExtent ? applicationExtent : item.extent;
};
ApplicationBase.prototype._getDefaultId = function (id, defaultId) {
var defaultUrlParam = "default";
var trimmedId = id ? id.trim() : "";
var useDefaultId = (!trimmedId || trimmedId === defaultUrlParam) && defaultId;
return useDefaultId ? defaultId : id;
};
ApplicationBase.prototype._mixinAllConfigs = function (params) {
var config = params.config || null;
var appConfig = params.application || null;
var localConfig = params.local || null;
var urlConfig = params.url || null;
return __assign(__assign(__assign(__assign({}, config), appConfig), localConfig), urlConfig);
};
ApplicationBase.prototype._setGeometryService = function (config, portal) {
var configHelperServices = config.helperServices;
var anyPortal = portal;
var portalHelperServices = anyPortal && anyPortal.helperServices;
var configGeometryUrl = configHelperServices &&
configHelperServices.geometry &&
configHelperServices.geometry.url;
var portalGeometryUrl = portalHelperServices &&
portalHelperServices.geometry &&
portalHelperServices.geometry.url;
var geometryServiceUrl = portalGeometryUrl || configGeometryUrl;
if (!geometryServiceUrl) {
return;
}
config_1.default.geometryServiceUrl = geometryServiceUrl;
};
ApplicationBase.prototype._setPortalUrl = function (portalUrl) {
if (!portalUrl) {
return;
}
config_1.default.portalUrl = portalUrl;
};
ApplicationBase.prototype._setProxyUrl = function (proxyUrl) {
if (!proxyUrl) {
return;
}
config_1.default.request.proxyUrl = proxyUrl;
};
ApplicationBase.prototype._registerOauthInfos = function (appId, portalUrl) {
if (!appId) {
return;
}
var info = new OAuthInfo_1.default({
appId: appId,
portalUrl: portalUrl
});
if (!info) {
return;
}
IdentityManager_1.default.registerOAuthInfos([info]);
};
ApplicationBase.prototype._getUrlParamValues = function (urlParams) {
var _this = this;
var urlObject = this._urlToObject();
var formattedUrlObject = {};
if (!urlObject || !urlParams || !urlParams.length) {
return;
}
urlParams.forEach(function (param) {
var urlParamValue = urlObject[param];
if (urlParamValue) {
formattedUrlObject[param] = _this._formatUrlParamValue(urlParamValue);
}
});
return formattedUrlObject;
};
ApplicationBase.prototype._urlToObject = function () {
var _this = this;
var query = (window.location.search || "?").substr(1), map = {};
var urlRE = /([^&=]+)=?([^&]*)(?:&+|$)/g;
query.replace(urlRE, function (match, key, value) {
map[key] = _this._stripStringTags(decodeURIComponent(value));
return "";
});
return map;
};
ApplicationBase.prototype._formatUrlParamValue = function (urlParamValue) {
if (typeof urlParamValue !== "string") {
return urlParamValue;
}
var lowerCaseValue = urlParamValue.toLowerCase();
if (lowerCaseValue === "true") {
return true;
}
if (lowerCaseValue === "false") {
return false;
}
return urlParamValue;
};
ApplicationBase.prototype._stripStringTags = function (value) {
var tagsRE = /<\/?[^>]+>/g;
return value.replace(tagsRE, "");
};
ApplicationBase.prototype._getAppUrl = function () {
var location = window.location;
var hostname = location.hostname;
var newOrigin = "//www.arcgis.com";
if (hostname.indexOf("devext.arcgis.com") !== -1) {
newOrigin = "//devext.arcgis.com";
}
else if (hostname.indexOf("qaext.arcgis.com") !== -1) {
newOrigin = "//qaext.arcgis.com";
}
var appurl = "" + location.protocol + newOrigin + location.pathname;
if (location === null || location === void 0 ? void 0 : location.search) {
appurl = "" + appurl + location.search;
}
return appurl;
};
ApplicationBase.prototype._isWithinConfigurationExperience = function () {
var frameElement = window.frameElement, location = window.location, parent = window.parent;
// If frameElement is null, origins between parent and child do not match
return frameElement
? // If origins match, check if parent iframe has data-embed-type="instant-config"
frameElement.getAttribute("data-embed-type") === "instant-config"
? // If so, app is within config experience - use draft values
true
: // Otherwise, it is not within config experience - use publish values
false
: // Origins do not match
// IF TRUE - If parent and child locations do not match, and the location hostnames are local host.
// Use draft values for locally hosted config panel testing
// IF FALSE - template app is embedded on hosted page - use publish values.
location !== parent.location &&
(location.hostname === "localhost" ||
location.hostname === "127.0.0.1");
};
return ApplicationBase;
}());
return ApplicationBase;
});
//# sourceMappingURL=ApplicationBase.js.map