-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [Frontend] Drag&Drop: Projects and Folders (#6957)
- Loading branch information
Showing
38 changed files
with
777 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
services/static-webserver/client/source/class/osparc/dashboard/DragDropHelpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* ************************************************************************ | ||
osparc - the simcore frontend | ||
https://osparc.io | ||
Copyright: | ||
2024 IT'IS Foundation, https://itis.swiss | ||
License: | ||
MIT: https://opensource.org/licenses/MIT | ||
Authors: | ||
* Odei Maiz (odeimaiz) | ||
************************************************************************ */ | ||
|
||
qx.Class.define("osparc.dashboard.DragDropHelpers", { | ||
type: "static", | ||
|
||
statics: { | ||
moveStudy: { | ||
dragStart: function(event, studyItem, studyDataOrigin) { | ||
event.addAction("move"); | ||
event.addType("osparc-moveStudy"); | ||
event.addData("osparc-moveStudy", { | ||
"studyDataOrigin": studyDataOrigin, | ||
}); | ||
|
||
// init drag indicator | ||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.getChildControl("dragged-resource").set({ | ||
label: studyDataOrigin["name"], | ||
icon: "@FontAwesome5Solid/file/16", | ||
}); | ||
dragWidget.start(); | ||
|
||
// make it semi transparent while being dragged | ||
studyItem.setOpacity(0.2); | ||
}, | ||
|
||
dragOver: function(event, folderItem, workspaceDestId) { | ||
let compatible = false; | ||
const studyDataOrigin = event.getData("osparc-moveStudy")["studyDataOrigin"]; | ||
const workspaceIdOrigin = studyDataOrigin["workspaceId"]; | ||
const workspaceOrigin = osparc.store.Workspaces.getInstance().getWorkspace(workspaceIdOrigin); | ||
const workspaceDest = osparc.store.Workspaces.getInstance().getWorkspace(workspaceDestId); | ||
// Compatibility checks: | ||
// - Drag over "Shared Workspaces" (0) | ||
// - No | ||
// - My Workspace -> My Workspace (1) | ||
// - Yes | ||
// - My Workspace -> Shared Workspace (2) | ||
// - Delete on Study | ||
// - Write on dest Workspace | ||
// - Shared Workspace -> My Workspace (3) | ||
// - Delete on origin Workspace | ||
// - Shared Workspace -> Shared Workspace (4) | ||
// - Delete on origin Workspace | ||
// - Write on dest Workspace | ||
if (workspaceDestId === -1) { // (0) | ||
compatible = false; | ||
} else if (workspaceIdOrigin === null && workspaceDestId === null) { // (1) | ||
compatible = true; | ||
} else if (workspaceIdOrigin === null && workspaceDest) { // (2) | ||
compatible = osparc.data.model.Study.canIDelete(studyDataOrigin["accessRights"]) && workspaceDest.getMyAccessRights()["write"]; | ||
} else if (workspaceOrigin && workspaceDestId === null) { // (3) | ||
compatible = workspaceOrigin.getMyAccessRights()["delete"]; | ||
} else if (workspaceOrigin && workspaceDest) { // (4) | ||
compatible = workspaceOrigin.getMyAccessRights()["delete"] && workspaceDest.getMyAccessRights()["write"]; | ||
} | ||
|
||
if (!compatible) { | ||
// do not allow | ||
event.preventDefault(); | ||
} | ||
|
||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.setDropAllowed(compatible); | ||
|
||
folderItem.getChildControl("icon").setTextColor(compatible ? "strong-main" : "text"); | ||
}, | ||
|
||
drop: function(event, folderItem, destWorkspaceId, destFolderId) { | ||
const studyData = event.getData("osparc-moveStudy")["studyDataOrigin"]; | ||
const studyToFolderData = { | ||
studyData, | ||
destWorkspaceId, | ||
destFolderId, | ||
}; | ||
folderItem.getChildControl("icon").resetTextColor(); | ||
return studyToFolderData; | ||
}, | ||
}, | ||
|
||
moveFolder: { | ||
dragStart: function(event, folderItem, folderOrigin) { | ||
event.addAction("move"); | ||
event.addType("osparc-moveFolder"); | ||
event.addData("osparc-moveFolder", { | ||
"folderOrigin": folderOrigin, | ||
}); | ||
|
||
// init drag indicator | ||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.getChildControl("dragged-resource").set({ | ||
label: folderOrigin.getName(), | ||
icon: "@FontAwesome5Solid/folder/16", | ||
}); | ||
dragWidget.start(); | ||
|
||
// make it semi transparent while being dragged | ||
folderItem.setOpacity(0.2); | ||
}, | ||
|
||
dragOver: function(event, folderItem, workspaceDestId, folderDestId) { | ||
let compatible = false; | ||
const folderOrigin = event.getData("osparc-moveFolder")["folderOrigin"]; | ||
const workspaceIdOrigin = folderOrigin.getWorkspaceId(); | ||
const workspaceOrigin = osparc.store.Workspaces.getInstance().getWorkspace(workspaceIdOrigin); | ||
const workspaceDest = osparc.store.Workspaces.getInstance().getWorkspace(workspaceDestId); | ||
// Compatibility checks: | ||
// - Drag over "Shared Workspaces" (0) | ||
// - No | ||
// - My Workspace -> My Workspace (1) | ||
// - Yes | ||
// - My Workspace -> Shared Workspace (2) | ||
// - ~~Delete on Study~~ | ||
// - Write on dest Workspace | ||
// - Shared Workspace -> My Workspace (3) | ||
// - Delete on origin Workspace | ||
// - Shared Workspace -> Shared Workspace (4) | ||
// - Delete on origin Workspace | ||
// - Write on dest Workspace | ||
if (workspaceDestId === -1) { // (0) | ||
compatible = false; | ||
} else if (folderOrigin.getFolderId() === folderDestId) { | ||
compatible = false; | ||
} else if (workspaceIdOrigin === null && workspaceDestId === null) { // (1) | ||
compatible = true; | ||
} else if (workspaceIdOrigin === null && workspaceDest) { // (2) | ||
compatible = workspaceDest.getMyAccessRights()["write"]; | ||
} else if (workspaceOrigin && workspaceDestId === null) { // (3) | ||
compatible = workspaceOrigin.getMyAccessRights()["delete"]; | ||
} else if (workspaceOrigin && workspaceDest) { // (4) | ||
compatible = workspaceOrigin.getMyAccessRights()["delete"] && workspaceDest.getMyAccessRights()["write"]; | ||
} | ||
|
||
if (!compatible) { | ||
// do not allow | ||
event.preventDefault(); | ||
} | ||
|
||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.setDropAllowed(compatible); | ||
|
||
folderItem.getChildControl("icon").setTextColor(compatible ? "strong-main" : "text"); | ||
}, | ||
|
||
drop: function(event, folderItem, destWorkspaceId, destFolderId) { | ||
const folderOrigin = event.getData("osparc-moveFolder")["folderOrigin"]; | ||
const folderToFolderData = { | ||
folderId: folderOrigin.getFolderId(), | ||
destWorkspaceId, | ||
destFolderId, | ||
}; | ||
folderItem.getChildControl("icon").resetTextColor(); | ||
return folderToFolderData; | ||
}, | ||
}, | ||
|
||
dragLeave: function(item) { | ||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.setDropAllowed(false); | ||
|
||
item.getChildControl("icon").resetTextColor(); | ||
}, | ||
|
||
dragEnd: function(draggedItem) { | ||
// bring back opacity after drag | ||
draggedItem.setOpacity(1); | ||
|
||
// hide drag indicator | ||
const dragWidget = osparc.dashboard.DragWidget.getInstance(); | ||
dragWidget.end(); | ||
} | ||
} | ||
}); |
Oops, something went wrong.