From ae8660980f5a9cfd44182855ef7297a372a445db Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 15:30:09 +0100 Subject: [PATCH 1/8] Move button --- .../client/source/class/osparc/dashboard/MoveResourceTo.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js b/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js index cd9a98d1d6f..ecd26def377 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/MoveResourceTo.js @@ -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) { From dff90b6bb06dd23af5dc6dcee90dddaedb76020c Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 15:32:27 +0100 Subject: [PATCH 2/8] first move to workspace, then move to folder --- .../source/class/osparc/dashboard/StudyBrowser.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index 327de47602c..08b6df02b3c 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -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), - ]) + this.__moveFolderToWorkspace(folderId, destWorkspaceId) // first move to workspace + .then(this.__moveFolderToFolder(folderId, destFolderId)) // then move to folder .then(() => this.__reloadFolders()) .catch(err => console.error(err)); } @@ -1243,10 +1241,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); From 9286e94ea498da5154868455788833468a194dd0 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 15:37:05 +0100 Subject: [PATCH 3/8] [skip ci] last moving --- .../client/source/class/osparc/dashboard/StudyBrowser.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index 08b6df02b3c..f932a6c13e4 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -1663,10 +1663,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); From 0a837a7257ba9c68fbc2908f8c67113e98a285dc Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 15:46:10 +0100 Subject: [PATCH 4/8] minor fix --- .../class/osparc/desktop/preferences/pages/GeneralPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js index dffafeabc72..70095507e49 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/GeneralPage.js @@ -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(); @@ -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(); } @@ -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())); From 5f59c4cf341de86489eebd73efce7c3aede82228 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 15:50:34 +0100 Subject: [PATCH 5/8] fix --- .../client/source/class/osparc/dashboard/StudyBrowser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index f932a6c13e4..6a39aa2ea56 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -577,7 +577,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { const destFolderId = data["folderId"]; const moveFolder = () => { this.__moveFolderToWorkspace(folderId, destWorkspaceId) // first move to workspace - .then(this.__moveFolderToFolder(folderId, destFolderId)) // then move to folder + .then(() => this.__moveFolderToFolder(folderId, destFolderId)) // then move to folder .then(() => this.__reloadFolders()) .catch(err => console.error(err)); } From e49a5be96711257bee1a7146f8982b7b9f3aabe4 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 16:05:40 +0100 Subject: [PATCH 6/8] refactor --- .../class/osparc/dashboard/StudyBrowser.js | 36 +--------------- .../source/class/osparc/store/Folders.js | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index 6a39aa2ea56..0a25257f247 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -576,8 +576,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { const destWorkspaceId = data["workspaceId"]; const destFolderId = data["folderId"]; const moveFolder = () => { - this.__moveFolderToWorkspace(folderId, destWorkspaceId) // first move to workspace - .then(() => this.__moveFolderToFolder(folderId, destFolderId)) // then move to folder + 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)); } @@ -595,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(() => { diff --git a/services/static-webserver/client/source/class/osparc/store/Folders.js b/services/static-webserver/client/source/class/osparc/store/Folders.js index 4206cb212dd..cc344c6e33b 100644 --- a/services/static-webserver/client/source/class/osparc/store/Folders.js +++ b/services/static-webserver/client/source/class/osparc/store/Folders.js @@ -223,6 +223,47 @@ qx.Class.define("osparc.store.Folders", { .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 oldParentFolderId = folder.getParentFolderId(); + const params = { + url: { + folderId, + workspaceId: destWorkspaceId, + } + }; + return osparc.data.Resources.fetch("folders", "moveToWorkspace", params) + .then(() => { + folder.setWorkspaceId(destWorkspaceId); + this.fireDataEvent("folderMoved", { + folder, + oldParentFolderId, + }); + }) + .catch(err => console.error(err)); + }, + getFolder: function(folderId = null) { return this.foldersCached.find(f => f.getFolderId() === folderId); }, From 5347b7adc52aea02658c938059fb6012f55b13f0 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 16:47:08 +0100 Subject: [PATCH 7/8] it works --- .../osparc/dashboard/WorkspacesAndFoldersTree.js | 3 ++- .../client/source/class/osparc/store/Folders.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js index da5a21797f1..2a057dba36d 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js @@ -303,7 +303,8 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", { // eslint-disable-next-line no-negated-condition const parentModel = this.__getModel(folder.getWorkspaceId(), oldParentFolderId !== undefined ? oldParentFolderId : folder.getParentFolderId()); if (parentModel) { - const idx = parentModel.getChildren().toArray().findIndex(c => folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId()); + console.log("folder removed: children", parentModel.getChildren().toArray()); + 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); } diff --git a/services/static-webserver/client/source/class/osparc/store/Folders.js b/services/static-webserver/client/source/class/osparc/store/Folders.js index cc344c6e33b..778189eb558 100644 --- a/services/static-webserver/client/source/class/osparc/store/Folders.js +++ b/services/static-webserver/client/source/class/osparc/store/Folders.js @@ -212,13 +212,22 @@ qx.Class.define("osparc.store.Folders", { }; return osparc.data.Resources.getInstance().fetch("folders", "update", params) .then(folderData => { - this.__addToCache(folderData); + 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); + } + /* if (updateData.parentFolderId !== oldParentFolderId) { this.fireDataEvent("folderMoved", { folder, oldParentFolderId, }); } + */ }) .catch(console.error); }, @@ -255,11 +264,15 @@ qx.Class.define("osparc.store.Folders", { }; return osparc.data.Resources.fetch("folders", "moveToWorkspace", params) .then(() => { + this.fireDataEvent("folderRemoved", folder); folder.setWorkspaceId(destWorkspaceId); + this.fireDataEvent("folderAdded", folder); + /* this.fireDataEvent("folderMoved", { folder, oldParentFolderId, }); + */ }) .catch(err => console.error(err)); }, From 60856448c63c0029985ac8f6bedc2df9401bcb10 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Wed, 4 Dec 2024 16:48:12 +0100 Subject: [PATCH 8/8] cleanup --- .../dashboard/WorkspacesAndFoldersTree.js | 29 +++++-------------- .../source/class/osparc/store/Folders.js | 16 ---------- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js index 2a057dba36d..01cea4d878c 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/WorkspacesAndFoldersTree.js @@ -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); @@ -299,26 +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) { - console.log("folder removed: children", parentModel.getChildren().toArray()); 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 } } }, diff --git a/services/static-webserver/client/source/class/osparc/store/Folders.js b/services/static-webserver/client/source/class/osparc/store/Folders.js index 778189eb558..bf7657a3279 100644 --- a/services/static-webserver/client/source/class/osparc/store/Folders.js +++ b/services/static-webserver/client/source/class/osparc/store/Folders.js @@ -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: { @@ -220,14 +219,6 @@ qx.Class.define("osparc.store.Folders", { if (folderMoved) { this.fireDataEvent("folderAdded", folder); } - /* - if (updateData.parentFolderId !== oldParentFolderId) { - this.fireDataEvent("folderMoved", { - folder, - oldParentFolderId, - }); - } - */ }) .catch(console.error); }, @@ -255,7 +246,6 @@ qx.Class.define("osparc.store.Folders", { return new Promise(resolve => resolve()); } - const oldParentFolderId = folder.getParentFolderId(); const params = { url: { folderId, @@ -267,12 +257,6 @@ qx.Class.define("osparc.store.Folders", { this.fireDataEvent("folderRemoved", folder); folder.setWorkspaceId(destWorkspaceId); this.fireDataEvent("folderAdded", folder); - /* - this.fireDataEvent("folderMoved", { - folder, - oldParentFolderId, - }); - */ }) .catch(err => console.error(err)); },