Skip to content

Commit

Permalink
Refs #2. Working path for archive download
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Apr 23, 2024
1 parent 6b208a5 commit ae66e8c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Frontend/DashboardsViewer/content/App.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ Window {
}
}

Connections {
/*Connections {
target: UserClient
onUserEvent: function(event) {
console.log("UserEvent: ", event)
}
}
}*/
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Item {
property var params: Object()
property bool autoFetch: false
property string filename: ""
property string archiveUuid: ""
property bool downloading: false

signal downloadProgress(var bytesReceived, var bytesTotal);
signal downloadStarted();
Expand All @@ -16,14 +18,21 @@ Item {

function downloadFile() {

if (downloading){
console.log("Already downloading file... Ignoring another download.")
return;
}

if (filename)
{
console.log("Should download file and save to: ", filename );
downloading = true;
console.log("Should download file " + url + " and save to: ", filename );
var fileDownloader = UserClient.downloadFile(filename, url, params);

fileDownloader.finished.connect(function() {
console.log("Finished");
downloadFinished();
downloading = false;
});

fileDownloader.downloadProgress.connect(function(bytesReceived, bytesTotal) {
Expand All @@ -33,6 +42,7 @@ Item {
}
else {
downloadFailed();
downloading = false;
}

}
Expand All @@ -51,4 +61,16 @@ Item {
}
}

Connections {
target: UserClient
onArchiveEvent: function(event) {
console.log("ArchiveEvent: ", event)
if (event.status === 2){
// Completed - start download!
url = event.archiveUrl;
downloadFile();
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 2.15
import QtQuick.Dialogs
import QtCore

import DashboardsViewer
import "../widgets"
Expand Down Expand Up @@ -151,8 +153,17 @@ BaseDelegate {
visible: showDownloadAssets
imgPath: "../images/icons/data.png"
onClicked: {
console.log("Download");
fileDownloader.downloadParticipantArchive(model[model.dataSource.fieldIdName])
if (dashboardViewerApp.isWebAssembly()) {
//This will use the browser download function. Download UI is provided by browser.
fileDownloader.filename = model[model.dataSource.fieldName]

//DownloadFile returnes a null object in WebASM
fileDownloader.downloadParticipantArchive(model[model.dataSource.fieldIdName])
} else {
//console.log('WebAssembly is not supported');
saveFileDialog.open();
}

}
}
}
Expand All @@ -161,6 +172,19 @@ BaseDelegate {
id: fileDownloader
}

FileDialog {
id: saveFileDialog
nameFilters: ["Zip files (*.zip)"]
defaultSuffix: ".zip"
fileMode: FileDialog.SaveFile
//URL
currentFolder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
selectedFile: currentFolder + "/participant.zip" //model[model.dataSource.fieldDisplayName] + ".zip"
onAccepted: function() {
fileDownloader.filename = saveFileDialog.currentFile;
fileDownloader.downloadParticipantArchive(model[model.dataSource.fieldIdName])
}
}


}

0 comments on commit ae66e8c

Please sign in to comment.