Skip to content

Commit

Permalink
Merge Move Folder to
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Sep 26, 2024
1 parent 9204845 commit 4e7a41f
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
events: {
"folderSelected": "qx.event.type.Data",
"folderUpdated": "qx.event.type.Data",
"moveFolderToFolderRequested": "qx.event.type.Data",
"moveFolderToWorkspaceRequested": "qx.event.type.Data",
"moveFolderToRequested": "qx.event.type.Data",
"deleteFolderRequested": "qx.event.type.Data"
},

Expand Down Expand Up @@ -191,13 +190,9 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
editButton.addListener("execute", () => this.__editFolder(), this);
menu.add(editButton);

const moveToFolderButton = new qx.ui.menu.Button(this.tr("Move to Folder..."), "@FontAwesome5Solid/folder/12");
moveToFolderButton.addListener("execute", () => this.fireDataEvent("moveFolderToFolderRequested", this.getFolderId()), this);
menu.add(moveToFolderButton);

const moveToWorkspaceButton = new qx.ui.menu.Button(this.tr("Move to Workspace..."), osparc.store.Workspaces.iconPath(14));
moveToWorkspaceButton.addListener("execute", () => this.fireDataEvent("moveFolderToWorkspaceRequested", this.getFolderId()), this);
menu.add(moveToWorkspaceButton);
const moveToButton = new qx.ui.menu.Button(this.tr("Move to..."), "@FontAwesome5Solid/folder/12");
moveToButton.addListener("execute", () => this.fireDataEvent("moveFolderToRequested", this.getFolderId()), this);
menu.add(moveToButton);

menu.addSeparator();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* ************************************************************************
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.MoveResource", {
extend: qx.ui.core.Widget,

construct: function(currentWorkspaceId, currentFolderId) {
this.base(arguments);

this.__currentWorkspaceId = currentWorkspaceId;
this.__currentFolderId = currentFolderId;

this._setLayout(new qx.ui.layout.VBox(10));

this.getChildControl("current-location");

const workspacesAndFoldersTree = this.getChildControl("workspaces-and-folders-tree");
this.getChildControl("cancel-btn");
const moveButton = this.getChildControl("move-btn");

moveButton.setEnabled(false);
workspacesAndFoldersTree.addListener("changeCurrentWorkspaceId", e => {
const workspaceId = e.getData();
this.__selectedWorkspaceId = workspaceId;
moveButton.setEnabled(this.__currentWorkspaceId !== this.__selectedWorkspaceId || this.__currentFolderId !== this.__selectedFolderId);
}, this);
workspacesAndFoldersTree.addListener("changeCurrentFolderId", e => {
const folderId = e.getData();
this.__selectedFolderId = folderId;
moveButton.setEnabled(this.__currentWorkspaceId !== this.__selectedWorkspaceId || this.__currentFolderId !== this.__selectedFolderId);
}, this);
moveButton.addListener("execute", () => {
this.fireDataEvent("moveTo", {
workspaceId: this.__selectedWorkspaceId,
folderId: this.__selectedFolderId,
});
}, this);
},

events: {
"cancel": "qx.event.type.Event",
"moveTo": "qx.event.type.Data"
},

