From ae66e8c4dd5a625a9e0a41524b8e69d7e4d81ece Mon Sep 17 00:00:00 2001 From: Simon Briere Date: Tue, 23 Apr 2024 09:11:05 -0400 Subject: [PATCH] Refs #2. Working path for archive download --- Frontend/DashboardsViewer/content/App.qml | 4 +-- .../dataSources/FileDownloadDataSource.qml | 24 +++++++++++++++- .../content/delegates/ParticipantDelegate.qml | 28 +++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Frontend/DashboardsViewer/content/App.qml b/Frontend/DashboardsViewer/content/App.qml index f11213b..1a7b34f 100644 --- a/Frontend/DashboardsViewer/content/App.qml +++ b/Frontend/DashboardsViewer/content/App.qml @@ -117,11 +117,11 @@ Window { } } - Connections { + /*Connections { target: UserClient onUserEvent: function(event) { console.log("UserEvent: ", event) } - } + }*/ } diff --git a/Frontend/DashboardsViewer/content/dataSources/FileDownloadDataSource.qml b/Frontend/DashboardsViewer/content/dataSources/FileDownloadDataSource.qml index 9a34944..1eac56c 100644 --- a/Frontend/DashboardsViewer/content/dataSources/FileDownloadDataSource.qml +++ b/Frontend/DashboardsViewer/content/dataSources/FileDownloadDataSource.qml @@ -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(); @@ -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) { @@ -33,6 +42,7 @@ Item { } else { downloadFailed(); + downloading = false; } } @@ -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(); + } + } + } + } diff --git a/Frontend/DashboardsViewer/content/delegates/ParticipantDelegate.qml b/Frontend/DashboardsViewer/content/delegates/ParticipantDelegate.qml index ed9efba..206ff11 100644 --- a/Frontend/DashboardsViewer/content/delegates/ParticipantDelegate.qml +++ b/Frontend/DashboardsViewer/content/delegates/ParticipantDelegate.qml @@ -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" @@ -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(); + } + } } } @@ -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]) + } + } }