Skip to content

Commit 3b362a9

Browse files
committed
Trash studies
1 parent 2a40d9f commit 3b362a9

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,9 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
864864
const studiesMoveButton = this.__createMoveStudiesButton(false);
865865
this._toolbar.add(studiesMoveButton);
866866

867+
const studiesTrashButton = this.__createTrashButton(false);
868+
this._toolbar.add(studiesTrashButton);
869+
867870
const studiesDeleteButton = this.__createDeleteButton(false);
868871
this._toolbar.add(studiesDeleteButton);
869872

@@ -1107,6 +1110,19 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
11071110
return moveStudiesButton;
11081111
},
11091112

1113+
__createTrashButton: function() {
1114+
const trashButton = new qx.ui.form.Button(this.tr("Trash"), "@FontAwesome5Solid/trash/14").set({
1115+
appearance: "danger-button",
1116+
visibility: "excluded"
1117+
});
1118+
osparc.utils.Utils.setIdToWidget(trashButton, "deleteStudiesBtn");
1119+
trashButton.addListener("execute", () => {
1120+
const selection = this._resourcesContainer.getSelection();
1121+
this.__trashStudies(selection.map(button => this.__getStudyData(button.getUuid(), false)), false);
1122+
}, this);
1123+
return trashButton;
1124+
},
1125+
11101126
__createDeleteButton: function() {
11111127
const deleteButton = new qx.ui.form.Button(this.tr("Delete"), "@FontAwesome5Solid/trash/14").set({
11121128
appearance: "danger-button",
@@ -1693,6 +1709,34 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
16931709
req.send(body);
16941710
},
16951711

1712+
__trashStudy: function(studyData) {
1713+
const myGid = osparc.auth.Data.getInstance().getGroupId();
1714+
const collabGids = Object.keys(studyData["accessRights"]);
1715+
const amICollaborator = collabGids.indexOf(myGid) > -1;
1716+
1717+
let operationPromise = null;
1718+
if (collabGids.length > 1 && amICollaborator) {
1719+
const arCopy = osparc.utils.Utils.deepCloneObject(studyData["accessRights"]);
1720+
// remove collaborator
1721+
delete arCopy[myGid];
1722+
operationPromise = osparc.info.StudyUtils.patchStudyData(studyData, "accessRights", arCopy);
1723+
} else {
1724+
// trash study
1725+
operationPromise = osparc.store.Store.getInstance().trashStudy(studyData.uuid);
1726+
}
1727+
operationPromise
1728+
.then(() => this.__removeFromStudyList(studyData.uuid))
1729+
.catch(err => {
1730+
console.error(err);
1731+
osparc.FlashMessenger.getInstance().logAs(err, "ERROR");
1732+
})
1733+
.finally(() => this.resetSelection());
1734+
},
1735+
1736+
__trashStudies: function(studiesData) {
1737+
studiesData.forEach(studyData => this.__trashStudy(studyData));
1738+
},
1739+
16961740
__doDeleteStudy: function(studyData) {
16971741
const myGid = osparc.auth.Data.getInstance().getGroupId();
16981742
const collabGids = Object.keys(studyData["accessRights"]);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ qx.Class.define("osparc.data.Resources", {
192192
method: "PATCH",
193193
url: statics.API + "/projects/{studyId}"
194194
},
195+
trash: {
196+
method: "POST",
197+
url: statics.API + "/projects/{studyId}:trash"
198+
},
199+
untrash: {
200+
method: "POST",
201+
url: statics.API + "/projects/{studyId}:untrash"
202+
},
195203
delete: {
196204
method: "DELETE",
197205
url: statics.API + "/projects/{studyId}"

services/static-webserver/client/source/class/osparc/store/Store.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,43 @@ qx.Class.define("osparc.store.Store", {
427427
}
428428
},
429429

430+
trashStudy: function(studyId) {
431+
const params = {
432+
url: {
433+
studyId
434+
}
435+
};
436+
return new Promise((resolve, reject) => {
437+
osparc.data.Resources.fetch("studies", "trash", params)
438+
.then(() => {
439+
this.remove("studies", "uuid", studyId);
440+
resolve();
441+
})
442+
.catch(err => {
443+
console.error(err);
444+
reject(err);
445+
});
446+
});
447+
},
448+
449+
untrashStudy: function(studyId) {
450+
const params = {
451+
url: {
452+
studyId
453+
}
454+
};
455+
return new Promise((resolve, reject) => {
456+
osparc.data.Resources.fetch("studies", "untrash", params)
457+
.then(() => {
458+
resolve();
459+
})
460+
.catch(err => {
461+
console.error(err);
462+
reject(err);
463+
});
464+
});
465+
},
466+
430467
deleteStudy: function(studyId) {
431468
const params = {
432469
url: {

0 commit comments

Comments
 (0)