@esri/solutions-components 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/calcite-input-text_5.cjs.entry.js +36 -36
- package/dist/cjs/calcite-shell-panel_14.cjs.entry.js +1 -1
- package/dist/cjs/solution-configuration.cjs.entry.js +1 -1
- package/dist/cjs/solution-contents_3.cjs.entry.js +1 -1
- package/dist/cjs/{solution-store-70002b57.js → solution-store-ca4639d5.js} +3 -3
- package/dist/collection/components/add-record-modal/test/add-record-modal.e2e.js +24 -0
- package/dist/collection/components/add-record-modal/test/add-record-modal.spec.js +32 -0
- package/dist/collection/components/buffer-tools/test/buffer-tools.e2e.js +24 -0
- package/dist/collection/components/buffer-tools/test/buffer-tools.spec.js +157 -0
- package/dist/collection/components/card-manager/test/card-manager.e2e.js +24 -0
- package/dist/collection/components/card-manager/test/card-manager.spec.js +32 -0
- package/dist/collection/components/comment-card/test/comment-card.e2e.js +24 -0
- package/dist/collection/components/comment-card/test/comment-card.spec.js +32 -0
- package/dist/collection/components/crowdsource-manager/test/crowdsource-manager.e2e.js +24 -0
- package/dist/collection/components/crowdsource-manager/test/crowdsource-manager.spec.js +32 -0
- package/dist/collection/components/crowdsource-reporter/test/crowdsource-reporter.e2e.js +24 -0
- package/dist/collection/components/crowdsource-reporter/test/crowdsource-reporter.spec.js +32 -0
- package/dist/collection/components/deduct-calculator/test/deduct-calculator.e2e.js +24 -0
- package/dist/collection/components/deduct-calculator/test/deduct-calculator.spec.js +32 -0
- package/dist/collection/components/edit-record-modal/test/edit-record-modal.e2e.js +24 -0
- package/dist/collection/components/edit-record-modal/test/edit-record-modal.spec.js +32 -0
- package/dist/collection/components/info-card/test/info-card.e2e.js +24 -0
- package/dist/collection/components/info-card/test/info-card.spec.js +32 -0
- package/dist/collection/components/json-editor/test/json-editor.e2e.js +31 -0
- package/dist/collection/components/json-editor/test/json-editor.spec.js +60 -0
- package/dist/collection/components/layer-table/test/layer-table.e2e.js +24 -0
- package/dist/collection/components/layer-table/test/layer-table.spec.js +32 -0
- package/dist/collection/components/list-item/test/list-item.e2e.js +24 -0
- package/dist/collection/components/list-item/test/list-item.spec.js +32 -0
- package/dist/collection/components/map-card/test/map-card.e2e.js +24 -0
- package/dist/collection/components/map-card/test/map-card.spec.js +32 -0
- package/dist/collection/components/map-draw-tools/test/map-draw-tools.e2e.js +24 -0
- package/dist/collection/components/map-draw-tools/test/map-draw-tools.spec.js +32 -0
- package/dist/collection/components/map-layer-picker/test/map-layer-picker.e2e.js +24 -0
- package/dist/collection/components/map-layer-picker/test/map-layer-picker.spec.js +109 -0
- package/dist/collection/components/map-search/test/map-search.e2e.js +24 -0
- package/dist/collection/components/map-search/test/map-search.spec.js +53 -0
- package/dist/collection/components/map-select-tools/map-select-tools.js +36 -36
- package/dist/collection/components/map-select-tools/test/map-select-tools.e2e.js +24 -0
- package/dist/collection/components/map-select-tools/test/map-select-tools.spec.js +349 -0
- package/dist/collection/components/media-card/test/media-card.e2e.js +24 -0
- package/dist/collection/components/media-card/test/media-card.spec.js +32 -0
- package/dist/collection/components/pci-calculator/test/pci-calculator.e2e.js +24 -0
- package/dist/collection/components/pci-calculator/test/pci-calculator.spec.js +32 -0
- package/dist/collection/components/pdf-download/test/pdf-download.e2e.js +71 -0
- package/dist/collection/components/pdf-download/test/pdf-download.spec.js +104 -0
- package/dist/collection/components/public-notification/test/public-notification.e2e.js +95 -0
- package/dist/collection/components/public-notification/test/public-notification.spec.js +149 -0
- package/dist/collection/components/refine-selection/refine-selection.css +85 -85
- package/dist/collection/components/solution-configuration/test/solution-configuration.e2e.js +31 -0
- package/dist/collection/components/solution-configuration/test/solution-configuration.spec.js +114 -0
- package/dist/collection/components/solution-contents/test/solution-contents.e2e.js +89 -0
- package/dist/collection/components/solution-contents/test/solution-contents.spec.js +138 -0
- package/dist/collection/components/solution-item/test/solution-item.e2e.js +31 -0
- package/dist/collection/components/solution-item/test/solution-item.spec.js +72 -0
- package/dist/collection/components/solution-item-details/test/solution-item-details.e2e.js +31 -0
- package/dist/collection/components/solution-item-details/test/solution-item-details.spec.js +137 -0
- package/dist/collection/components/solution-item-icon/test/solution-item-icon.e2e.js +24 -0
- package/dist/collection/components/solution-item-icon/test/solution-item-icon.spec.js +34 -0
- package/dist/collection/components/solution-item-sharing/test/solution-item-sharing.e2e.js +31 -0
- package/dist/collection/components/solution-item-sharing/test/solution-item-sharing.spec.js +49 -0
- package/dist/collection/components/solution-organization-variables/test/solution-organization-variables.e2e.js +31 -0
- package/dist/collection/components/solution-organization-variables/test/solution-organization-variables.spec.js +60 -0
- package/dist/collection/components/solution-resource-item/test/solution-resource-item.e2e.js +31 -0
- package/dist/collection/components/solution-resource-item/test/solution-resource-item.spec.js +50 -0
- package/dist/collection/components/solution-spatial-ref/test/solution-spatial-ref.e2e.js +31 -0
- package/dist/collection/components/solution-spatial-ref/test/solution-spatial-ref.spec.js +170 -0
- package/dist/collection/components/solution-template-data/test/solution-template-data.e2e.js +31 -0
- package/dist/collection/components/solution-template-data/test/solution-template-data.spec.js +55 -0
- package/dist/collection/components/solution-variables/test/solution-variables.e2e.js +31 -0
- package/dist/collection/components/solution-variables/test/solution-variables.spec.js +126 -0
- package/dist/collection/utils/publicNotificationUtils.js +45 -0
- package/dist/collection/utils/templates.e2e.js +25 -0
- package/dist/collection/utils/test/csvUtils.spec.js +46 -0
- package/dist/collection/utils/test/downloadUtils.spec.js +102 -0
- package/dist/collection/utils/test/pciUtils.spec.js +297 -0
- package/dist/collection/utils/test/solution-store.spec.js +439 -0
- package/dist/components/map-select-tools2.js +36 -36
- package/dist/components/solution-store.js +3 -3
- package/dist/esm/calcite-input-text_5.entry.js +36 -36
- package/dist/esm/calcite-shell-panel_14.entry.js +1 -1
- package/dist/esm/solution-configuration.entry.js +1 -1
- package/dist/esm/solution-contents_3.entry.js +1 -1
- package/dist/esm/{solution-store-5d068b07.js → solution-store-70f874f8.js} +3 -3
- package/dist/solutions-components/{p-41802f6b.entry.js → p-16dfb254.entry.js} +1 -1
- package/dist/solutions-components/{p-4769a2a5.entry.js → p-5ed755a2.entry.js} +1 -1
- package/dist/solutions-components/{p-826a814d.js → p-78719506.js} +2 -2
- package/dist/solutions-components/{p-9f620303.entry.js → p-b4b19fd3.entry.js} +1 -1
- package/dist/solutions-components/{p-24fe6e1c.entry.js → p-d5d5942d.entry.js} +1 -1
- package/dist/solutions-components/solutions-components.esm.js +1 -1
- package/dist/solutions-components/utils/common.js +291 -0
- package/dist/solutions-components/utils/csvDownload.js +36 -0
- package/dist/solutions-components/utils/csvUtils.js +32 -0
- package/dist/solutions-components/utils/downloadUtils.js +386 -0
- package/dist/solutions-components/utils/interfaces.js +56 -0
- package/dist/solutions-components/utils/languageUtil.js +85 -0
- package/dist/solutions-components/utils/loadModules.js +20 -0
- package/dist/solutions-components/utils/locale.js +56 -0
- package/dist/solutions-components/utils/mapViewUtils.js +140 -0
- package/dist/solutions-components/utils/pciUtils.js +837 -0
- package/dist/solutions-components/utils/pdfUtils.js +62 -0
- package/dist/solutions-components/utils/publicNotificationStore.js +38 -0
- package/dist/solutions-components/utils/publicNotificationUtils.js +45 -0
- package/dist/solutions-components/utils/queryUtils.js +148 -0
- package/dist/solutions-components/utils/solution-store.js +579 -0
- package/dist/solutions-components/utils/templates.e2e.js +25 -0
- package/dist/solutions-components/utils/templates.js +341 -0
- package/dist/solutions-components/utils/test/csvUtils.spec.js +46 -0
- package/dist/solutions-components/utils/test/downloadUtils.spec.js +102 -0
- package/dist/solutions-components/utils/test/mocks/jsApi.js +74 -0
- package/dist/solutions-components/utils/test/pciUtils.spec.js +297 -0
- package/dist/solutions-components/utils/test/solution-store.spec.js +439 -0
- package/dist/solutions-components/utils/test/testUtils.js +135 -0
- package/dist/solutions-components/utils/types.js +14 -0
- package/dist/solutions-components_commit.txt +7 -0
- package/package.json +7 -7
@@ -0,0 +1,291 @@
|
|
1
|
+
/** @license
|
2
|
+
* Copyright 2022 Esri
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
/*
|
17
|
+
| Helper functions from solutions-common
|
18
|
+
*/
|
19
|
+
import { convertItemResourceToStorageResource, EFileType, updateItem, SolutionTemplateFormatVersion } from "@esri/solution-common";
|
20
|
+
import { EUpdateType } from "./interfaces";
|
21
|
+
import { addItemResource, removeItemResource, updateItemResource } from "@esri/arcgis-rest-portal";
|
22
|
+
/**
|
23
|
+
* Get an array from a list of nodes
|
24
|
+
*
|
25
|
+
* @param nodeList list of nodes
|
26
|
+
*
|
27
|
+
* @returns array of nodes
|
28
|
+
*/
|
29
|
+
export function nodeListToArray(nodeList) {
|
30
|
+
return Array.isArray(nodeList) ? nodeList : Array.from(nodeList);
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* Saves any updated templates to the current solution item
|
34
|
+
*
|
35
|
+
* @param templates the updated templates array
|
36
|
+
* @param thumbnailurl url for the items thumbnail
|
37
|
+
* @param id for the solution item
|
38
|
+
* @param data the current solution items data
|
39
|
+
* @param authentication credentials for the request
|
40
|
+
* @param translations translated strings for messages
|
41
|
+
*
|
42
|
+
* @returns a promise that will resolve with a success true/false response
|
43
|
+
*/
|
44
|
+
export async function save(id, data, models, authentication, translations) {
|
45
|
+
const itemInfo = { id };
|
46
|
+
const params = {
|
47
|
+
text: data
|
48
|
+
};
|
49
|
+
await _updateResources(id, models, data, authentication);
|
50
|
+
// TODO compare data with the source data in the model...should be able to
|
51
|
+
// understand if it has changes
|
52
|
+
// TODO...only update if has changes
|
53
|
+
const updateResults = await updateItem(itemInfo, authentication, undefined, params);
|
54
|
+
return Promise.resolve({
|
55
|
+
success: updateResults.success,
|
56
|
+
message: updateResults.success ? translations.editsSaved : translations.saveFailed
|
57
|
+
});
|
58
|
+
}
|
59
|
+
/**
|
60
|
+
* Updates the solutions thumbnail and data resources
|
61
|
+
*
|
62
|
+
* @param solutionId id for the solution
|
63
|
+
* @param models the models for the solutions templates
|
64
|
+
* @param data the current data object for the solution
|
65
|
+
* @param authentication credentials for the request
|
66
|
+
*
|
67
|
+
* @returns a promise that will resolve with response results
|
68
|
+
*/
|
69
|
+
export async function _updateResources(solutionId, models, data, authentication) {
|
70
|
+
return new Promise((resolve, reject) => {
|
71
|
+
const promises = [];
|
72
|
+
Object.keys(models).forEach(itemId => {
|
73
|
+
const model = models[itemId];
|
74
|
+
promises.push(_updateThumbnailResource(solutionId, model, data, authentication));
|
75
|
+
_updateFileResources(solutionId, model, data, promises, authentication);
|
76
|
+
});
|
77
|
+
if (promises.length > 0) {
|
78
|
+
Promise.all(promises).then(resolve, reject);
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
resolve({ success: true });
|
82
|
+
}
|
83
|
+
});
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* Updates the solutions thumbnail and data resources
|
87
|
+
*
|
88
|
+
* @param solutionId id for the solution
|
89
|
+
* @param model the model for the current solution template
|
90
|
+
* @param authentication credentials for the request
|
91
|
+
*
|
92
|
+
* @returns a promise that will resolve with response results
|
93
|
+
*/
|
94
|
+
function _updateThumbnailResource(solutionId, model, data, authentication) {
|
95
|
+
return new Promise((resolve, reject) => {
|
96
|
+
if (model.thumbnailNew) {
|
97
|
+
if (model.thumbnailOrigin) {
|
98
|
+
const name = model.thumbnailOrigin.name;
|
99
|
+
const opts = {
|
100
|
+
id: solutionId,
|
101
|
+
authentication,
|
102
|
+
resource: model.thumbnailNew,
|
103
|
+
name
|
104
|
+
};
|
105
|
+
const resources = model.resources.filter(r => r.endsWith(name));
|
106
|
+
if (resources.length === 1) {
|
107
|
+
const nameParts = resources[0].split("/");
|
108
|
+
if (nameParts.length === 2) {
|
109
|
+
opts.prefix = nameParts[0];
|
110
|
+
}
|
111
|
+
}
|
112
|
+
updateItemResource(opts).then(resolve, reject);
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
// if the item does not have an origin thumb we need to add rather than update
|
116
|
+
const resourceFilePath = {
|
117
|
+
type: EFileType.Thumbnail,
|
118
|
+
folder: null,
|
119
|
+
filename: model.thumbnailNew.name,
|
120
|
+
url: "",
|
121
|
+
blob: model.thumbnailNew,
|
122
|
+
updateType: EUpdateType.Add
|
123
|
+
};
|
124
|
+
_add(solutionId, model, data, resourceFilePath, authentication, true).then(resolve, reject);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
resolve({ success: true });
|
129
|
+
}
|
130
|
+
});
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Updates the solutions data resources
|
134
|
+
*
|
135
|
+
* This function will update the provided promises argument by adding add/remove/update promises
|
136
|
+
*
|
137
|
+
* @param solutionId id for the solution
|
138
|
+
* @param model the model for the current solution template
|
139
|
+
* @param data the current data object for the solution
|
140
|
+
* @param promises list of add/remove/update promises
|
141
|
+
* @param authentication credentials for the request
|
142
|
+
*/
|
143
|
+
function _updateFileResources(solutionId, model, data, promises, authentication) {
|
144
|
+
// add/remove/update resources
|
145
|
+
model.resourceFilePaths.forEach(resourceFilePath => {
|
146
|
+
switch (resourceFilePath.updateType) {
|
147
|
+
case EUpdateType.Add:
|
148
|
+
promises.push(_add(solutionId, model, data, resourceFilePath, authentication));
|
149
|
+
break;
|
150
|
+
case EUpdateType.Remove:
|
151
|
+
promises.push(_remove(solutionId, model, data, resourceFilePath, authentication));
|
152
|
+
break;
|
153
|
+
case EUpdateType.Update:
|
154
|
+
promises.push(_update(solutionId, model, resourceFilePath, authentication));
|
155
|
+
break;
|
156
|
+
default:
|
157
|
+
break;
|
158
|
+
}
|
159
|
+
});
|
160
|
+
}
|
161
|
+
/**
|
162
|
+
* Generates add resource request
|
163
|
+
*
|
164
|
+
* @param solutionId id for the solution
|
165
|
+
* @param model the model for the current solution template
|
166
|
+
* @param data the current data object for the solution
|
167
|
+
* @param resourceFilePath resource file info
|
168
|
+
* @param authentication credentials for the request
|
169
|
+
*
|
170
|
+
* @returns a promise that will resolve to a response with success true/false
|
171
|
+
*/
|
172
|
+
function _add(solutionId, model, data, resourceFilePath, authentication, isThumbnail = false) {
|
173
|
+
return new Promise((resolve, reject) => {
|
174
|
+
const storageName = convertItemResourceToStorageResource(model.itemId + isThumbnail.toString() ? "_info_thumbnail" :
|
175
|
+
(resourceFilePath.blob.name === resourceFilePath.filename
|
176
|
+
? "_info_data"
|
177
|
+
: "_info_dataz"), resourceFilePath.blob.name, SolutionTemplateFormatVersion);
|
178
|
+
const opts = {
|
179
|
+
id: solutionId,
|
180
|
+
authentication,
|
181
|
+
resource: resourceFilePath.blob,
|
182
|
+
name: storageName.filename,
|
183
|
+
params: {}
|
184
|
+
};
|
185
|
+
if (storageName.folder) {
|
186
|
+
opts.params = {
|
187
|
+
resourcesPrefix: storageName.folder
|
188
|
+
};
|
189
|
+
}
|
190
|
+
addItemResource(opts).then(results => {
|
191
|
+
var _a;
|
192
|
+
if (results.success) {
|
193
|
+
_updateTemplateResourcePaths(data, model.itemId, EUpdateType.Add, ((_a = opts.params) === null || _a === void 0 ? void 0 : _a.resourcesPrefix) ? `${opts.params.resourcesPrefix}/${opts.name}` : opts.name, "");
|
194
|
+
}
|
195
|
+
resolve(results);
|
196
|
+
}, reject);
|
197
|
+
});
|
198
|
+
}
|
199
|
+
/**
|
200
|
+
* Generates add resource request
|
201
|
+
*
|
202
|
+
* @param solutionId id for the solution
|
203
|
+
* @param model the model for the current solution template
|
204
|
+
* @param data the current data object for the solution
|
205
|
+
* @param resourceFilePath resource file info
|
206
|
+
* @param authentication credentials for the request
|
207
|
+
*
|
208
|
+
* @returns a promise that will resolve to a response with success true/false
|
209
|
+
*/
|
210
|
+
function _remove(solutionId, model, data, resourceFilePath, authentication) {
|
211
|
+
return new Promise((resolve, reject) => {
|
212
|
+
const name = resourceFilePath.filename;
|
213
|
+
const resources = model.resources.filter(r => r.endsWith(name));
|
214
|
+
if (resources.length > 0) {
|
215
|
+
const opts = {
|
216
|
+
id: solutionId,
|
217
|
+
authentication,
|
218
|
+
resource: resources[0]
|
219
|
+
};
|
220
|
+
removeItemResource(opts).then(results => {
|
221
|
+
if (results.success) {
|
222
|
+
_updateTemplateResourcePaths(data, model.itemId, EUpdateType.Remove, resources[0], "");
|
223
|
+
}
|
224
|
+
resolve(results);
|
225
|
+
}, reject);
|
226
|
+
}
|
227
|
+
else {
|
228
|
+
resolve({ success: false });
|
229
|
+
}
|
230
|
+
});
|
231
|
+
}
|
232
|
+
/**
|
233
|
+
* Generates update resource request
|
234
|
+
*
|
235
|
+
* @param solutionId id for the solution
|
236
|
+
* @param model the model for the current solution template
|
237
|
+
* @param resourceFilePath resource file info
|
238
|
+
* @param authentication credentials for the request
|
239
|
+
*
|
240
|
+
* @returns a promise that will resolve to a response with success true/false
|
241
|
+
*/
|
242
|
+
function _update(solutionId, model, resourceFilePath, authentication) {
|
243
|
+
const sourceFileName = resourceFilePath.sourceFileName;
|
244
|
+
const opts = {
|
245
|
+
id: solutionId,
|
246
|
+
authentication,
|
247
|
+
resource: resourceFilePath.blob,
|
248
|
+
name: sourceFileName
|
249
|
+
};
|
250
|
+
const resources = model.resources.filter(r => r.endsWith(sourceFileName));
|
251
|
+
if (resources.length === 1) {
|
252
|
+
const nameParts = resources[0].split("/");
|
253
|
+
if (nameParts.length === 2) {
|
254
|
+
opts.prefix = nameParts[0];
|
255
|
+
}
|
256
|
+
}
|
257
|
+
return updateItemResource(opts);
|
258
|
+
}
|
259
|
+
/**
|
260
|
+
* Update the resources paths for a given template
|
261
|
+
*
|
262
|
+
* This function will update the provided data argument with any new or removed resource paths
|
263
|
+
*
|
264
|
+
* @param data the current data object for the solution
|
265
|
+
* @param id the id of the current template
|
266
|
+
* @param updateType add/update/remove
|
267
|
+
* @param path the resource prefix/name
|
268
|
+
* @param sourceFileName from the current resourceFilePath
|
269
|
+
*
|
270
|
+
*/
|
271
|
+
function _updateTemplateResourcePaths(data, id, updateType, path, sourceFileName) {
|
272
|
+
data.templates = data.templates.map(t => {
|
273
|
+
if (t.itemId === id) {
|
274
|
+
switch (updateType) {
|
275
|
+
case EUpdateType.Add:
|
276
|
+
t.resources.push(path);
|
277
|
+
break;
|
278
|
+
case EUpdateType.Update:
|
279
|
+
t.resources = t.resources.filter(r => r.indexOf(sourceFileName) < 0);
|
280
|
+
t.resources.push(path);
|
281
|
+
break;
|
282
|
+
case EUpdateType.Remove:
|
283
|
+
t.resources = t.resources.filter(r => r.indexOf(path) < 0);
|
284
|
+
break;
|
285
|
+
default:
|
286
|
+
break;
|
287
|
+
}
|
288
|
+
}
|
289
|
+
return t;
|
290
|
+
});
|
291
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/** @license
|
2
|
+
* Copyright 2022 Esri
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
//#region Public functions
|
17
|
+
/**
|
18
|
+
* Download the CSV file
|
19
|
+
*
|
20
|
+
* @param title Title (without file extension) to use for file; defaults to "export"
|
21
|
+
* @param outputLines Lines of output to write to file
|
22
|
+
*
|
23
|
+
* @see {@link https://medium.com/@danny.pule/export-json-to-csv-file-using-javascript-a0b7bc5b00d2}
|
24
|
+
*/
|
25
|
+
export function downloadCSVFile(title, outputLines) {
|
26
|
+
const link = document.createElement("a");
|
27
|
+
if (link.download !== undefined) {
|
28
|
+
link.href = URL.createObjectURL(new Blob(outputLines, { type: "text/csv;charset=utf-8;" }));
|
29
|
+
link.download = `${title}.csv` || "export.csv";
|
30
|
+
link.style.visibility = "hidden";
|
31
|
+
document.body.appendChild(link);
|
32
|
+
link.click();
|
33
|
+
document.body.removeChild(link);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
//#endregion
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/** @license
|
2
|
+
* Copyright 2022 Esri
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
//#region Declarations
|
17
|
+
import * as csvDownload from "./csvDownload";
|
18
|
+
//#endregion
|
19
|
+
//#region Public functions
|
20
|
+
/**
|
21
|
+
* Export a csv of the attributes from the features that match the provided ids
|
22
|
+
*
|
23
|
+
* @param filename Name to use for file
|
24
|
+
* @param labels Labels to write
|
25
|
+
*/
|
26
|
+
export function exportCSV(filename, labels) {
|
27
|
+
// Format values to string so it doesn't get tripped up when a value has a comma
|
28
|
+
// another option could be to export with a different delimiter
|
29
|
+
const outputLines = labels.map(label => Object.values(label).map(v => `"${v}"`).join(",") + "\r\n");
|
30
|
+
csvDownload.downloadCSVFile(filename, outputLines);
|
31
|
+
}
|
32
|
+
//#endregion
|