Skip to content

Commit edb9b92

Browse files
authored
Download button in File Picker (#2689)
1 parent 84b4c36 commit edb9b92

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

services/web/client/source/class/osparc/desktop/WorkbenchView.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
248248

249249
__createTabPage: function(icon, tooltip, widget, backgroundColor = "background-main") {
250250
const tabPage = new qx.ui.tabview.Page().set({
251-
layout: new qx.ui.layout.VBox(5),
251+
layout: new qx.ui.layout.VBox(10),
252252
backgroundColor,
253253
icon: icon+"/24"
254254
});
@@ -894,7 +894,14 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
894894

895895
const view = osparc.file.FilePicker.buildInfoView(filePicker);
896896
view.setEnabled(false);
897+
897898
this.__infoPage.add(view);
899+
900+
const downloadFileBtn = new qx.ui.form.Button(this.tr("Download"), "@FontAwesome5Solid/cloud-download-alt/14").set({
901+
allowGrowX: false
902+
});
903+
downloadFileBtn.addListener("execute", () => osparc.file.FilePicker.downloadOutput(filePicker));
904+
this.__infoPage.add(downloadFileBtn);
898905
} else {
899906
// empty File Picker
900907
const tabViewLeftPanel = this.getChildControl("side-panel-left-tabs");

services/web/client/source/class/osparc/file/FilePicker.js

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,36 @@ qx.Class.define("osparc.file.FilePicker", {
139139
}
140140
},
141141

142+
getOutputFileMetadata: function(node) {
143+
return new Promise((resolve, reject) => {
144+
const outValue = osparc.file.FilePicker.getOutput(node.getOutputs());
145+
const params = {
146+
url: {
147+
locationId: outValue.store,
148+
datasetId: outValue.dataset
149+
}
150+
};
151+
osparc.data.Resources.fetch("storageFiles", "getByLocationAndDataset", params)
152+
.then(files => {
153+
const fileMetadata = files.find(file => file.file_id === outValue.path);
154+
if (fileMetadata) {
155+
resolve(fileMetadata);
156+
} else {
157+
reject();
158+
}
159+
})
160+
.catch(() => reject());
161+
});
162+
},
163+
142164
buildFileFromStoreInfoView: function(node, form) {
143-
const outValue = osparc.file.FilePicker.getOutput(node.getOutputs());
144-
const params = {
145-
url: {
146-
locationId: outValue.store,
147-
datasetId: outValue.dataset
148-
}
149-
};
150-
osparc.data.Resources.fetch("storageFiles", "getByLocationAndDataset", params)
151-
.then(files => {
152-
const fileMetadata = files.find(file => file.file_uuid === outValue.path);
153-
if (fileMetadata) {
154-
for (let [key, value] of Object.entries(fileMetadata)) {
155-
const entry = new qx.ui.form.TextField();
156-
form.add(entry, key, null, key);
157-
if (value) {
158-
entry.setValue(value.toString());
159-
}
165+
this.self().getOutputFileMetadata(node)
166+
.then(fileMetadata => {
167+
for (let [key, value] of Object.entries(fileMetadata)) {
168+
const entry = new qx.ui.form.TextField();
169+
form.add(entry, key, null, key);
170+
if (value) {
171+
entry.setValue(value.toString());
160172
}
161173
}
162174
});
@@ -191,6 +203,17 @@ qx.Class.define("osparc.file.FilePicker", {
191203
return new qx.ui.form.renderer.Single(form);
192204
},
193205

206+
downloadOutput: function(node) {
207+
this.self().getOutputFileMetadata(node)
208+
.then(fileMetadata => {
209+
if ("location_id" in fileMetadata && "file_id" in fileMetadata) {
210+
const locationId = fileMetadata["location_id"];
211+
const fileId = fileMetadata["file_id"];
212+
osparc.utils.Utils.retrieveURLAndDownload(locationId, fileId);
213+
}
214+
});
215+
},
216+
194217
serializeOutput: function(outputs) {
195218
let output = {};
196219
const outFileValue = osparc.file.FilePicker.getOutput(outputs);

tests/e2e/utils/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ async function getStudyState(page, studyId) {
304304
const resp = await makeRequest(page, endPoint);
305305

306306
if (resp !== null && "state" in resp && "value" in resp["state"]) {
307-
return resp["state"]["value"];
307+
const state = resp["state"]["value"];
308+
console.log("-----> study state", state);
309+
return state;
308310
}
309311
console.log("Unable to parse Pipeline Status:", JSON.stringify(resp));
310312
return null;

0 commit comments

Comments
 (0)