Skip to content

Commit

Permalink
Refs #2. Completed asset downloads paths for participant, session and…
Browse files Browse the repository at this point in the history
… specific asset.
  • Loading branch information
SBriere committed Apr 29, 2024
1 parent 6589b46 commit 96d40fd
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 127 deletions.
1 change: 1 addition & 0 deletions Frontend/DashboardsViewer/content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ qt6_add_qml_module(content
# Screens
screens/Dashboard.qml
screens/DashboardSelector.qml
screens/LoadingScreen.qml
screens/Login.qml

# Uis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import QtQuick 2.15
import OpenTeraLibs.UserClient 1.0

import DashboardsViewer

Item {
id: fileDownloadDataSource
property string url: "" // Empty URL
Expand All @@ -9,13 +11,13 @@ Item {
property string filename: ""
property string archiveUuid: ""
property bool downloading: false
property bool compressing: false

signal downloadProgress(var bytesReceived, var bytesTotal);
signal downloadStarted();
signal downloadFinished();
signal downloadFailed();


function downloadFile() {

if (downloading){
Expand All @@ -30,7 +32,7 @@ Item {
var fileDownloader = UserClient.downloadFile(filename, url, params);

fileDownloader.finished.connect(function() {
console.log("Finished");
//console.log("Finished");
downloadFinished();
downloading = false;
});
Expand All @@ -42,7 +44,7 @@ Item {
}
else {
downloadFailed();
downloading = false;
downloading = false;
}

}
Expand All @@ -55,12 +57,42 @@ Item {
params = {"id_participant": id_participant}
var reply = UserClient.get("/api/user/assets/archive", params)

compressing = true;

reply.requestSucceeded.connect(function(response, statusCode) {
console.log(response, statusCode);
//console.log(response, statusCode);
});
}
}

function downloadSessionArchive(id_session) {

if (id_session)
{
// Step #1, Call the Archive API
params = {"id_session": id_session}
var reply = UserClient.get("/api/user/assets/archive", params)

compressing = true;

reply.requestSucceeded.connect(function(response, statusCode) {
//console.log(response, statusCode);
});
}
}

function downloadSpecificAsset(asset_uuid){
params = {"asset_uuid": asset_uuid, "with_urls": true}
var reply = UserClient.get("/api/user/assets", params)
reply.requestSucceeded.connect(function(response, statusCode) {
// Download file
params = {"asset_uuid": asset_uuid, "access_token": response[0].access_token};
url = response[0].asset_url.replace(UserClient.url, "")
downloadFile();
});

}

Connections {
target: UserClient
onArchiveEvent: function(event) {
Expand All @@ -71,6 +103,7 @@ Item {
url = url_parts[0];
params = {"archive_uuid": event.archiveUuid};
downloadFile();
compressing = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ BaseDelegate {

FileDownloadDataSource{
id: fileDownloader
onCompressingChanged:{
if (screenLoading !== undefined){
screenLoading.text = qsTr("Compressing data...");
screenLoading.visible = compressing;
screenLoading.progressValue = -1;
}
}
onDownloadingChanged: {
if (screenLoading !== undefined){
screenLoading.text = qsTr("Downloading...");
screenLoading.visible = downloading;
screenLoading.progressValue = 0;
}
}
onDownloadProgress: function(bytesReceived, bytesTotal){
if (screenLoading !== undefined){
screenLoading.progressValue = (bytesReceived / bytesTotal) * 100
}
}
}

FileDialog {
Expand All @@ -179,7 +198,7 @@ BaseDelegate {
fileMode: FileDialog.SaveFile
//URL
currentFolder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
selectedFile: currentFolder + "/participant.zip" //model[model.dataSource.fieldDisplayName] + ".zip"
selectedFile: currentFolder + "/" + model[model.dataSource.fieldDisplayName] + ".zip" //"participant.zip" //model[model.dataSource.fieldDisplayName] + ".zip"
onAccepted: function() {
fileDownloader.filename = saveFileDialog.currentFile;
fileDownloader.downloadParticipantArchive(model[model.dataSource.fieldIdName])
Expand Down
114 changes: 86 additions & 28 deletions Frontend/DashboardsViewer/content/delegates/SessionDelegate.qml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 2.15
import QtQuick.Dialogs
import QtCore

import DashboardsViewer
import "../ui"
import "../widgets"
import "../dataSources"

BaseDelegate {
id: myDelegate
Expand All @@ -13,6 +17,8 @@ BaseDelegate {
property int daysWarningThreshold: 7
property int daysErrorThreshold: 14

property bool showDownloadAssets: true

property bool isCurrentItem: ListView ? ListView.isCurrentItem : false

states: [
Expand Down Expand Up @@ -113,6 +119,31 @@ BaseDelegate {
border.color: isCurrentItem ? "lightgrey" : "black"
border.width: isCurrentItem ? 5 : 1
radius: 5
MouseArea {
id: mouseArea
anchors.fill: parent
onDoubleClicked: {
//console.log("SessionDelegate clicked");
if (stackView) {
stackView.push("../widgets/SessionViewerWidget.qml", {"session": model})
}
}
onPressAndHold: {
//console.log("SessionDelegate long pressed");

if (stackView) {
stackView.push("../widgets/SessionViewerWidget.qml", {"session": model})
}

}
onClicked: {
onClicked: {
if (myDelegate.ListView)
myDelegate.ListView.view.currentIndex = index;
model.dataSource.itemSelected(model[model.dataSource.fieldIdName])
}
}
}
}

RowLayout {
Expand Down Expand Up @@ -190,17 +221,16 @@ BaseDelegate {
Item{
Layout.fillWidth: true
}
}

Text{
id: txtName
Layout.fillWidth: true
text: model.session_name
font.pixelSize: Constants.baseFontSize
wrapMode: Text.WordWrap
style: Text.Outline
color: Constants.textColor
}

Text{
id: txtName
Layout.fillWidth: true
text: model.session_name
font.pixelSize: Constants.baseFontSize
wrapMode: Text.WordWrap
style: Text.Outline
color: Constants.textColor
}

Text{
Expand All @@ -218,31 +248,59 @@ BaseDelegate {
}

}
}
ImageButtonWidget{
id: btnDownload
visible: model.session_assets_count > 0 && showDownloadAssets
imgPath: "../images/icons/data.png"
onClicked: {
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();
}

MouseArea {
id: mouseArea
anchors.fill: parent
onDoubleClicked: {
console.log("SessionDelegate clicked");
if (stackView) {
stackView.push("../widgets/SessionViewerWidget.qml", {"session": model})
}
}
onPressAndHold: {
console.log("SessionDelegate long pressed");
}

if (stackView) {
stackView.push("../widgets/SessionViewerWidget.qml", {"session": model})
FileDownloadDataSource{
id: fileDownloader
onCompressingChanged:{
if (screenLoading !== undefined){
screenLoading.text = qsTr("Compressing data...");
screenLoading.visible = compressing;
screenLoading.progressValue = -1;
}

}
onClicked: {
onClicked: {
if (myDelegate.ListView)
myDelegate.ListView.view.currentIndex = index;
model.dataSource.itemSelected(model[model.dataSource.fieldIdName])
onDownloadingChanged: {
if (screenLoading !== undefined){
screenLoading.text = qsTr("Downloading...");
screenLoading.visible = downloading;
screenLoading.progressValue = 0;
}
}
onDownloadProgress: function(bytesReceived, bytesTotal){
if (screenLoading !== undefined){
screenLoading.progressValue = (bytesReceived / bytesTotal) * 100
}
}
}
FileDialog {
id: saveFileDialog
nameFilters: ["Zip files (*.zip)"]
defaultSuffix: ".zip"
fileMode: FileDialog.SaveFile
//URL
currentFolder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
selectedFile: currentFolder + "/" + model[model.dataSource.fieldDisplayName] + ".zip"
onAccepted: function() {
fileDownloader.filename = saveFileDialog.currentFile;
fileDownloader.downloadSessionArchive(model[model.dataSource.fieldIdName])
}
}
} // Item
28 changes: 4 additions & 24 deletions Frontend/DashboardsViewer/content/screens/Dashboard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,14 @@ Item {
}
}

/*Text {
id: dashboardText
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
text: qsTr("DASHBOARD")
font.pixelSize: 60
height: 60
horizontalAlignment: Text.AlignHCenter
LoadingScreen{
id: screenLoading
visible: false
z: 3
}

Button {
id: closeButton
anchors.left: parent.left
anchors.top: parent.top
width: 150
height: 60
text: qsTr("Close")
onClicked: function () {
stackview.pop()
}
}*/

StackView {
id: dashboardStackView
anchors.fill: parent
/*anchors.top: dashboardText.bottom
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right*/
}
}
36 changes: 36 additions & 0 deletions Frontend/DashboardsViewer/content/screens/LoadingScreen.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import QtQuick
import QtQuick.Controls

import DashboardsViewer

Item {
anchors.fill: parent

property alias text: txtInfos.text
property int progressValue: -1

Rectangle{
id: recFiller
anchors.fill: parent
color: "#aa000000"
Column{
anchors.centerIn: parent
spacing: 10
Text{
id: txtInfos
font.pixelSize: Constants.largeFontSize
color: "white"
text: qsTr("Loading...")
}
ProgressBar{
indeterminate: progressValue < 0
to: 100
value: progressValue >= 0 ? progressValue : 0
width: parent.width
}
}
MouseArea{
anchors.fill: parent
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BaseWidget {

property alias text: control.text
required property string imgPath
property alias textControl: textItem

implicitHeight: control.implicitHeight
implicitWidth: control.implicitWidth + 10
Expand Down
Loading

0 comments on commit 96d40fd

Please sign in to comment.