members: {
__currentWorkspaceId: null,
__currentFolderId: null,
__selectedWorkspaceId: null,
__selectedFolderId: null,

_createChildControlImpl: function(id) {
let control;
switch (id) {
case "current-location": {
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.__currentWorkspaceId);
let currentLocation = workspace ? workspace.getName() : "My Workspace";
const folder = osparc.store.Folders.getInstance().getFolder(this.__currentFolderId);
if (folder) {
// OM intermediate folders missing
currentLocation += " / " + folder.getName()
}
control = new qx.ui.basic.Label(this.tr("Current location: ") + currentLocation);
this._add(control);
break;
}
case "workspaces-and-folders-tree":
control = new osparc.dashboard.WorkspacesAndFoldersTree();
this._add(control);
break;
case "buttons-layout":
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(10).set({
alignX: "right"
}));
this._add(control);
break;
case "cancel-btn": {
const buttons = this.getChildControl("buttons-layout");
control = new qx.ui.form.Button(this.tr("Cancel")).set({
appearance: "form-button-text"
});
control.addListener("execute", () => this.fireEvent("cancel"), this);
buttons.add(control);
break;
}
case "move-btn": {
const buttons = this.getChildControl("buttons-layout");
control = new qx.ui.form.Button(this.tr("Move")).set({
appearance: "form-button"
});
buttons.add(control);
break;
}
}
return control || this.base(arguments, id);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
resourcesContainer.addListener("tagClicked", e => this._searchBarFilter.addTagActiveFilter(e.getData()));
resourcesContainer.addListener("emptyStudyClicked", e => this._deleteResourceRequested(e.getData()));
resourcesContainer.addListener("folderUpdated", e => this._folderUpdated(e.getData()));
resourcesContainer.addListener("moveFolderToFolderRequested", e => this._moveFolderToFolderRequested(e.getData()));
resourcesContainer.addListener("moveFolderToWorkspaceRequested", e => this._moveFolderToWorkspaceRequested(e.getData()));
resourcesContainer.addListener("moveFolderToRequested", e => this._moveFolderToRequested(e.getData()));
resourcesContainer.addListener("deleteFolderRequested", e => this._deleteFolderRequested(e.getData()));
resourcesContainer.addListener("folderSelected", e => {
const folderId = e.getData();
Expand Down Expand Up @@ -492,11 +491,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
throw new Error("Abstract method called!");
},

_moveFolderToFolderRequested: function(folderId) {
throw new Error("Abstract method called!");
},

_moveFolderToWorkspaceRequested: function(folderId) {
_moveFolderToRequested: function(folderId) {
throw new Error("Abstract method called!");
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
"changeVisibility": "qx.event.type.Data",
"folderSelected": "qx.event.type.Data",
"folderUpdated": "qx.event.type.Data",
"moveFolderToFolderRequested": "qx.event.type.Data",
"moveFolderToWorkspaceRequested": "qx.event.type.Data",
"moveFolderToRequested": "qx.event.type.Data",
"deleteFolderRequested": "qx.event.type.Data",
"workspaceSelected": "qx.event.type.Data",
"workspaceUpdated": "qx.event.type.Data",
Expand Down Expand Up @@ -385,8 +384,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
[
"folderSelected",
"folderUpdated",
"moveFolderToFolderRequested",
"moveFolderToWorkspaceRequested",
"moveFolderToRequested",
"deleteFolderRequested",
].forEach(eName => card.addListener(eName, e => this.fireDataEvent(eName, e.getData())));
return card;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,27 +513,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
this.__reloadFolders();
},

_moveFolderToFolderRequested: function(folderId) {
const moveFolderToFolder = new osparc.dashboard.MoveResourceToFolder(this.getCurrentFolderId(), this.getCurrentWorkspaceId());
const title = "Move to Folder";
const win = osparc.ui.window.Window.popUpInWindow(moveFolderToFolder, title, 350, 280);
moveFolderToFolder.addListener("moveToFolder", e => {
win.close();
const folder = osparc.store.Folders.getInstance().getFolder(folderId);
const destFolderId = e.getData();
const updatedData = {
name: folder.getName(),
parentFolderId: destFolderId,
};
osparc.store.Folders.getInstance().putFolder(folderId, updatedData)
.then(() => {
folder.setParentFolderId(destFolderId);
this.__reloadFolders()
})
.catch(err => console.error(err));
});
},

__showMoveToWorkspaceWarningMessage: function() {
const msg = this.tr("The permissions will be taken from the new workspace?");
const win = new osparc.ui.window.Confirmation(msg).set({
Expand All @@ -543,40 +522,65 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
return win;
},

_moveFolderToWorkspaceRequested: function(folderId) {
const folderToWorkspaceRequested = false;
if (!folderToWorkspaceRequested) {
const msg = this.tr("Coming soon");
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
return;
}
const moveFolderToWorkspace = new osparc.dashboard.MoveResourceToWorkspace(this.getCurrentWorkspaceId());
const title = "Move to Workspace";
const win = osparc.ui.window.Window.popUpInWindow(moveFolderToWorkspace, title, 350, 280);
moveFolderToWorkspace.addListener("moveToWorkspace", e => {
_moveFolderToRequested: function(workspaceId, folderId) {
const moveFolderToFolder = new osparc.dashboard.MoveResource(this.getCurrentWorkspaceId(), this.getCurrentFolderId());
const title = "Move to...";
const win = osparc.ui.window.Window.popUpInWindow(moveFolderToFolder, title, 350, 280);
moveFolderToFolder.addListener("moveTo", e => {
win.close();
const destWorkspaceId = e.getData();
const data = e.getData();
const destWorkspaceId = data["workspaceId"];
const destFolderId = data["folderId"];
if (destWorkspaceId !== workspaceId) {
const msg = this.tr("Coming soon");
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
return;
}
// OM only if workspace changed
const confirmationWin = this.__showMoveToWorkspaceWarningMessage();
confirmationWin.addListener("close", () => {
if (confirmationWin.getConfirmed()) {
const params = {
url: {
folderId,
workspaceId: destWorkspaceId,
}
};
osparc.data.Resources.fetch("folders", "moveToWorkspace", params)
.then(() => {
const folder = osparc.store.Folders.getInstance().getFolder(folderId);
if (folder) {
folder.setWorkspaceId(destWorkspaceId);
}
this.__reloadFolders()
})
Promise.all([
this.__moveFolderToWorkspaceRequested(folderId, destWorkspaceId),
this.__moveFolderToFolderRequested(folderId, destFolderId),
])
.then(() => this.__reloadFolders())
.catch(err => console.error(err));
}
}, this);
}, this);
});
},

__moveFolderToWorkspaceRequested: function(folderId, destWorkspaceId) {
const folder = osparc.store.Folders.getInstance().getFolder(folderId);
if (folder.getWorkspaceId() === destWorkspaceId) {
// resolve right away
return new Promise(resolve => resolve());
}
const params = {
url: {
folderId,
workspaceId: destWorkspaceId,
}
};
return osparc.data.Resources.fetch("folders", "moveToWorkspace", params)
.then(() => folder.setWorkspaceId(destWorkspaceId))
.catch(err => console.error(err));
},

__moveFolderToFolderRequested: function(folderId, destFolderId) {
if (folderId === destFolderId) {
// resolve right away
return new Promise(resolve => resolve());
}
const folder = osparc.store.Folders.getInstance().getFolder(folderId);
const updatedData = {
name: folder.getName(),
parentFolderId: destFolderId,
};
return osparc.store.Folders.getInstance().putFolder(folderId, updatedData)
.then(() => folder.setParentFolderId(destFolderId))
.catch(err => console.error(err));
},

_deleteFolderRequested: function(folderId) {
Expand Down

0 comments on commit 4e7a41f

Please sign in to comment.