Skip to content

Commit

Permalink
🐛 [Frontend] Fix: Move folder to a different workspace and subfolder (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Dec 5, 2024
1 parent 3ade7ef commit cba896a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ qx.Class.define("osparc.dashboard.MoveResourceTo", {

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

moveButton.setEnabled(false);
const moveButton = this.getChildControl("move-btn");
moveButton.setEnabled(currentWorkspaceId !== null || currentFolderId !== null); // disable if current location is My Workspace's root
workspacesAndFoldersTree.getSelection().addListener("change", () => {
const selection = workspacesAndFoldersTree.getSelection();
if (selection.getLength() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
const destWorkspaceId = data["workspaceId"];
const destFolderId = data["folderId"];
const moveFolder = () => {
Promise.all([
this.__moveFolderToWorkspace(folderId, destWorkspaceId),
this.__moveFolderToFolder(folderId, destFolderId),
])
osparc.store.Folders.getInstance().moveFolderToWorkspace(folderId, destWorkspaceId) // first move to workspace
.then(() => osparc.store.Folders.getInstance().moveFolderToFolder(folderId, destFolderId)) // then move to folder
.then(() => this.__reloadFolders())
.catch(err => console.error(err));
}
Expand All @@ -597,38 +595,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
moveFolderTo.addListener("cancel", () => win.close());
},

__moveFolderToWorkspace: 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));
},

__moveFolderToFolder: 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));
},

_trashFolderRequested: function(folderId) {
osparc.store.Folders.getInstance().trashFolder(folderId, this.getCurrentWorkspaceId())
.then(() => {
Expand Down Expand Up @@ -1243,10 +1209,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
const selection = this._resourcesContainer.getSelection();
selection.forEach(button => {
const studyData = button.getResourceData();
Promise.all([
this.__moveStudyToWorkspace(studyData, destWorkspaceId),
this.__moveStudyToFolder(studyData, destFolderId),
])
this.__moveStudyToWorkspace(studyData, destWorkspaceId) // first move to workspace
.then(() => this.__moveStudyToFolder(studyData, destFolderId)) // then move to folder
.then(() => this.__removeFromStudyList(studyData["uuid"]))
.catch(err => {
console.error(err);
Expand Down Expand Up @@ -1667,10 +1631,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
const destWorkspaceId = data["workspaceId"];
const destFolderId = data["folderId"];
const moveStudy = () => {
Promise.all([
this.__moveStudyToWorkspace(studyData, destWorkspaceId),
this.__moveStudyToFolder(studyData, destFolderId),
])
this.__moveStudyToWorkspace(studyData, destWorkspaceId) // first move to workspace
.then(() => this.__moveStudyToFolder(studyData, destFolderId)) // then move to folder
.then(() => this.__removeFromStudyList(studyData["uuid"]))
.catch(err => {
console.error(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
this.__folderRemoved(folder);
}, this);

osparc.store.Folders.getInstance().addListener("folderMoved", e => {
const {
folder,
oldParentFolderId,
} = e.getData();
this.__folderRemoved(folder, oldParentFolderId);
this.__folderAdded(folder);
}, this);

osparc.store.Workspaces.getInstance().addListener("workspaceAdded", e => {
const workspace = e.getData();
this.__addWorkspace(workspace);
Expand Down Expand Up @@ -299,25 +290,22 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
}
},

__folderRemoved: function(folder, oldParentFolderId) {
__folderRemoved: function(folder) {
// eslint-disable-next-line no-negated-condition
const parentModel = this.__getModel(folder.getWorkspaceId(), oldParentFolderId !== undefined ? oldParentFolderId : folder.getParentFolderId());
const parentModel = this.__getModel(folder.getWorkspaceId(), folder.getParentFolderId());
if (parentModel) {
const idx = parentModel.getChildren().toArray().findIndex(c => folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId());
const idx = parentModel.getChildren().toArray().findIndex(c => "getWorkspaceId" in c && folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId());
if (idx > -1) {
parentModel.getChildren().removeAt(idx);
}
}

if (oldParentFolderId === undefined) {
// it was removed, not moved
// remove it from the cached models
const modelFound = this.__getModel(folder.getWorkspaceId(), folder.getFolderId());
if (modelFound) {
const index = this.__models.indexOf(modelFound);
if (index > -1) { // only splice array when item is found
this.__models.splice(index, 1); // 2nd parameter means remove one item only
}
// remove it from the cached models
const modelFound = this.__getModel(folder.getWorkspaceId(), folder.getFolderId());
if (modelFound) {
const index = this.__models.indexOf(modelFound);
if (index > -1) { // only splice array when item is found
this.__models.splice(index, 1); // 2nd parameter means remove one item only
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", {
if (osparc.desktop.credits.Utils.areWalletsEnabled()) {
this.__addCreditsIndicatorSettings();
}

const preferences = osparc.Preferences.getInstance();
if (preferences.getLowDiskSpaceThreshold()) {
this.__addLowDiskSpaceSetting();
Expand All @@ -38,7 +38,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", {
}

// this.__addJobConcurrencySetting();

if (osparc.product.Utils.isS4LProduct() || osparc.product.Utils.isProduct("s4llite")) {
this.__addS4LUserPrivacySettings();
}
Expand Down Expand Up @@ -147,6 +147,7 @@ qx.Class.define("osparc.desktop.preferences.pages.GeneralPage", {
allowGrowX: false,
enabled: true
});
const preferences = osparc.Preferences.getInstance();
preferences.bind("lowDiskSpaceThreshold", diskUsageSpinner, "value");

diskUsageSpinner.addListener("changeValue", e => osparc.Preferences.patchPreferenceField("lowDiskSpaceThreshold", diskUsageSpinner, e.getData()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ qx.Class.define("osparc.store.Folders", {
events: {
"folderAdded": "qx.event.type.Data",
"folderRemoved": "qx.event.type.Data",
"folderMoved": "qx.event.type.Data",
},

statics: {
Expand Down Expand Up @@ -212,17 +211,56 @@ qx.Class.define("osparc.store.Folders", {
};
return osparc.data.Resources.getInstance().fetch("folders", "update", params)
.then(folderData => {
this.__addToCache(folderData);
if (updateData.parentFolderId !== oldParentFolderId) {
this.fireDataEvent("folderMoved", {
folder,
oldParentFolderId,
});
const folderMoved = updateData.parentFolderId !== oldParentFolderId;
if (folderMoved) {
this.fireDataEvent("folderRemoved", folder);
}
this.__addToCache(folderData); // it will update the folder model
if (folderMoved) {
this.fireDataEvent("folderAdded", folder);
}
})
.catch(console.error);
},

moveFolderToFolder: function(folderId, destFolderId) {
if (folderId === destFolderId) {
// resolve right away
return new Promise(resolve => resolve());
}

const folder = this.getFolder(folderId);
const updatedData = {
name: folder.getName(),
parentFolderId: destFolderId,
};
return this.putFolder(folderId, updatedData)
.then(() => folder.setParentFolderId(destFolderId))
.catch(err => console.error(err));
},

moveFolderToWorkspace: function(folderId, destWorkspaceId) {
const folder = this.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(() => {
this.fireDataEvent("folderRemoved", folder);
folder.setWorkspaceId(destWorkspaceId);
this.fireDataEvent("folderAdded", folder);
})
.catch(err => console.error(err));
},

getFolder: function(folderId = null) {
return this.foldersCached.find(f => f.getFolderId() === folderId);
},
Expand Down

0 comments on commit cba896a

Please sign in to comment.