Skip to content

Commit ba19c8a

Browse files
committed
Added Document Dialog into Edit Feature Attachments sample
1 parent 38a20a2 commit ba19c8a

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

Edit Feature Attachments/MyApp.qml

+36-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import QtQuick.Controls.Material 2.1
2424
import ArcGIS.AppFramework 1.0
2525
import ArcGIS.AppFramework.Controls 1.0
2626
import Esri.ArcGISRuntime 100.2
27+
import ArcGIS.AppFramework.Platform 1.0
2728

2829
import "controls" as Controls
2930

@@ -52,11 +53,17 @@ App {
5253
Controls.HeaderBar{}
5354
}
5455

56+
BusyIndicator{
57+
id: busy
58+
anchors.centerIn: parent
59+
Material.accent: "#8f499c"
60+
running: false
61+
}
62+
5563
// sample starts here ------------------------------------------------------------------
5664
contentItem: Rectangle{
5765
anchors.top:header.bottom
5866

59-
6067
MapView {
6168
id: mapView
6269
anchors.fill: parent
@@ -100,7 +107,13 @@ App {
100107

101108
// signal handler for selecting features
102109
onSelectFeaturesStatusChanged: {
110+
if (selectFeaturesStatus === Enums.TaskStatusInProgress) {
111+
// busy.running = true
112+
console.log("######################TaskStatusInProgress")
113+
}
114+
103115
if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
116+
busy.running = false
104117
if (!selectFeaturesResult.iterator.hasNext)
105118
return;
106119

@@ -360,6 +373,9 @@ App {
360373
height: width
361374
fillMode: Image.PreserveAspectFit
362375
source: attachmentUrl
376+
onSourceChanged: {
377+
console.log(source)
378+
}
363379
}
364380

365381
MouseArea {
@@ -381,25 +397,29 @@ App {
381397

382398
// file dialog for selecting a file to add as an attachment
383399
//! [EditFeatures add attachment from a file dialog]
384-
FileDialog {
400+
DocumentDialog {
385401
id: fileDialog
386402

387403
function doAddAttachment(){
388404
if (selectedFeature.loadStatus === Enums.LoadStatusLoaded) {
389405
selectedFeature.onLoadStatusChanged.disconnect(doAddAttachment);
390-
selectedFeature.attachments.addAttachment(fileDialog.fileUrl, "application/octet-stream", fileInfo.fileName);
406+
selectedFeature.attachments.addAttachment(fileDialog.filePath, "application/octet-stream", fileInfo.fileName);
407+
408+
391409
}
392410
}
393411

394412
onAccepted: {
395413
// add the attachment to the feature table
396-
fileInfo.url = fileDialog.fileUrl;
414+
fileInfo.url = filePath
397415
if (selectedFeature.loadStatus === Enums.LoadStatusLoaded) {
398-
selectedFeature.attachments.addAttachment(fileDialog.fileUrl, "application/octet-stream", fileInfo.fileName);
416+
selectedFeature.attachments.addAttachment(filePath, "application/octet-stream", fileInfo.fileName);
399417
} else {
400418
selectedFeature.onLoadStatusChanged.connect(doAddAttachment);
401419
selectedFeature.load();
402420
}
421+
busy.running = true
422+
console.log(filePath)
403423
}
404424
}
405425
//! [EditFeatures add attachment from a file dialog]
@@ -412,6 +432,17 @@ App {
412432
FileInfo {
413433
id: fileInfo
414434
}
435+
436+
//Show storage permission pop-up on Android
437+
438+
FileFolder {
439+
id: fileFolder
440+
path: AppFramework.userHomePath
441+
}
442+
443+
Component.onCompleted: {
444+
fileFolder.makeFolder()
445+
}
415446
}
416447
}
417448

Edit Feature Attachments/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
## Add, delete, and fetch attachments for a specific feature in a feature service.
33

4-
This sample demonstrates the following:
5-
- Click or tap on a feature to show its callout. The callout specifies the number of attachments for that particular feature.
6-
- Selecting on the info button inside the callout shows the list of those attachments.
7-
- In the list you can add a new attachment by selecting the + button. You can delete an attachment by selecting an attachment and selecting the - button.
4+
Click or tap on a feature to show its callout. The callout specifies the number of attachments for that particular feature. Selecting on the info button inside the callout shows the list of those attachments. In the list, you can add a new attachment by selecting the + button. When clicking on the + button, a native document picker will open, which is invoked by DocumentDialog from AppFramework Platform plugin. You can delete an attachment by selecting an attachment and selecting the - button. This is all controlled through the attachment list model, which is obtained through the feature. The attachment list model works similarly to other QML models and can be directly fed into a list view for easy display and user interaction.
5+
6+
By default, fetchAttachmentInfos is called automatically for the selected feature, which will request the attachment info JSON from the service. This JSON contains information such as name (the file name) and attachmentUrl (the URL to the file data.)
7+
8+
To edit the attachments, call addAttachment or deleteAttachment on the AttachmentListModel. By default, edits are automatically applied to the service and applyEdits does not need to be called.
89

910
[Resource Level](https://geonet.esri.com/groups/appstudio/blog/2016/12/06/how-to-describe-our-resources-in-terms-of-difficulty-complexity-and-time-to-digest): 🍌🍌🍌
1011

0 commit comments

Comments
 (0)