Skip to content

Commit f772080

Browse files
authored
✨ [Frontend] Delete Functions (#8351)
1 parent 50c2568 commit f772080

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
16401640
return deleteButton;
16411641
},
16421642

1643-
1644-
16451643
__createSelectButton: function() {
16461644
const selectButton = new qx.ui.form.ToggleButton().set({
16471645
appearance: "form-button-outlined",
@@ -1794,12 +1792,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
17941792
this._reloadCards();
17951793
},
17961794

1797-
__removeFromStudyList: function(studyId) {
1798-
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
1795+
__removeFromList: function(resourceUuid) {
1796+
const idx = this._resourcesList.findIndex(resource => resource["uuid"] === resourceUuid);
17991797
if (idx > -1) {
18001798
this._resourcesList.splice(idx, 1);
18011799
}
1802-
this._resourcesContainer.removeCard(studyId);
1800+
this._resourcesContainer.removeCard(resourceUuid);
18031801
},
18041802

18051803
_populateCardMenu: function(card) {
@@ -1812,7 +1810,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
18121810
this._populateTemplateCardMenu(card);
18131811
break;
18141812
case "function":
1815-
card.getChildControl("menu-selection-stack").exclude();
1813+
this.__populateFunctionCardMenu(card);
18161814
break;
18171815
}
18181816
},
@@ -1919,6 +1917,14 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19191917
card.evaluateMenuButtons();
19201918
},
19211919

1920+
__populateFunctionCardMenu: function(card) {
1921+
const menu = card.getMenu();
1922+
const functionData = card.getResourceData();
1923+
1924+
const deleteButton = this.__getDeleteFunctionMenuButton(functionData);
1925+
menu.add(deleteButton);
1926+
},
1927+
19221928
__getOpenLocationMenuButton: function(studyData) {
19231929
const openLocationButton = new qx.ui.menu.Button(this.tr("Open location"), "@FontAwesome5Solid/external-link-alt/12");
19241930
openLocationButton.addListener("execute", () => {
@@ -1994,7 +2000,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19942000
__doMoveStudy: function(studyData, destWorkspaceId, destFolderId) {
19952001
this.__moveStudyToWorkspace(studyData, destWorkspaceId) // first move to workspace
19962002
.then(() => this.__moveStudyToFolder(studyData, destFolderId)) // then move to folder
1997-
.then(() => this.__removeFromStudyList(studyData["uuid"]))
2003+
.then(() => this.__removeFromList(studyData["uuid"]))
19982004
.catch(err => osparc.FlashMessenger.logError(err));
19992005
},
20002006

@@ -2192,6 +2198,54 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21922198
return deleteButton;
21932199
},
21942200

2201+
__getDeleteFunctionMenuButton: function(functionData) {
2202+
const deleteButton = new qx.ui.menu.Button(this.tr("Delete"), "@FontAwesome5Solid/trash/12");
2203+
deleteButton.set({
2204+
appearance: "menu-button"
2205+
});
2206+
osparc.utils.Utils.setIdToWidget(deleteButton, "functionItemMenuDelete");
2207+
deleteButton.addListener("execute", () => {
2208+
this.__popUpDeleteFunctionWindow(functionData, false);
2209+
}, this);
2210+
return deleteButton;
2211+
},
2212+
2213+
__popUpDeleteFunctionWindow: function(functionData, force, message) {
2214+
const win = this.__createConfirmDeleteWindow([functionData.title]);
2215+
win.setCaption(this.tr("Delete function"));
2216+
if (force) {
2217+
if (message) {
2218+
win.setMessage(message);
2219+
} else {
2220+
const msg = this.tr("The function has associated jobs. Are you sure you want to delete it?");
2221+
win.setMessage(msg);
2222+
}
2223+
}
2224+
win.center();
2225+
win.open();
2226+
win.addListener("close", () => {
2227+
if (win.getConfirmed()) {
2228+
this.__doDeleteFunction(functionData, force);
2229+
}
2230+
}, this);
2231+
},
2232+
2233+
__doDeleteFunction: function(functionData, force = false) {
2234+
osparc.store.Functions.deleteFunction(functionData.uuid, force)
2235+
.then(() => {
2236+
this.__removeFromList(functionData.uuid);
2237+
const msg = this.tr("Successfully deleted");
2238+
osparc.FlashMessenger.logAs(msg, "INFO");
2239+
})
2240+
.catch(err => {
2241+
if (err && err.status && err.status === 409) {
2242+
this.__popUpDeleteFunctionWindow(functionData, true, err.message);
2243+
} else {
2244+
osparc.FlashMessenger.logError(err);
2245+
}
2246+
});
2247+
},
2248+
21952249
__getStudyData: function(id) {
21962250
return this._resourcesList.find(study => study.uuid === id);
21972251
},
@@ -2303,7 +2357,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
23032357
__untrashStudy: function(studyData) {
23042358
osparc.store.Study.getInstance().untrashStudy(studyData.uuid)
23052359
.then(() => {
2306-
this.__removeFromStudyList(studyData.uuid);
2360+
this.__removeFromList(studyData.uuid);
23072361
const msg = this.tr("Successfully restored");
23082362
osparc.FlashMessenger.logAs(msg, "INFO");
23092363
this._resourceFilter.evaluateTrashEmpty();
@@ -2315,7 +2369,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
23152369
__trashStudy: function(studyData) {
23162370
osparc.store.Study.getInstance().trashStudy(studyData.uuid)
23172371
.then(() => {
2318-
this.__removeFromStudyList(studyData.uuid);
2372+
this.__removeFromList(studyData.uuid);
23192373
const msg = this.tr("Successfully deleted");
23202374
osparc.FlashMessenger.logAs(msg, "INFO");
23212375
this._resourceFilter.setTrashEmpty(false);
@@ -2353,7 +2407,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
23532407
operationPromise = osparc.store.Study.getInstance().deleteStudy(studyData.uuid);
23542408
}
23552409
operationPromise
2356-
.then(() => this.__removeFromStudyList(studyData.uuid))
2410+
.then(() => this.__removeFromList(studyData.uuid))
23572411
.catch(err => osparc.FlashMessenger.logError(err))
23582412
.finally(() => this.resetSelection());
23592413
},

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ qx.Class.define("osparc.data.Resources", {
644644
method: "POST",
645645
url: statics.API + "/functions"
646646
},
647+
delete: {
648+
method: "DELETE",
649+
url: statics.API + "/functions/{functionId}?force={force}"
650+
},
647651
patch: {
648652
method: "PATCH",
649653
url: statics.API + "/functions/{functionId}?include_extras=true"

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ qx.Class.define("osparc.store.Functions", {
165165
});
166166
},
167167

168+
deleteFunction: function(functionId, force = false) {
169+
const params = {
170+
url: {
171+
functionId,
172+
force,
173+
}
174+
};
175+
return osparc.data.Resources.fetch("functions", "delete", params)
176+
.catch(error => {
177+
console.error("Error deleting function:", error);
178+
throw error; // Rethrow the error to propagate it to the caller
179+
});
180+
},
181+
168182
__putCollaborator: function(functionData, gid, newPermissions) {
169183
const params = {
170184
url: {

0 commit comments

Comments
 (0)