Skip to content

Commit

Permalink
dragOver and drop
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 15, 2024
1 parent be5def7 commit a7e87c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,43 @@ qx.Class.define("osparc.dashboard.DragDropHelpers", {
// make it semi transparent while being dragged
studyItem.setOpacity(0.2);
},

dragOver: function(event, folderDest, folderItem) {
let compatible = false;
const studyDataOrigin = event.getData("osparc-moveStudy")["studyDataOrigin"];
// Compatibility checks:
// - My workspace
// - None
// - Shared workspace
// - write access on workspace
const workspaceId = studyDataOrigin["workspaceId"];
if (workspaceId) {
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
if (workspace) {
compatible = workspace.getMyAccessRights()["write"];
}
} else {
compatible = true;
}
if (compatible) {
folderItem.getChildControl("icon").setTextColor("strong-main");
} else {
folderItem.getChildControl("icon").setTextColor("danger-red");
// do not allow
event.preventDefault();
}
const dragWidget = osparc.dashboard.DragWidget.getInstance();
dragWidget.setDropAllowed(compatible);
},

drop: function(event, folderDest) {
const studyData = event.getData("osparc-moveStudy")["studyDataOrigin"];
const studyToFolderData = {
studyData,
destFolderId: folderDest.getFolderId(),
};
return studyToFolderData;
},
},

moveFolder: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,34 +176,10 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
this.setDroppable(true);

this.addListener("dragover", e => {
const folderDest = this.getFolder();
if (e.supportsType("osparc-moveStudy")) {
let compatible = false;
const studyData = e.getData("osparc-moveStudy")["studyDataOrigin"];
// Compatibility checks:
// - My workspace
// - None
// - Shared workspace
// - write access on workspace
const workspaceId = studyData["workspaceId"];
if (workspaceId) {
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
if (workspace) {
compatible = workspace.getMyAccessRights()["write"];
}
} else {
compatible = true;
}
if (compatible) {
this.getChildControl("icon").setTextColor("strong-main");
} else {
this.getChildControl("icon").setTextColor("danger-red");
// do not allow
e.preventDefault();
}
const dragWidget = osparc.dashboard.DragWidget.getInstance();
dragWidget.setDropAllowed(compatible);
osparc.dashboard.DragDropHelpers.moveStudy.dragOver(e, folderDest, this);
} else if (e.supportsType("osparc-moveFolder")) {
const folderDest = this.getFolder();
osparc.dashboard.DragDropHelpers.moveFolder.dragOver(e, folderDest, this);
}
});
Expand All @@ -217,15 +193,11 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
});

this.addListener("drop", e => {
const folderDest = this.getFolder();
if (e.supportsType("osparc-moveStudy")) {
const studyData = e.getData("osparc-moveStudy")["studyDataOrigin"];
const studyToFolderData = {
studyData,
destFolderId: this.getFolderId(),
};
const studyToFolderData = osparc.dashboard.DragDropHelpers.moveStudy.drop(e, folderDest);
this.fireDataEvent("studyToFolderRequested", studyToFolderData);
} else if (e.supportsType("osparc-moveFolder")) {
const folderDest = this.getFolder();
const folderToFolderData = osparc.dashboard.DragDropHelpers.moveFolder.drop(e, folderDest);
this.fireDataEvent("folderToFolderRequested", folderToFolderData);
}
Expand Down

0 comments on commit a7e87c0

Please sign in to comment.