Skip to content

Commit 8719bab

Browse files
committed
refactor
1 parent e32e933 commit 8719bab

File tree

2 files changed

+107
-106
lines changed

2 files changed

+107
-106
lines changed

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,111 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
579579
throw new Error("Abstract method called!");
580580
},
581581

582+
_populateTemplateCardMenu: function(card) {
583+
const menu = card.getMenu();
584+
const templateData = card.getResourceData();
585+
586+
const editButton = this.__getEditTemplateMenuButton(templateData);
587+
if (editButton) {
588+
menu.add(editButton);
589+
menu.addSeparator();
590+
}
591+
592+
const openButton = this._getOpenMenuButton(templateData);
593+
if (openButton) {
594+
menu.add(openButton);
595+
}
596+
597+
const shareButton = this._getShareMenuButton(card);
598+
if (shareButton) {
599+
menu.add(shareButton);
600+
}
601+
602+
const tagsButton = this._getTagsMenuButton(card);
603+
if (tagsButton) {
604+
menu.add(tagsButton);
605+
}
606+
607+
const deleteButton = this.__getDeleteTemplateMenuButton(templateData);
608+
if (deleteButton && editButton) {
609+
menu.addSeparator();
610+
menu.add(deleteButton);
611+
}
612+
},
613+
614+
__getEditTemplateMenuButton: function(templateData) {
615+
const isCurrentUserOwner = osparc.data.model.Study.canIWrite(templateData["accessRights"]);
616+
if (!isCurrentUserOwner) {
617+
return null;
618+
}
619+
620+
const editButton = new qx.ui.menu.Button(this.tr("Open"));
621+
editButton.addListener("execute", () => {
622+
const isStudyCreation = false;
623+
this._startStudyById(templateData["uuid"], null, null, isStudyCreation);
624+
}, this);
625+
return editButton;
626+
},
627+
628+
__getDeleteTemplateMenuButton: function(templateData) {
629+
const isCurrentUserOwner = osparc.data.model.Study.canIDelete(templateData["accessRights"]);
630+
if (!isCurrentUserOwner) {
631+
return null;
632+
}
633+
634+
const deleteButton = new qx.ui.menu.Button(this.tr("Delete"), "@FontAwesome5Solid/trash/12");
635+
deleteButton.set({
636+
appearance: "menu-button"
637+
});
638+
deleteButton.addListener("execute", () => this._deleteTemplateRequested(templateData), this);
639+
return deleteButton;
640+
},
641+
642+
_deleteTemplateRequested: function(templateData) {
643+
const rUSure = this.tr("Are you sure you want to delete ");
644+
const msg = rUSure + "<b>" + templateData.name + "</b>?";
645+
const win = new osparc.ui.window.Confirmation(msg).set({
646+
caption: this.tr("Delete"),
647+
confirmText: this.tr("Delete"),
648+
confirmAction: "delete"
649+
});
650+
win.center();
651+
win.open();
652+
win.addListener("close", () => {
653+
if (win.getConfirmed()) {
654+
this.__doDeleteTemplate(templateData);
655+
}
656+
}, this);
657+
},
658+
659+
__doDeleteTemplate: function(templateData) {
660+
const myGid = osparc.auth.Data.getInstance().getGroupId();
661+
const collabGids = Object.keys(templateData["accessRights"]);
662+
const amICollaborator = collabGids.indexOf(myGid) > -1;
663+
664+
let operationPromise = null;
665+
if (collabGids.length > 1 && amICollaborator) {
666+
const arCopy = osparc.utils.Utils.deepCloneObject(templateData["accessRights"]);
667+
// remove collaborator
668+
delete arCopy[myGid];
669+
operationPromise = osparc.store.Study.patchStudyData(templateData, "accessRights", arCopy);
670+
} else {
671+
// delete study
672+
operationPromise = osparc.store.Store.getInstance().deleteStudy(templateData.uuid);
673+
}
674+
operationPromise
675+
.then(() => this.__removeFromTemplateList(templateData.uuid))
676+
.catch(err => osparc.FlashMessenger.logError(err));
677+
},
678+
679+
__removeFromTemplateList: function(templateId) {
680+
const idx = this._resourcesList.findIndex(study => study["uuid"] === templateId);
681+
if (idx > -1) {
682+
this._resourcesList.splice(idx, 1);
683+
}
684+
this._resourcesContainer.removeCard(templateId);
685+
},
686+
582687
_updateTemplateData: function(templateData) {
583688
const templatesList = this._resourcesList;
584689
const index = templatesList.findIndex(template => template["uuid"] === templateData["uuid"]);

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

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -231,119 +231,15 @@ qx.Class.define("osparc.dashboard.TutorialBrowser", {
231231

232232
// MENU //
233233
_populateCardMenu: function(card) {
234-
const menu = card.getMenu();
235-
const templateData = card.getResourceData();
236-
237-
const editButton = this.__getEditTemplateMenuButton(templateData);
238-
if (editButton) {
239-
menu.add(editButton);
240-
menu.addSeparator();
241-
}
242-
243-
const openButton = this._getOpenMenuButton(templateData);
244-
if (openButton) {
245-
menu.add(openButton);
246-
}
247-
248-
const shareButton = this._getShareMenuButton(card);
249-
if (shareButton) {
250-
menu.add(shareButton);
251-
}
252-
253-
const tagsButton = this._getTagsMenuButton(card);
254-
if (tagsButton) {
255-
menu.add(tagsButton);
256-
}
257-
258-
const deleteButton = this.__getDeleteTemplateMenuButton(templateData);
259-
if (deleteButton && editButton) {
260-
menu.addSeparator();
261-
menu.add(deleteButton);
262-
}
263-
},
264-
265-
__getEditTemplateMenuButton: function(templateData) {
266-
const isCurrentUserOwner = osparc.data.model.Study.canIWrite(templateData["accessRights"]);
267-
if (!isCurrentUserOwner) {
268-
return null;
269-
}
270-
271-
const editButton = new qx.ui.menu.Button(this.tr("Open"));
272-
editButton.addListener("execute", () => this.__editTemplate(templateData), this);
273-
return editButton;
234+
this._populateTemplateCardMenu(card);
274235
},
275236

276237
__getTemplateData: function(id) {
277238
return this._resourcesList.find(template => template.uuid === id);
278239
},
279240

280241
_deleteResourceRequested: function(templateId) {
281-
this.__deleteTemplateRequested(this.__getTemplateData(templateId));
282-
},
283-
284-
__deleteTemplateRequested: function(templateData) {
285-
const rUSure = this.tr("Are you sure you want to delete ");
286-
const msg = rUSure + "<b>" + templateData.name + "</b>?";
287-
const win = new osparc.ui.window.Confirmation(msg).set({
288-
caption: this.tr("Delete"),
289-
confirmText: this.tr("Delete"),
290-
confirmAction: "delete"
291-
});
292-
win.center();
293-
win.open();
294-
win.addListener("close", () => {
295-
if (win.getConfirmed()) {
296-
this.__doDeleteTemplate(templateData);
297-
}
298-
}, this);
299-
},
300-
301-
__getDeleteTemplateMenuButton: function(templateData) {
302-
const isCurrentUserOwner = osparc.data.model.Study.canIDelete(templateData["accessRights"]);
303-
if (!isCurrentUserOwner) {
304-
return null;
305-
}
306-
307-
const deleteButton = new qx.ui.menu.Button(this.tr("Delete"), "@FontAwesome5Solid/trash/12");
308-
deleteButton.set({
309-
appearance: "menu-button"
310-
});
311-
osparc.utils.Utils.setIdToWidget(deleteButton, "studyItemMenuDelete");
312-
deleteButton.addListener("execute", () => this.__deleteTemplateRequested(templateData), this);
313-
return deleteButton;
314-
},
315-
316-
__editTemplate: function(studyData) {
317-
const isStudyCreation = false;
318-
this._startStudyById(studyData.uuid, null, null, isStudyCreation);
319-
},
320-
321-
__doDeleteTemplate: function(studyData) {
322-
const myGid = osparc.auth.Data.getInstance().getGroupId();
323-
const collabGids = Object.keys(studyData["accessRights"]);
324-
const amICollaborator = collabGids.indexOf(myGid) > -1;
325-
326-
let operationPromise = null;
327-
if (collabGids.length > 1 && amICollaborator) {
328-
const arCopy = osparc.utils.Utils.deepCloneObject(studyData["accessRights"]);
329-
// remove collaborator
330-
delete arCopy[myGid];
331-
operationPromise = osparc.store.Study.patchStudyData(studyData, "accessRights", arCopy);
332-
} else {
333-
// delete study
334-
operationPromise = osparc.store.Store.getInstance().deleteStudy(studyData.uuid);
335-
}
336-
operationPromise
337-
.then(() => this.__removeFromTemplateList(studyData.uuid))
338-
.catch(err => osparc.FlashMessenger.logError(err));
339-
},
340-
341-
__removeFromTemplateList: function(templateId) {
342-
const idx = this._resourcesList.findIndex(study => study["uuid"] === templateId);
343-
if (idx > -1) {
344-
this._resourcesList.splice(idx, 1);
345-
}
346-
this._resourcesContainer.removeCard(templateId);
242+
this._deleteTemplateRequested(this.__getTemplateData(templateId));
347243
},
348244
// MENU //
349245

0 commit comments

Comments
 (0)