@esri/solutions-components 0.7.31 → 0.7.32

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.
@@ -5,9 +5,9 @@
5
5
  */
6
6
  import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
7
7
  import { l as loadModules } from './loadModules.js';
8
- import { g as getLayerOrTable } from './mapViewUtils.js';
8
+ import { a as getAllLayers } from './mapViewUtils.js';
9
9
 
10
- const createFeatureCss = ":host{display:block}.esri-editor__panel-toolbar{display:none !important}";
10
+ const createFeatureCss = ":host{display:block}.esri-editor__panel-toolbar{display:none !important}.esri-editor__update-actions{display:none !important}.esri-editor__panel-content{padding-block:0px !important}.esri-editor .esri-item-list__group__header{display:none !important}.esri-editor__panel-content__section .esri-widget__heading{display:none !important}.esri-editor .esri-item-list__filter-container--sticky{padding-block:0px !important;padding-inline:10px !important}";
11
11
 
12
12
  const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature extends HTMLElement {
13
13
  constructor() {
@@ -16,8 +16,10 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
16
16
  this.success = createEvent(this, "success", 7);
17
17
  this.fail = createEvent(this, "fail", 7);
18
18
  this.drawComplete = createEvent(this, "drawComplete", 7);
19
+ this.editingAttachment = createEvent(this, "editingAttachment", 7);
19
20
  this.mapView = undefined;
20
21
  this.selectedLayerId = undefined;
22
+ this.customizeSubmit = false;
21
23
  }
22
24
  //--------------------------------------------------------------------------
23
25
  //
@@ -88,18 +90,8 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
88
90
  * Init Editor widget and starts the create workflow
89
91
  */
90
92
  async init() {
91
- if (this.mapView) {
92
- if (this.mapView && this.selectedLayerId) {
93
- await getLayerOrTable(this.mapView, this.selectedLayerId);
94
- await this.createEditorWidget();
95
- await this.startCreate();
96
- this._editor.viewModel.featureFormViewModel.on('submit', this.submitted.bind(this));
97
- setTimeout(() => {
98
- var _a, _b;
99
- this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')[1].shadowRoot.querySelector('calcite-panel').shadowRoot.querySelector('article').querySelector('header').setAttribute('style', 'display: none');
100
- (_b = (_a = this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')[1].shadowRoot.querySelector('calcite-panel').shadowRoot.querySelector('article')) === null || _a === void 0 ? void 0 : _a.querySelector('footer')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'display: none');
101
- }, 700);
102
- }
93
+ if (this.mapView && this.selectedLayerId) {
94
+ await this.createEditorWidget();
103
95
  }
104
96
  }
105
97
  /**
@@ -108,10 +100,12 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
108
100
  * @protected
109
101
  */
110
102
  async initModules() {
111
- const [Editor] = await loadModules([
112
- "esri/widgets/Editor"
103
+ const [Editor, reactiveUtils] = await loadModules([
104
+ "esri/widgets/Editor",
105
+ "esri/core/reactiveUtils"
113
106
  ]);
114
107
  this.Editor = Editor;
108
+ this.reactiveUtils = reactiveUtils;
115
109
  }
116
110
  /**
117
111
  * Display editor widget to create the new feature
@@ -121,51 +115,105 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
121
115
  if (this._editor) {
122
116
  this._editor.destroy();
123
117
  }
118
+ const layerInfos = [];
124
119
  const container = document.createElement("div");
125
- const layer = await getLayerOrTable(this.mapView, this.selectedLayerId);
126
- const selectedLayer = {
127
- layer: layer
128
- };
120
+ const allMapLayers = await getAllLayers(this.mapView);
121
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
122
+ allMapLayers.forEach(async (eachLayer) => {
123
+ layerInfos.push({
124
+ layer: eachLayer,
125
+ enabled: (eachLayer === null || eachLayer === void 0 ? void 0 : eachLayer.type) === "feature" && (eachLayer === null || eachLayer === void 0 ? void 0 : eachLayer.id) === this.selectedLayerId,
126
+ addEnabled: true,
127
+ updateEnabled: false,
128
+ deleteEnabled: false // default is true, set to false to disable the ability to delete features
129
+ });
130
+ });
129
131
  this._editor = new this.Editor({
130
132
  allowedWorkflows: "create-features",
131
133
  view: this.mapView,
132
- layerInfos: [selectedLayer],
134
+ layerInfos: layerInfos,
133
135
  visibleElements: {
134
- snappingControls: false,
135
- snappingControlsElements: {
136
- featureEnabledToggle: false,
137
- layerList: false,
138
- enabledToggle: false
139
- }
136
+ snappingControls: false
140
137
  },
141
- container,
138
+ container
142
139
  });
143
140
  this.el.appendChild(container);
141
+ //Add handle to watch if attachments are added/edited
142
+ const attachmentHandle = this.reactiveUtils.watch(() => this._editor.viewModel.state, (state) => {
143
+ if (state === 'adding-attachment' || state === 'editing-attachment') {
144
+ this._addingAttachment = true;
145
+ this.editingAttachment.emit(true);
146
+ }
147
+ else {
148
+ if (this._addingAttachment) {
149
+ this.editingAttachment.emit(false);
150
+ this._addingAttachment = false;
151
+ }
152
+ }
153
+ });
154
+ this._editor.viewModel.addHandles(attachmentHandle);
155
+ //Add handle to watch featureTemplatesViewModel ready state and then start the creation
156
+ const handle = this.reactiveUtils.watch(() => this._editor.viewModel.featureTemplatesViewModel.state, (state) => {
157
+ if (state === 'ready') {
158
+ void this.startCreate();
159
+ }
160
+ });
161
+ this._editor.viewModel.addHandles(handle);
144
162
  }
145
163
  /**
146
164
  * Start creating the feature
147
165
  * @protected
148
166
  */
149
167
  async startCreate() {
150
- var _a, _b;
151
- const layer = await getLayerOrTable(this.mapView, this.selectedLayerId);
152
- if (layer) {
153
- let template = layer.templates && layer.templates.length ? layer.templates[0] : {};
154
- if (((_a = layer.sourceJSON) === null || _a === void 0 ? void 0 : _a.types.length) && ((_b = layer.sourceJSON.types[0].templates) === null || _b === void 0 ? void 0 : _b.length)) {
155
- template = layer.sourceJSON.types[0].templates[0];
156
- }
157
- const creationInfo = {
158
- layer: layer,
159
- template: template
160
- };
161
- await this._editor.startCreateFeaturesWorkflowAtFeatureCreation(creationInfo);
162
- this._editor.viewModel.sketchViewModel.on("create", (evt) => {
163
- if (evt.state === "complete") {
164
- this.drawComplete.emit();
165
- }
168
+ var _a;
169
+ if ((_a = this._editor.viewModel.featureTemplatesViewModel.items) === null || _a === void 0 ? void 0 : _a.length) {
170
+ const items = this._editor.viewModel.featureTemplatesViewModel.items[0].get("items");
171
+ //once the feature template is selected handle the event for formSubmit and sketch complete
172
+ //also, hide the headers and footer in the editor as we will be showing our own submit and cancel button
173
+ this._editor.viewModel.featureTemplatesViewModel.on('select', () => {
174
+ setTimeout(() => {
175
+ //on form submit
176
+ this._editor.viewModel.featureFormViewModel.on('submit', this.submitted.bind(this));
177
+ //on sketch complete emit the event
178
+ this._editor.viewModel.sketchViewModel.on("create", (evt) => {
179
+ if (evt.state === "complete") {
180
+ this.drawComplete.emit();
181
+ }
182
+ });
183
+ this.hideEditorsElements();
184
+ }, 700);
185
+ this.hideEditorsElements();
166
186
  });
187
+ //if only one feature template then directly start geometry creation for that
188
+ //else allow feature template selection to user
189
+ if (items.length === 1) {
190
+ this._editor.viewModel.featureTemplatesViewModel.select(items[0]);
191
+ }
192
+ //hides the header and footer elements in editor widget
193
+ this.hideEditorsElements();
167
194
  }
168
195
  }
196
+ /**
197
+ * Hides the elements of editor widget
198
+ * @protected
199
+ */
200
+ hideEditorsElements() {
201
+ if (!this.customizeSubmit) {
202
+ return;
203
+ }
204
+ setTimeout(() => {
205
+ var _a;
206
+ //hides the header and footer on the featureForm
207
+ (_a = this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')) === null || _a === void 0 ? void 0 : _a.forEach((flowItem) => {
208
+ var _a, _b, _c, _d, _e;
209
+ const article = (_c = (_b = (_a = flowItem.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('calcite-panel')) === null || _b === void 0 ? void 0 : _b.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('article');
210
+ //hide the header
211
+ (_d = article === null || article === void 0 ? void 0 : article.querySelector('header')) === null || _d === void 0 ? void 0 : _d.setAttribute('style', 'display: none');
212
+ //hide the footer
213
+ (_e = article === null || article === void 0 ? void 0 : article.querySelector('footer')) === null || _e === void 0 ? void 0 : _e.setAttribute('style', 'display: none');
214
+ });
215
+ }, 700);
216
+ }
169
217
  /**
170
218
  * On creation of feature emit the event that the feature is created
171
219
  * @param evt feature submit event
@@ -173,9 +221,12 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
173
221
  */
174
222
  async submitted(evt) {
175
223
  var _a;
224
+ //return if any attribute is invalid , focus will be shifted to the invalid attribute in feature form
176
225
  if (evt.invalid.length) {
177
226
  return;
178
227
  }
228
+ //Submit only when valid attributes
229
+ //emit success or fail based on the result
179
230
  if (evt.valid.length) {
180
231
  try {
181
232
  await this._editor.activeWorkflow.commit();
@@ -203,6 +254,7 @@ const CreateFeature = /*@__PURE__*/ proxyCustomElement(class CreateFeature exten
203
254
  }, [0, "create-feature", {
204
255
  "mapView": [16],
205
256
  "selectedLayerId": [1, "selected-layer-id"],
257
+ "customizeSubmit": [4, "customize-submit"],
206
258
  "close": [64],
207
259
  "submit": [64]
208
260
  }, undefined, {
@@ -110,6 +110,7 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
110
110
  * @returns Promise when complete
111
111
  */
112
112
  async componentWillLoad() {
113
+ this._urlParamsLoaded = false;
113
114
  await this._initModules();
114
115
  await this._getTranslations();
115
116
  }
@@ -146,6 +147,11 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
146
147
  setSelectedLayer(layerId, layerName) {
147
148
  this._selectedLayerId = layerId;
148
149
  this._selectedLayerName = layerName;
150
+ //show only current layer on map and hide other valid editable layers
151
+ //if layerId is empty then show all the layers on map
152
+ this._validLayers.forEach(layer => {
153
+ layer.set('visible', !layerId || (layer.id === layerId));
154
+ });
149
155
  }
150
156
  /**
151
157
  * Get the reporter app functionality
@@ -202,15 +208,22 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
202
208
  * @protected
203
209
  */
204
210
  getFeatureCreateFlowItem() {
205
- return (h("calcite-flow-item", { collapsed: this.isMobile && this._sidePanelCollapsed, heading: this._selectedLayerName, onCalciteFlowItemBack: this.backFromCreateFeaturePanel.bind(this) }, this.isMobile && this.getActionToExpandCollapsePanel(), this._showSubmitCancelButton && h("div", { class: "width-full", slot: "footer" }, h("calcite-button", { appearance: "secondary", class: "footer-top-button footer-button", onClick: this.onSubmitButtonClick.bind(this), width: "full" }, this._translations.submit), h("calcite-button", { appearance: "outline", class: "footer-button", onClick: this.backFromCreateFeaturePanel.bind(this), width: "full" }, this._translations.cancel)), h("calcite-panel", { "full-height": true, "full-width": true }, h("calcite-notice", { class: "notice-msg", icon: "lightbulb", kind: "success", open: true }, h("div", { slot: "message" }, this._translations.featureEditFormInfoMsg)), h("create-feature", { mapView: this.mapView, onDrawComplete: this.showSubmitCancelButton.bind(this), onFail: this.createFeatureFailed.bind(this), onSuccess: this.navigateHomePage.bind(this), ref: el => this._createFeature = el, selectedLayerId: this._selectedLayerId }))));
211
+ return (h("calcite-flow-item", { collapsed: this.isMobile && this._sidePanelCollapsed, heading: this._selectedLayerName, onCalciteFlowItemBack: this.backFromCreateFeaturePanel.bind(this) }, this.isMobile && this.getActionToExpandCollapsePanel(), this._showSubmitCancelButton && h("div", { class: "width-full", slot: "footer" }, h("calcite-button", { appearance: "secondary", class: "footer-top-button footer-button", onClick: this.onSubmitButtonClick.bind(this), width: "full" }, this._translations.submit), h("calcite-button", { appearance: "outline", class: "footer-button", onClick: this.backFromCreateFeaturePanel.bind(this), width: "full" }, this._translations.cancel)), h("calcite-panel", { "full-height": true, "full-width": true }, h("calcite-notice", { class: "notice-msg", icon: "lightbulb", kind: "success", open: true }, h("div", { slot: "message" }, this._translations.featureEditFormInfoMsg)), h("create-feature", { customizeSubmit: true, mapView: this.mapView, onDrawComplete: this.onDrawComplete.bind(this), onEditingAttachment: this.showSubmitCancelButton.bind(this), onFail: this.createFeatureFailed.bind(this), onSuccess: this.onReportSubmitted.bind(this), ref: el => this._createFeature = el, selectedLayerId: this._selectedLayerId }))));
206
212
  }
207
213
  /**
208
214
  * When drawing of incident location completed on map show the submit and cancel button
209
215
  * @protected
210
216
  */
211
- showSubmitCancelButton() {
217
+ onDrawComplete() {
212
218
  this._showSubmitCancelButton = true;
213
219
  }
220
+ /**
221
+ * When Add attachment panel is enabled hide the submit and cancel button
222
+ * @protected
223
+ */
224
+ showSubmitCancelButton(evt) {
225
+ this._showSubmitCancelButton = !evt.detail;
226
+ }
214
227
  /**
215
228
  * On back from create feature, call submit editor to destroy the Editor widget instance
216
229
  * @protected
@@ -243,11 +256,22 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
243
256
  * On submit report navigate to the layer list home page and refresh the layer list
244
257
  * @protected
245
258
  */
246
- navigateHomePage() {
259
+ onReportSubmitted() {
247
260
  this._reportSubmitted = true;
261
+ this.navigateToHomePage();
262
+ }
263
+ /**
264
+ * Navigates to layer-list
265
+ * @protected
266
+ */
267
+ navigateToHomePage() {
268
+ if (this._createFeature) {
269
+ this._createFeature.close();
270
+ }
248
271
  if (this._layerList) {
249
272
  this._layerList.refresh();
250
273
  }
274
+ this.setSelectedFeatures([]);
251
275
  this._flowItems = ["layer-list"];
252
276
  }
253
277
  /**
@@ -293,7 +317,10 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
293
317
  //update the has valid layer state
294
318
  this._hasValidLayers = layersListed.length > 0;
295
319
  //navigate to the feature details if URL params found
296
- await this.loadFeatureFromURLParams();
320
+ if (!this._urlParamsLoaded) {
321
+ this._urlParamsLoaded = true;
322
+ await this.loadFeatureFromURLParams();
323
+ }
297
324
  }
298
325
  /**On click of layer list item show feature list
299
326
  * @param evt Event which has details of selected layerId and layerName
@@ -310,10 +337,10 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
310
337
  backFromSelectedPanel() {
311
338
  const updatedFlowItems = [...this._flowItems];
312
339
  updatedFlowItems.pop();
313
- //clear the selected layer and feature when back to layer list
340
+ //Back to layer list, and return as the flowItems will be reset in navigateToHomePage
314
341
  if (updatedFlowItems.length === 1) {
315
- this.setSelectedLayer('', '');
316
- this.setSelectedFeatures([]);
342
+ this.navigateToHomePage();
343
+ return;
317
344
  }
318
345
  this._flowItems = [...updatedFlowItems];
319
346
  }
@@ -462,7 +489,6 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
462
489
  }
463
490
  /**
464
491
  * Updates the share url for current selected feature
465
- * @returns
466
492
  * @protected
467
493
  */
468
494
  _updateShareURL() {
@@ -491,6 +517,7 @@ const CrowdsourceReporter$1 = /*@__PURE__*/ proxyCustomElement(class Crowdsource
491
517
  }
492
518
  /**
493
519
  * Navigates to selected features detail based on the URL params
520
+ * @protected
494
521
  */
495
522
  async loadFeatureFromURLParams() {
496
523
  if (this.layerId && this.objectId) {
@@ -12,7 +12,7 @@ import { c as connectLocalized, d as disconnectLocalized } from './locale-6107ef
12
12
  import { c as connectMessages, s as setUpMessages, d as disconnectMessages, u as updateMessages } from './t9n-f16911e7.js';
13
13
  import { S as SLOTS$1 } from './resources-649a0f91.js';
14
14
  import { l as loadModules, g as getLocaleComponentStrings, f as formatNumber } from './locale-731e75a8.js';
15
- import { g as getLayerOrTable, c as getFeatureLayerView, h as highlightFeatures, d as getMapLayerHash, a as getAllLayers } from './mapViewUtils-cf05e880.js';
15
+ import { a as getAllLayers, g as getLayerOrTable, c as getFeatureLayerView, h as highlightFeatures, d as getMapLayerHash } from './mapViewUtils-cf05e880.js';
16
16
  import { P as PopupUtils } from './popupUtils-d75edf93.js';
17
17
  import './guid-36c6c6a5.js';
18
18
  import './resources-cdc36705.js';
@@ -335,7 +335,7 @@ const FlowItem = class {
335
335
  };
336
336
  FlowItem.style = flowItemCss;
337
337
 
338
- const createFeatureCss = ":host{display:block}.esri-editor__panel-toolbar{display:none !important}";
338
+ const createFeatureCss = ":host{display:block}.esri-editor__panel-toolbar{display:none !important}.esri-editor__update-actions{display:none !important}.esri-editor__panel-content{padding-block:0px !important}.esri-editor .esri-item-list__group__header{display:none !important}.esri-editor__panel-content__section .esri-widget__heading{display:none !important}.esri-editor .esri-item-list__filter-container--sticky{padding-block:0px !important;padding-inline:10px !important}";
339
339
 
340
340
  const CreateFeature = class {
341
341
  constructor(hostRef) {
@@ -343,8 +343,10 @@ const CreateFeature = class {
343
343
  this.success = createEvent(this, "success", 7);
344
344
  this.fail = createEvent(this, "fail", 7);
345
345
  this.drawComplete = createEvent(this, "drawComplete", 7);
346
+ this.editingAttachment = createEvent(this, "editingAttachment", 7);
346
347
  this.mapView = undefined;
347
348
  this.selectedLayerId = undefined;
349
+ this.customizeSubmit = false;
348
350
  }
349
351
  //--------------------------------------------------------------------------
350
352
  //
@@ -415,18 +417,8 @@ const CreateFeature = class {
415
417
  * Init Editor widget and starts the create workflow
416
418
  */
417
419
  async init() {
418
- if (this.mapView) {
419
- if (this.mapView && this.selectedLayerId) {
420
- await getLayerOrTable(this.mapView, this.selectedLayerId);
421
- await this.createEditorWidget();
422
- await this.startCreate();
423
- this._editor.viewModel.featureFormViewModel.on('submit', this.submitted.bind(this));
424
- setTimeout(() => {
425
- var _a, _b;
426
- this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')[1].shadowRoot.querySelector('calcite-panel').shadowRoot.querySelector('article').querySelector('header').setAttribute('style', 'display: none');
427
- (_b = (_a = this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')[1].shadowRoot.querySelector('calcite-panel').shadowRoot.querySelector('article')) === null || _a === void 0 ? void 0 : _a.querySelector('footer')) === null || _b === void 0 ? void 0 : _b.setAttribute('style', 'display: none');
428
- }, 700);
429
- }
420
+ if (this.mapView && this.selectedLayerId) {
421
+ await this.createEditorWidget();
430
422
  }
431
423
  }
432
424
  /**
@@ -435,10 +427,12 @@ const CreateFeature = class {
435
427
  * @protected
436
428
  */
437
429
  async initModules() {
438
- const [Editor] = await loadModules([
439
- "esri/widgets/Editor"
430
+ const [Editor, reactiveUtils] = await loadModules([
431
+ "esri/widgets/Editor",
432
+ "esri/core/reactiveUtils"
440
433
  ]);
441
434
  this.Editor = Editor;
435
+ this.reactiveUtils = reactiveUtils;
442
436
  }
443
437
  /**
444
438
  * Display editor widget to create the new feature
@@ -448,50 +442,104 @@ const CreateFeature = class {
448
442
  if (this._editor) {
449
443
  this._editor.destroy();
450
444
  }
445
+ const layerInfos = [];
451
446
  const container = document.createElement("div");
452
- const layer = await getLayerOrTable(this.mapView, this.selectedLayerId);
453
- const selectedLayer = {
454
- layer: layer
455
- };
447
+ const allMapLayers = await getAllLayers(this.mapView);
448
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
449
+ allMapLayers.forEach(async (eachLayer) => {
450
+ layerInfos.push({
451
+ layer: eachLayer,
452
+ enabled: (eachLayer === null || eachLayer === void 0 ? void 0 : eachLayer.type) === "feature" && (eachLayer === null || eachLayer === void 0 ? void 0 : eachLayer.id) === this.selectedLayerId,
453
+ addEnabled: true,
454
+ updateEnabled: false,
455
+ deleteEnabled: false // default is true, set to false to disable the ability to delete features
456
+ });
457
+ });
456
458
  this._editor = new this.Editor({
457
459
  allowedWorkflows: "create-features",
458
460
  view: this.mapView,
459
- layerInfos: [selectedLayer],
461
+ layerInfos: layerInfos,
460
462
  visibleElements: {
461
- snappingControls: false,
462
- snappingControlsElements: {
463
- featureEnabledToggle: false,
464
- layerList: false,
465
- enabledToggle: false
466
- }
463
+ snappingControls: false
467
464
  },
468
- container,
465
+ container
469
466
  });
470
467
  this.el.appendChild(container);
468
+ //Add handle to watch if attachments are added/edited
469
+ const attachmentHandle = this.reactiveUtils.watch(() => this._editor.viewModel.state, (state) => {
470
+ if (state === 'adding-attachment' || state === 'editing-attachment') {
471
+ this._addingAttachment = true;
472
+ this.editingAttachment.emit(true);
473
+ }
474
+ else {
475
+ if (this._addingAttachment) {
476
+ this.editingAttachment.emit(false);
477
+ this._addingAttachment = false;
478
+ }
479
+ }
480
+ });
481
+ this._editor.viewModel.addHandles(attachmentHandle);
482
+ //Add handle to watch featureTemplatesViewModel ready state and then start the creation
483
+ const handle = this.reactiveUtils.watch(() => this._editor.viewModel.featureTemplatesViewModel.state, (state) => {
484
+ if (state === 'ready') {
485
+ void this.startCreate();
486
+ }
487
+ });
488
+ this._editor.viewModel.addHandles(handle);
471
489
  }
472
490
  /**
473
491
  * Start creating the feature
474
492
  * @protected
475
493
  */
476
494
  async startCreate() {
477
- var _a, _b;
478
- const layer = await getLayerOrTable(this.mapView, this.selectedLayerId);
479
- if (layer) {
480
- let template = layer.templates && layer.templates.length ? layer.templates[0] : {};
481
- if (((_a = layer.sourceJSON) === null || _a === void 0 ? void 0 : _a.types.length) && ((_b = layer.sourceJSON.types[0].templates) === null || _b === void 0 ? void 0 : _b.length)) {
482
- template = layer.sourceJSON.types[0].templates[0];
483
- }
484
- const creationInfo = {
485
- layer: layer,
486
- template: template
487
- };
488
- await this._editor.startCreateFeaturesWorkflowAtFeatureCreation(creationInfo);
489
- this._editor.viewModel.sketchViewModel.on("create", (evt) => {
490
- if (evt.state === "complete") {
491
- this.drawComplete.emit();
492
- }
495
+ var _a;
496
+ if ((_a = this._editor.viewModel.featureTemplatesViewModel.items) === null || _a === void 0 ? void 0 : _a.length) {
497
+ const items = this._editor.viewModel.featureTemplatesViewModel.items[0].get("items");
498
+ //once the feature template is selected handle the event for formSubmit and sketch complete
499
+ //also, hide the headers and footer in the editor as we will be showing our own submit and cancel button
500
+ this._editor.viewModel.featureTemplatesViewModel.on('select', () => {
501
+ setTimeout(() => {
502
+ //on form submit
503
+ this._editor.viewModel.featureFormViewModel.on('submit', this.submitted.bind(this));
504
+ //on sketch complete emit the event
505
+ this._editor.viewModel.sketchViewModel.on("create", (evt) => {
506
+ if (evt.state === "complete") {
507
+ this.drawComplete.emit();
508
+ }
509
+ });
510
+ this.hideEditorsElements();
511
+ }, 700);
512
+ this.hideEditorsElements();
493
513
  });
514
+ //if only one feature template then directly start geometry creation for that
515
+ //else allow feature template selection to user
516
+ if (items.length === 1) {
517
+ this._editor.viewModel.featureTemplatesViewModel.select(items[0]);
518
+ }
519
+ //hides the header and footer elements in editor widget
520
+ this.hideEditorsElements();
521
+ }
522
+ }
523
+ /**
524
+ * Hides the elements of editor widget
525
+ * @protected
526
+ */
527
+ hideEditorsElements() {
528
+ if (!this.customizeSubmit) {
529
+ return;
494
530
  }
531
+ setTimeout(() => {
532
+ var _a;
533
+ //hides the header and footer on the featureForm
534
+ (_a = this.el.querySelector('.esri-editor').querySelectorAll('calcite-flow-item')) === null || _a === void 0 ? void 0 : _a.forEach((flowItem) => {
535
+ var _a, _b, _c, _d, _e;
536
+ const article = (_c = (_b = (_a = flowItem.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('calcite-panel')) === null || _b === void 0 ? void 0 : _b.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('article');
537
+ //hide the header
538
+ (_d = article === null || article === void 0 ? void 0 : article.querySelector('header')) === null || _d === void 0 ? void 0 : _d.setAttribute('style', 'display: none');
539
+ //hide the footer
540
+ (_e = article === null || article === void 0 ? void 0 : article.querySelector('footer')) === null || _e === void 0 ? void 0 : _e.setAttribute('style', 'display: none');
541
+ });
542
+ }, 700);
495
543
  }
496
544
  /**
497
545
  * On creation of feature emit the event that the feature is created
@@ -500,9 +548,12 @@ const CreateFeature = class {
500
548
  */
501
549
  async submitted(evt) {
502
550
  var _a;
551
+ //return if any attribute is invalid , focus will be shifted to the invalid attribute in feature form
503
552
  if (evt.invalid.length) {
504
553
  return;
505
554
  }
555
+ //Submit only when valid attributes
556
+ //emit success or fail based on the result
506
557
  if (evt.valid.length) {
507
558
  try {
508
559
  await this._editor.activeWorkflow.commit();
@@ -79,6 +79,7 @@ const CrowdsourceReporter = class {
79
79
  * @returns Promise when complete
80
80
  */
81
81
  async componentWillLoad() {
82
+ this._urlParamsLoaded = false;
82
83
  await this._initModules();
83
84
  await this._getTranslations();
84
85
  }
@@ -115,6 +116,11 @@ const CrowdsourceReporter = class {
115
116
  setSelectedLayer(layerId, layerName) {
116
117
  this._selectedLayerId = layerId;
117
118
  this._selectedLayerName = layerName;
119
+ //show only current layer on map and hide other valid editable layers
120
+ //if layerId is empty then show all the layers on map
121
+ this._validLayers.forEach(layer => {
122
+ layer.set('visible', !layerId || (layer.id === layerId));
123
+ });
118
124
  }
119
125
  /**
120
126
  * Get the reporter app functionality
@@ -171,15 +177,22 @@ const CrowdsourceReporter = class {
171
177
  * @protected
172
178
  */
173
179
  getFeatureCreateFlowItem() {
174
- return (h("calcite-flow-item", { collapsed: this.isMobile && this._sidePanelCollapsed, heading: this._selectedLayerName, onCalciteFlowItemBack: this.backFromCreateFeaturePanel.bind(this) }, this.isMobile && this.getActionToExpandCollapsePanel(), this._showSubmitCancelButton && h("div", { class: "width-full", slot: "footer" }, h("calcite-button", { appearance: "secondary", class: "footer-top-button footer-button", onClick: this.onSubmitButtonClick.bind(this), width: "full" }, this._translations.submit), h("calcite-button", { appearance: "outline", class: "footer-button", onClick: this.backFromCreateFeaturePanel.bind(this), width: "full" }, this._translations.cancel)), h("calcite-panel", { "full-height": true, "full-width": true }, h("calcite-notice", { class: "notice-msg", icon: "lightbulb", kind: "success", open: true }, h("div", { slot: "message" }, this._translations.featureEditFormInfoMsg)), h("create-feature", { mapView: this.mapView, onDrawComplete: this.showSubmitCancelButton.bind(this), onFail: this.createFeatureFailed.bind(this), onSuccess: this.navigateHomePage.bind(this), ref: el => this._createFeature = el, selectedLayerId: this._selectedLayerId }))));
180
+ return (h("calcite-flow-item", { collapsed: this.isMobile && this._sidePanelCollapsed, heading: this._selectedLayerName, onCalciteFlowItemBack: this.backFromCreateFeaturePanel.bind(this) }, this.isMobile && this.getActionToExpandCollapsePanel(), this._showSubmitCancelButton && h("div", { class: "width-full", slot: "footer" }, h("calcite-button", { appearance: "secondary", class: "footer-top-button footer-button", onClick: this.onSubmitButtonClick.bind(this), width: "full" }, this._translations.submit), h("calcite-button", { appearance: "outline", class: "footer-button", onClick: this.backFromCreateFeaturePanel.bind(this), width: "full" }, this._translations.cancel)), h("calcite-panel", { "full-height": true, "full-width": true }, h("calcite-notice", { class: "notice-msg", icon: "lightbulb", kind: "success", open: true }, h("div", { slot: "message" }, this._translations.featureEditFormInfoMsg)), h("create-feature", { customizeSubmit: true, mapView: this.mapView, onDrawComplete: this.onDrawComplete.bind(this), onEditingAttachment: this.showSubmitCancelButton.bind(this), onFail: this.createFeatureFailed.bind(this), onSuccess: this.onReportSubmitted.bind(this), ref: el => this._createFeature = el, selectedLayerId: this._selectedLayerId }))));
175
181
  }
176
182
  /**
177
183
  * When drawing of incident location completed on map show the submit and cancel button
178
184
  * @protected
179
185
  */
180
- showSubmitCancelButton() {
186
+ onDrawComplete() {
181
187
  this._showSubmitCancelButton = true;
182
188
  }
189
+ /**
190
+ * When Add attachment panel is enabled hide the submit and cancel button
191
+ * @protected
192
+ */
193
+ showSubmitCancelButton(evt) {
194
+ this._showSubmitCancelButton = !evt.detail;
195
+ }
183
196
  /**
184
197
  * On back from create feature, call submit editor to destroy the Editor widget instance
185
198
  * @protected
@@ -212,11 +225,22 @@ const CrowdsourceReporter = class {
212
225
  * On submit report navigate to the layer list home page and refresh the layer list
213
226
  * @protected
214
227
  */
215
- navigateHomePage() {
228
+ onReportSubmitted() {
216
229
  this._reportSubmitted = true;
230
+ this.navigateToHomePage();
231
+ }
232
+ /**
233
+ * Navigates to layer-list
234
+ * @protected
235
+ */
236
+ navigateToHomePage() {
237
+ if (this._createFeature) {
238
+ this._createFeature.close();
239
+ }
217
240
  if (this._layerList) {
218
241
  this._layerList.refresh();
219
242
  }
243
+ this.setSelectedFeatures([]);
220
244
  this._flowItems = ["layer-list"];
221
245
  }
222
246
  /**
@@ -262,7 +286,10 @@ const CrowdsourceReporter = class {
262
286
  //update the has valid layer state
263
287
  this._hasValidLayers = layersListed.length > 0;
264
288
  //navigate to the feature details if URL params found
265
- await this.loadFeatureFromURLParams();
289
+ if (!this._urlParamsLoaded) {
290
+ this._urlParamsLoaded = true;
291
+ await this.loadFeatureFromURLParams();
292
+ }
266
293
  }
267
294
  /**On click of layer list item show feature list
268
295
  * @param evt Event which has details of selected layerId and layerName
@@ -279,10 +306,10 @@ const CrowdsourceReporter = class {
279
306
  backFromSelectedPanel() {
280
307
  const updatedFlowItems = [...this._flowItems];
281
308
  updatedFlowItems.pop();
282
- //clear the selected layer and feature when back to layer list
309
+ //Back to layer list, and return as the flowItems will be reset in navigateToHomePage
283
310
  if (updatedFlowItems.length === 1) {
284
- this.setSelectedLayer('', '');
285
- this.setSelectedFeatures([]);
311
+ this.navigateToHomePage();
312
+ return;
286
313
  }
287
314
  this._flowItems = [...updatedFlowItems];
288
315
  }
@@ -431,7 +458,6 @@ const CrowdsourceReporter = class {
431
458
  }
432
459
  /**
433
460
  * Updates the share url for current selected feature
434
- * @returns
435
461
  * @protected
436
462
  */
437
463
  _updateShareURL() {
@@ -460,6 +486,7 @@ const CrowdsourceReporter = class {
460
486
  }
461
487
  /**
462
488
  * Navigates to selected features detail based on the URL params
489
+ * @protected
463
490
  */
464
491
  async loadFeatureFromURLParams() {
465
492
  if (this.layerId && this.objectId) {