Skip to content

Commit

Permalink
Added Document Dialog into Edit Feature Attachments sample
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaJin-zz committed Apr 23, 2019
1 parent 38a20a2 commit ba19c8a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
41 changes: 36 additions & 5 deletions Edit Feature Attachments/MyApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import QtQuick.Controls.Material 2.1
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import Esri.ArcGISRuntime 100.2
import ArcGIS.AppFramework.Platform 1.0

import "controls" as Controls

Expand Down Expand Up @@ -52,11 +53,17 @@ App {
Controls.HeaderBar{}
}

BusyIndicator{
id: busy
anchors.centerIn: parent
Material.accent: "#8f499c"
running: false
}

// sample starts here ------------------------------------------------------------------
contentItem: Rectangle{
anchors.top:header.bottom


MapView {
id: mapView
anchors.fill: parent
Expand Down Expand Up @@ -100,7 +107,13 @@ App {

// signal handler for selecting features
onSelectFeaturesStatusChanged: {
if (selectFeaturesStatus === Enums.TaskStatusInProgress) {
// busy.running = true
console.log("######################TaskStatusInProgress")
}

if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
busy.running = false
if (!selectFeaturesResult.iterator.hasNext)
return;

Expand Down Expand Up @@ -360,6 +373,9 @@ App {
height: width
fillMode: Image.PreserveAspectFit
source: attachmentUrl
onSourceChanged: {
console.log(source)
}
}

MouseArea {
Expand All @@ -381,25 +397,29 @@ App {

// file dialog for selecting a file to add as an attachment
//! [EditFeatures add attachment from a file dialog]
FileDialog {
DocumentDialog {
id: fileDialog

function doAddAttachment(){
if (selectedFeature.loadStatus === Enums.LoadStatusLoaded) {
selectedFeature.onLoadStatusChanged.disconnect(doAddAttachment);
selectedFeature.attachments.addAttachment(fileDialog.fileUrl, "application/octet-stream", fileInfo.fileName);
selectedFeature.attachments.addAttachment(fileDialog.filePath, "application/octet-stream", fileInfo.fileName);


}
}

onAccepted: {
// add the attachment to the feature table
fileInfo.url = fileDialog.fileUrl;
fileInfo.url = filePath
if (selectedFeature.loadStatus === Enums.LoadStatusLoaded) {
selectedFeature.attachments.addAttachment(fileDialog.fileUrl, "application/octet-stream", fileInfo.fileName);
selectedFeature.attachments.addAttachment(filePath, "application/octet-stream", fileInfo.fileName);
} else {
selectedFeature.onLoadStatusChanged.connect(doAddAttachment);
selectedFeature.load();
}
busy.running = true
console.log(filePath)
}
}
//! [EditFeatures add attachment from a file dialog]
Expand All @@ -412,6 +432,17 @@ App {
FileInfo {
id: fileInfo
}

//Show storage permission pop-up on Android

FileFolder {
id: fileFolder
path: AppFramework.userHomePath
}

Component.onCompleted: {
fileFolder.makeFolder()
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions Edit Feature Attachments/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

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

This sample demonstrates the following:
- 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. You can delete an attachment by selecting an attachment and selecting the - button.
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.

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.)

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.

[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): 🍌🍌🍌

Expand Down

0 comments on commit ba19c8a

Please sign in to comment.