Skip to content

Commit 268259f

Browse files
authored
🎨 [Frontend] Delete export-data task after downloading artifacts (#7567)
1 parent 10c4a9d commit 268259f

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@ qx.Class.define("osparc.data.Resources", {
580580
get: {
581581
method: "GET",
582582
url: statics.API + "/tasks"
583+
},
584+
delete: {
585+
method: "DELETE",
586+
url: statics.API + "/tasks/{taskId}"
583587
}
584588
}
585589
},

services/static-webserver/client/source/class/osparc/file/FileLabelWithActions.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
109109
setItemSelected: function(selectedItem) {
110110
if (selectedItem) {
111111
this.__selection = [selectedItem];
112-
const isFile = osparc.file.FilesTree.isFile(selectedItem);
113-
const isMultiDownloadEnabled = osparc.utils.DisabledPlugins.isMultiDownloadEnabled();
114-
this.getChildControl("download-button").setEnabled(isFile || isMultiDownloadEnabled); // folders can also be downloaded
112+
this.getChildControl("download-button").setEnabled(true); // folders can also be downloaded
115113
this.getChildControl("delete-button").setEnabled(true); // folders can also be deleted
116114
this.getChildControl("selected-label").setValue(selectedItem.getLabel());
117115
} else {
@@ -143,11 +141,10 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
143141
},
144142

145143
__retrieveURLAndDownloadSelected: function() {
146-
const isMultiDownloadEnabled = osparc.utils.DisabledPlugins.isMultiDownloadEnabled();
147144
if (this.isMultiSelect()) {
148145
if (this.__selection.length === 1 && osparc.file.FilesTree.isFile(this.__selection[0])) {
149146
this.__retrieveURLAndDownloadFile(this.__selection[0]);
150-
} else if (this.__selection.length > 1 && isMultiDownloadEnabled) {
147+
} else if (this.__selection.length > 1) {
151148
const paths = this.__selection.map(item => item.getPath());
152149
this.__retrieveURLAndExportData(paths);
153150
}
@@ -156,7 +153,7 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
156153
if (selection) {
157154
if (osparc.file.FilesTree.isFile(selection)) {
158155
this.__retrieveURLAndDownloadFile(selection);
159-
} else if (isMultiDownloadEnabled) {
156+
} else {
160157
const paths = [selection.getPath()];
161158
this.__retrieveURLAndExportData(paths);
162159
}

services/static-webserver/client/source/class/osparc/task/ExportData.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ qx.Class.define("osparc.task.ExportData", {
8585
.then(data => {
8686
if (data && data.link) {
8787
const fileName = taskData["result"].split("/").pop();
88-
osparc.utils.Utils.downloadLink(data.link, "GET", fileName);
88+
const progressCb = null;
89+
const loadedCb = () => {
90+
const deleteParams = {
91+
url: {
92+
taskId: task.getTaskId(),
93+
}
94+
};
95+
osparc.data.Resources.fetch("tasks", "delete", deleteParams);
96+
}
97+
osparc.utils.Utils.downloadLink(data.link, "GET", fileName, progressCb, loadedCb);
8998
}
9099
})
91100
}

services/static-webserver/client/source/class/osparc/utils/DisabledPlugins.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ qx.Class.define("osparc.utils.DisabledPlugins", {
5656
return osparc.store.StaticInfo.getInstance().isDevFeaturesEnabled();
5757
},
5858

59-
isMultiDownloadEnabled: function() {
60-
return osparc.store.StaticInfo.getInstance().isDevFeaturesEnabled();
61-
},
62-
6359
isJobsEnabled: function() {
6460
return osparc.store.StaticInfo.getInstance().isDevFeaturesEnabled();
6561
},

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,24 +858,25 @@ qx.Class.define("osparc.utils.Utils", {
858858
}
859859
});
860860
xhr.addEventListener("progress", e => {
861-
if (xhr.readyState === XMLHttpRequest.LOADING) {
862-
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 400)) {
863-
if (e["type"] === "progress" && progressCb) {
864-
progressCb(e.loaded / e.total);
865-
}
866-
}
861+
if (
862+
progressCb &&
863+
xhr.readyState === XMLHttpRequest.LOADING &&
864+
(xhr.status === 0 || (xhr.status >= 200 && xhr.status < 400)) &&
865+
e["type"] === "progress"
866+
) {
867+
progressCb(e.loaded / e.total);
867868
}
868869
});
869870
xhr.addEventListener("load", () => {
870871
if (xhr.status == 200) {
871-
if (loadedCb) {
872-
loadedCb();
873-
}
874872
const blob = new Blob([xhr.response]);
875873
if (!fileName) {
876874
fileName = this.self().filenameFromContentDisposition(xhr);
877875
}
878876
this.self().downloadBlobContent(blob, fileName);
877+
if (loadedCb) {
878+
loadedCb();
879+
}
879880
resolve();
880881
} else {
881882
reject(xhr);

0 commit comments

Comments
 (0)