From d793098ed9366067703e3134775036a6da8dda2a Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 11:15:33 +0200 Subject: [PATCH 01/48] renaming --- .../client/source/class/osparc/desktop/StudyEditor.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 4b0848288d2..d0d571fdb52 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -126,7 +126,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { __slideshowView: null, __autoSaveTimer: null, __studyEditorIdlingTracker: null, - __lastSavedStudy: null, + __studyDataInBackend: null, __updatingStudy: null, __updateThrottled: null, __nodesSlidesTree: null, @@ -169,7 +169,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { study.openStudy() .then(() => { - this.__lastSavedStudy = osparc.utils.Utils.deepCloneObject(study.serialize()); + this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(study.serialize()); this.__workbenchView.setStudy(study); this.__slideshowView.setStudy(study); @@ -720,7 +720,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { didStudyChange: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); - const delta = diffPatcher.diff(this.__lastSavedStudy, newObj); + const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); if (delta) { let deltaKeys = Object.keys(delta); // lastChangeDate and creationDate should not be taken into account as data change @@ -761,7 +761,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { const newObj = this.getStudy().serialize(); return this.getStudy().updateStudy(newObj, run) .then(() => { - this.__lastSavedStudy = osparc.utils.Utils.deepCloneObject(newObj); + this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(newObj); }) .catch(error => { if ("status" in error && error.status === 409) { From 575acb7f325ae4e8868b589a65f466795fc362dc Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 11:17:16 +0200 Subject: [PATCH 02/48] getStudyChanges --- .../client/source/class/osparc/desktop/MainPage.js | 2 +- .../client/source/class/osparc/desktop/StudyEditor.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js index ad1d6f6441c..51fe34df6c3 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js @@ -155,7 +155,7 @@ qx.Class.define("osparc.desktop.MainPage", { __backToDashboard: async function() { const dashboardBtn = this.__navBar.getChildControl("dashboard-button"); dashboardBtn.setFetching(true); - if (this.__studyEditor.didStudyChange()) { + if (this.__studyEditor.getStudyChanges().length) { // make sure very latest changes are saved await this.__studyEditor.updateStudyDocument(false); } diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index d0d571fdb52..0d5ca58293f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -717,7 +717,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__stopAutoSaveTimer(); }, - didStudyChange: function() { + getStudyChanges: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); @@ -734,13 +734,13 @@ qx.Class.define("osparc.desktop.StudyEditor", { } }); - return deltaKeys.length; + return deltaKeys; } - return false; + return []; }, __checkStudyChanges: function() { - if (this.didStudyChange()) { + if (this.getStudyChanges().length) { if (this.__updatingStudy > 0) { // throttle update this.__updateThrottled = true; From f23280c2fe51bfefe6f9923fbc6718458e42dc34 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 11:34:15 +0200 Subject: [PATCH 03/48] minor --- .../class/osparc/desktop/StudyEditor.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 0d5ca58293f..0cccc231eaf 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -722,19 +722,14 @@ qx.Class.define("osparc.desktop.StudyEditor", { const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); if (delta) { - let deltaKeys = Object.keys(delta); // lastChangeDate and creationDate should not be taken into account as data change - [ - "creationDate", - "lastChangeDate" - ].forEach(prop => { - const index = deltaKeys.indexOf(prop); - if (index > -1) { - deltaKeys.splice(index, 1); - } - }); - - return deltaKeys; + delete delta["creationDate"]; + delete delta["lastChangeDate"]; + const deltaKeys = Object.keys(delta); + if (deltaKeys.length) { + console.log("delta", delta); + return deltaKeys; + } } return []; }, From 8c68429e035a1c21e26bf097c7c3fbbb6d72dffd Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 11:43:38 +0200 Subject: [PATCH 04/48] patchStudy expects array of changes --- .../source/class/osparc/data/model/Study.js | 22 ++++++++++++++----- .../source/class/osparc/info/MergedLarge.js | 5 ++++- .../source/class/osparc/info/StudyLarge.js | 5 ++++- .../source/class/osparc/info/StudyUtils.js | 5 ++++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index f34ce1865ef..58ff8813518 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -595,10 +595,16 @@ qx.Class.define("osparc.data.model.Study", { return jsonObject; }, - patchStudy: function(fieldKey, value) { + patchStudy: function(studyChanges) { return new Promise((resolve, reject) => { const patchData = {}; - patchData[fieldKey] = value; + studyChanges.forEach(studyChange => { + const { + fieldKey, + value + } = studyChange; + patchData[fieldKey] = value; + }); const params = { url: { "studyId": this.getUuid() @@ -607,9 +613,15 @@ qx.Class.define("osparc.data.model.Study", { }; osparc.data.Resources.fetch("studies", "patch", params) .then(() => { - const upKey = qx.lang.String.firstUp(fieldKey); - const setter = "set" + upKey; - this[setter](value); + studyChanges.forEach(studyChange => { + const { + fieldKey, + value + } = studyChange; + const upKey = qx.lang.String.firstUp(fieldKey); + const setter = "set" + upKey; + this[setter](value); + }); // A bit hacky, but it's not sent back to the backend this.set({ lastChangeDate: new Date() diff --git a/services/static-webserver/client/source/class/osparc/info/MergedLarge.js b/services/static-webserver/client/source/class/osparc/info/MergedLarge.js index 39d909633c9..64aa5a6cc2b 100644 --- a/services/static-webserver/client/source/class/osparc/info/MergedLarge.js +++ b/services/static-webserver/client/source/class/osparc/info/MergedLarge.js @@ -400,7 +400,10 @@ qx.Class.define("osparc.info.MergedLarge", { }, __patchStudy: function(fieldKey, value) { - this.getStudy().patchStudy(fieldKey, value) + this.getStudy().patchStudy([{ + fieldKey, + value + }]) .then(studyData => { this.fireDataEvent("updateStudy", studyData); qx.event.message.Bus.getInstance().dispatchByName("updateStudy", studyData); diff --git a/services/static-webserver/client/source/class/osparc/info/StudyLarge.js b/services/static-webserver/client/source/class/osparc/info/StudyLarge.js index fb9e4b942e5..7780b47db59 100644 --- a/services/static-webserver/client/source/class/osparc/info/StudyLarge.js +++ b/services/static-webserver/client/source/class/osparc/info/StudyLarge.js @@ -320,7 +320,10 @@ qx.Class.define("osparc.info.StudyLarge", { }, __patchStudy: function(fieldKey, value) { - this.getStudy().patchStudy(fieldKey, value) + this.getStudy().patchStudy([{ + fieldKey, + value + }]) .then(studyData => { studyData["resourceType"] = this.__isTemplate ? "template" : "study"; this.fireDataEvent("updateStudy", studyData); diff --git a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js index 2b0fc11524a..e0e25c13837 100644 --- a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js +++ b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js @@ -197,7 +197,10 @@ qx.Class.define("osparc.info.StudyUtils", { const newVal = e.getData(); const devObjCopy = osparc.utils.Utils.deepCloneObject(devObj); devObjCopy["disableServiceAutoStart"] = !newVal; - study.patchStudy("dev", devObjCopy); + study.patchStudy([{ + fieldKey: "dev", + value: devObjCopy + }]); }); return cb; }, From 726225a281cf18633165942cd606f0a1338086f6 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 11:55:51 +0200 Subject: [PATCH 05/48] deprecate run argument --- .../client/source/class/osparc/data/model/Study.js | 5 ++--- .../client/source/class/osparc/desktop/MainPage.js | 2 +- .../source/class/osparc/desktop/StudyEditor.js | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 58ff8813518..415003e9359 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -633,12 +633,11 @@ qx.Class.define("osparc.data.model.Study", { }); }, - updateStudy: function(params, run = false) { + updateStudy: function(params) { return new Promise((resolve, reject) => { osparc.data.Resources.fetch("studies", "put", { url: { - "studyId": this.getUuid(), - run + "studyId": this.getUuid() }, data: { ...this.serialize(), diff --git a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js index 51fe34df6c3..c988f4865e9 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js @@ -157,7 +157,7 @@ qx.Class.define("osparc.desktop.MainPage", { dashboardBtn.setFetching(true); if (this.__studyEditor.getStudyChanges().length) { // make sure very latest changes are saved - await this.__studyEditor.updateStudyDocument(false); + await this.__studyEditor.updateStudyDocument(); } this.closeEditor(); this.__showDashboard(); diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 0cccc231eaf..8239a99a9e2 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -453,7 +453,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { } this.getStudy().setPipelineRunning(true); - this.updateStudyDocument(true) + this.updateStudyDocument() .then(() => { this.__requestStartPipeline(this.getStudy().getUuid(), partialPipeline); }) @@ -565,7 +565,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { // ------------------ START/STOP PIPELINE ------------------ __updatePipelineAndRetrieve: function(node, portKey = null) { - this.updateStudyDocument(false) + this.updateStudyDocument() .then(() => { if (node) { this.getStudyLogger().debug(node.getNodeId(), "Retrieving inputs"); @@ -740,12 +740,12 @@ qx.Class.define("osparc.desktop.StudyEditor", { // throttle update this.__updateThrottled = true; } else { - this.updateStudyDocument(false); + this.updateStudyDocument(); } } }, - updateStudyDocument: function(run = false) { + updateStudyDocument: function() { if (!osparc.data.model.Study.canIWrite(this.getStudy().getAccessRights())) { return new Promise(resolve => { resolve(); @@ -754,7 +754,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy++; const newObj = this.getStudy().serialize(); - return this.getStudy().updateStudy(newObj, run) + return this.getStudy().updateStudy(newObj) .then(() => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(newObj); }) @@ -773,7 +773,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy--; if (this.__updateThrottled && this.__updatingStudy === 0) { this.__updateThrottled = false; - this.updateStudyDocument(false); + this.updateStudyDocument(); } }); }, From 5e96bc122fe6696534e0d7ab6f5d86031cad5bda Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 12:29:15 +0200 Subject: [PATCH 06/48] minor --- .../client/source/class/osparc/desktop/StudyEditor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 8239a99a9e2..c0de06464bf 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -725,6 +725,13 @@ qx.Class.define("osparc.desktop.StudyEditor", { // lastChangeDate and creationDate should not be taken into account as data change delete delta["creationDate"]; delete delta["lastChangeDate"]; + Object.entries((key, val) => { + // keep only the new value + // JsonDiffPatch returns {key: [old_value, ney_value]} + if (val.length > 1) { + delta[key] = val[1]; + } + }); const deltaKeys = Object.keys(delta); if (deltaKeys.length) { console.log("delta", delta); From 15825a596c781614ae44ca3306bbcbcf0270234e Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 12:31:56 +0200 Subject: [PATCH 07/48] __getStudyChanges --- .../source/class/osparc/desktop/MainPage.js | 2 +- .../source/class/osparc/desktop/StudyEditor.js | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js index c988f4865e9..07be7277cd8 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/MainPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/MainPage.js @@ -155,7 +155,7 @@ qx.Class.define("osparc.desktop.MainPage", { __backToDashboard: async function() { const dashboardBtn = this.__navBar.getChildControl("dashboard-button"); dashboardBtn.setFetching(true); - if (this.__studyEditor.getStudyChanges().length) { + if (this.__studyEditor.didStudyChange()) { // make sure very latest changes are saved await this.__studyEditor.updateStudyDocument(); } diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index c0de06464bf..406b92e00e8 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -717,7 +717,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__stopAutoSaveTimer(); }, - getStudyChanges: function() { + __getStudyChanges: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); @@ -732,17 +732,19 @@ qx.Class.define("osparc.desktop.StudyEditor", { delta[key] = val[1]; } }); - const deltaKeys = Object.keys(delta); - if (deltaKeys.length) { - console.log("delta", delta); - return deltaKeys; - } + console.log("delta", delta); + return delta; } return []; }, + didStudyChange: function() { + const studyChanges = this.__getStudyChanges(); + return Boolean(studyChanges.length); + }, + __checkStudyChanges: function() { - if (this.getStudyChanges().length) { + if (this.didStudyChange()) { if (this.__updatingStudy > 0) { // throttle update this.__updateThrottled = true; @@ -760,6 +762,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { } this.__updatingStudy++; + const studyChanges = this.__getStudyChanges(); const newObj = this.getStudy().serialize(); return this.getStudy().updateStudy(newObj) .then(() => { From 6fbdf5ff3ac11e91d8e25c33020460e79ea865bf Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 12:34:17 +0200 Subject: [PATCH 08/48] minor --- .../client/source/class/osparc/desktop/StudyEditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 406b92e00e8..1be009dbca5 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -725,7 +725,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { // lastChangeDate and creationDate should not be taken into account as data change delete delta["creationDate"]; delete delta["lastChangeDate"]; - Object.entries((key, val) => { + Object.entries(delta).forEach(([key, val]) => { // keep only the new value // JsonDiffPatch returns {key: [old_value, ney_value]} if (val.length > 1) { From 88ccf26d0370cefba3ed2491876ab1337b8e81b6 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 12:38:07 +0200 Subject: [PATCH 09/48] fixes --- .../client/source/class/osparc/desktop/StudyEditor.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 1be009dbca5..234c2abf01a 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -725,11 +725,11 @@ qx.Class.define("osparc.desktop.StudyEditor", { // lastChangeDate and creationDate should not be taken into account as data change delete delta["creationDate"]; delete delta["lastChangeDate"]; - Object.entries(delta).forEach(([key, val]) => { + Object.entries(delta).forEach(([key, data]) => { // keep only the new value // JsonDiffPatch returns {key: [old_value, ney_value]} - if (val.length > 1) { - delta[key] = val[1]; + if (data.length > 1) { + delta[key] = data[1]; } }); console.log("delta", delta); @@ -740,7 +740,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { didStudyChange: function() { const studyChanges = this.__getStudyChanges(); - return Boolean(studyChanges.length); + return Boolean(Object.keys(studyChanges).length); }, __checkStudyChanges: function() { From 9b16520559ce2f16cc50efc4751551ae2b428f59 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:32:43 +0200 Subject: [PATCH 10/48] patchStudy expects object --- .../client/source/class/osparc/data/model/Study.js | 9 +-------- .../client/source/class/osparc/info/MergedLarge.js | 5 +---- .../client/source/class/osparc/info/StudyLarge.js | 5 +---- .../client/source/class/osparc/info/StudyUtils.js | 5 +---- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 415003e9359..b3ce0417da4 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -597,14 +597,7 @@ qx.Class.define("osparc.data.model.Study", { patchStudy: function(studyChanges) { return new Promise((resolve, reject) => { - const patchData = {}; - studyChanges.forEach(studyChange => { - const { - fieldKey, - value - } = studyChange; - patchData[fieldKey] = value; - }); + const patchData = studyChanges; const params = { url: { "studyId": this.getUuid() diff --git a/services/static-webserver/client/source/class/osparc/info/MergedLarge.js b/services/static-webserver/client/source/class/osparc/info/MergedLarge.js index 64aa5a6cc2b..3c8cb9dc76a 100644 --- a/services/static-webserver/client/source/class/osparc/info/MergedLarge.js +++ b/services/static-webserver/client/source/class/osparc/info/MergedLarge.js @@ -400,10 +400,7 @@ qx.Class.define("osparc.info.MergedLarge", { }, __patchStudy: function(fieldKey, value) { - this.getStudy().patchStudy([{ - fieldKey, - value - }]) + this.getStudy().patchStudy({[fieldKey]: value}) .then(studyData => { this.fireDataEvent("updateStudy", studyData); qx.event.message.Bus.getInstance().dispatchByName("updateStudy", studyData); diff --git a/services/static-webserver/client/source/class/osparc/info/StudyLarge.js b/services/static-webserver/client/source/class/osparc/info/StudyLarge.js index 7780b47db59..881b199e0f3 100644 --- a/services/static-webserver/client/source/class/osparc/info/StudyLarge.js +++ b/services/static-webserver/client/source/class/osparc/info/StudyLarge.js @@ -320,10 +320,7 @@ qx.Class.define("osparc.info.StudyLarge", { }, __patchStudy: function(fieldKey, value) { - this.getStudy().patchStudy([{ - fieldKey, - value - }]) + this.getStudy().patchStudy({[fieldKey]: value}) .then(studyData => { studyData["resourceType"] = this.__isTemplate ? "template" : "study"; this.fireDataEvent("updateStudy", studyData); diff --git a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js index e0e25c13837..24673031540 100644 --- a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js +++ b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js @@ -197,10 +197,7 @@ qx.Class.define("osparc.info.StudyUtils", { const newVal = e.getData(); const devObjCopy = osparc.utils.Utils.deepCloneObject(devObj); devObjCopy["disableServiceAutoStart"] = !newVal; - study.patchStudy([{ - fieldKey: "dev", - value: devObjCopy - }]); + study.patchStudy({"dev": devObjCopy}); }); return cb; }, From f14f5d06380f5aae98f4071cc86f6ba23c68e99c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:43:22 +0200 Subject: [PATCH 11/48] fix patch resolve --- .../client/source/class/osparc/data/model/Study.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index b3ce0417da4..2e2d04942b6 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -606,20 +606,16 @@ qx.Class.define("osparc.data.model.Study", { }; osparc.data.Resources.fetch("studies", "patch", params) .then(() => { - studyChanges.forEach(studyChange => { - const { - fieldKey, - value - } = studyChange; + Object.keys(studyChanges).forEach(fieldKey => { const upKey = qx.lang.String.firstUp(fieldKey); const setter = "set" + upKey; - this[setter](value); - }); + this[setter](studyChanges[fieldKey]); + }) // A bit hacky, but it's not sent back to the backend this.set({ lastChangeDate: new Date() }); - const studyData = this.serializeStudyData(); + const studyData = this.serialize(); resolve(studyData); }) .catch(err => reject(err)); From 95779eb7cfe888918a50d5378aaa1bb3cc5fda09 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:43:46 +0200 Subject: [PATCH 12/48] do not call update anymore --- .../client/source/class/osparc/desktop/StudyEditor.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 234c2abf01a..11ade4a8f61 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -732,7 +732,6 @@ qx.Class.define("osparc.desktop.StudyEditor", { delta[key] = data[1]; } }); - console.log("delta", delta); return delta; } return []; @@ -763,10 +762,10 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy++; const studyChanges = this.__getStudyChanges(); - const newObj = this.getStudy().serialize(); - return this.getStudy().updateStudy(newObj) - .then(() => { - this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(newObj); + console.log("studyChanges", studyChanges); + return this.getStudy().patchStudy(studyChanges) + .then(studyData => { + this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); }) .catch(error => { if ("status" in error && error.status === 409) { From 3f4ec098c64b9ebbed48afc859adec95e9e8348c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:46:53 +0200 Subject: [PATCH 13/48] __studyDataToModel --- .../source/class/osparc/data/model/Study.js | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 2e2d04942b6..4d91bf81602 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -42,29 +42,7 @@ qx.Class.define("osparc.data.model.Study", { construct: function(studyData) { this.base(arguments); - this.set({ - uuid: studyData.uuid || this.getUuid(), - name: studyData.name || this.getName(), - description: studyData.description || this.getDescription(), - thumbnail: studyData.thumbnail || this.getThumbnail(), - prjOwner: studyData.prjOwner || this.getPrjOwner(), - accessRights: studyData.accessRights || this.getAccessRights(), - creationDate: studyData.creationDate ? new Date(studyData.creationDate) : this.getCreationDate(), - lastChangeDate: studyData.lastChangeDate ? new Date(studyData.lastChangeDate) : this.getLastChangeDate(), - classifiers: studyData.classifiers || this.getClassifiers(), - tags: studyData.tags || this.getTags(), - state: studyData.state || this.getState(), - quality: studyData.quality || this.getQuality(), - permalink: studyData.permalink || this.getPermalink(), - dev: studyData.dev || this.getDev() - }); - - const wbData = studyData.workbench || this.getWorkbench(); - const workbench = new osparc.data.model.Workbench(wbData, studyData.ui); - this.setWorkbench(workbench); - workbench.setStudy(this); - - this.setUi(new osparc.data.model.StudyUI(studyData.ui)); + this.__studyDataToModel(studyData); this.__buildWorkbench(); }, @@ -316,6 +294,35 @@ qx.Class.define("osparc.data.model.Study", { }, members: { + /** + * @param studyData {Object} Object containing the (total or partial) serialized Study Data + */ + __studyDataToModel: function(studyData) { + this.set({ + uuid: studyData.uuid || this.getUuid(), + name: studyData.name || this.getName(), + description: studyData.description || this.getDescription(), + thumbnail: studyData.thumbnail || this.getThumbnail(), + prjOwner: studyData.prjOwner || this.getPrjOwner(), + accessRights: studyData.accessRights || this.getAccessRights(), + creationDate: studyData.creationDate ? new Date(studyData.creationDate) : this.getCreationDate(), + lastChangeDate: studyData.lastChangeDate ? new Date(studyData.lastChangeDate) : this.getLastChangeDate(), + classifiers: studyData.classifiers || this.getClassifiers(), + tags: studyData.tags || this.getTags(), + state: studyData.state || this.getState(), + quality: studyData.quality || this.getQuality(), + permalink: studyData.permalink || this.getPermalink(), + dev: studyData.dev || this.getDev() + }); + + const wbData = studyData.workbench || this.getWorkbench(); + const workbench = new osparc.data.model.Workbench(wbData, studyData.ui); + this.setWorkbench(workbench); + workbench.setStudy(this); + + this.setUi(new osparc.data.model.StudyUI(studyData.ui)); + }, + __buildWorkbench: function() { this.getWorkbench().buildWorkbench(); }, From 2c1d1a5588487e9405a0f44ca44d0f1897bbc328 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:47:39 +0200 Subject: [PATCH 14/48] minor --- .../source/class/osparc/data/model/Study.js | 66 +++++++------------ 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 4d91bf81602..5f2b05aba81 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -323,6 +323,30 @@ qx.Class.define("osparc.data.model.Study", { this.setUi(new osparc.data.model.StudyUI(studyData.ui)); }, + serialize: function(clean = true) { + let jsonObject = {}; + const propertyKeys = this.self().getProperties(); + propertyKeys.forEach(key => { + if (this.self().IgnoreSerializationProps.includes(key)) { + return; + } + if (key === "workbench") { + jsonObject[key] = this.getWorkbench().serialize(clean); + return; + } + if (key === "ui") { + jsonObject[key] = this.getUi().serialize(); + return; + } + const value = this.get(key); + if (value !== null) { + // only put the value in the payload if there is a value + jsonObject[key] = value; + } + }); + return jsonObject; + }, + __buildWorkbench: function() { this.getWorkbench().buildWorkbench(); }, @@ -560,48 +584,6 @@ qx.Class.define("osparc.data.model.Study", { return !this.getUi().getSlideshow().isEmpty(); }, - serializeStudyData: function() { - let studyData = {}; - const propertyKeys = this.self().getProperties(); - propertyKeys.forEach(key => { - if (key === "workbench") { - studyData[key] = this.getWorkbench().serialize(); - return; - } - if (key === "ui") { - studyData[key] = this.getUi().serialize(); - return; - } - const value = this.get(key); - studyData[key] = value; - }); - return studyData; - }, - - serialize: function(clean = true) { - let jsonObject = {}; - const propertyKeys = this.self().getProperties(); - propertyKeys.forEach(key => { - if (this.self().IgnoreSerializationProps.includes(key)) { - return; - } - if (key === "workbench") { - jsonObject[key] = this.getWorkbench().serialize(clean); - return; - } - if (key === "ui") { - jsonObject[key] = this.getUi().serialize(); - return; - } - const value = this.get(key); - if (value !== null) { - // only put the value in the payload if there is a value - jsonObject[key] = value; - } - }); - return jsonObject; - }, - patchStudy: function(studyChanges) { return new Promise((resolve, reject) => { const patchData = studyChanges; From e5b48ec4f67202131a0dbc24c59c667abdc76f0d Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 13:58:41 +0200 Subject: [PATCH 15/48] more refactoring --- .../source/class/osparc/data/model/Study.js | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 5f2b05aba81..0653c8d66b9 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -44,6 +44,8 @@ qx.Class.define("osparc.data.model.Study", { this.__studyDataToModel(studyData); + this.getWorkbench().setStudy(this); + this.__buildWorkbench(); }, @@ -298,29 +300,42 @@ qx.Class.define("osparc.data.model.Study", { * @param studyData {Object} Object containing the (total or partial) serialized Study Data */ __studyDataToModel: function(studyData) { - this.set({ - uuid: studyData.uuid || this.getUuid(), - name: studyData.name || this.getName(), - description: studyData.description || this.getDescription(), - thumbnail: studyData.thumbnail || this.getThumbnail(), - prjOwner: studyData.prjOwner || this.getPrjOwner(), - accessRights: studyData.accessRights || this.getAccessRights(), - creationDate: studyData.creationDate ? new Date(studyData.creationDate) : this.getCreationDate(), - lastChangeDate: studyData.lastChangeDate ? new Date(studyData.lastChangeDate) : this.getLastChangeDate(), - classifiers: studyData.classifiers || this.getClassifiers(), - tags: studyData.tags || this.getTags(), - state: studyData.state || this.getState(), - quality: studyData.quality || this.getQuality(), - permalink: studyData.permalink || this.getPermalink(), - dev: studyData.dev || this.getDev() + [ + "uuid", + "name", + "description", + "thumbnail", + "accessRights", + "classifiers", + "tags", + "state", + "quality", + "permalink", + "dev" + ].forEach(sameKey => { + if (sameKey in studyData) { + this.set({ + [sameKey]: studyData[sameKey], + }); + } }); - const wbData = studyData.workbench || this.getWorkbench(); - const workbench = new osparc.data.model.Workbench(wbData, studyData.ui); + if ("creationDate" in studyData) { + this.set({ + "creationDate": new Date(studyData.creationDate) + }); + } + if ("lastChangeDate" in studyData) { + this.set({ + "lastChangeDate": new Date(studyData.lastChangeDate) + }); + } + + const workbench = new osparc.data.model.Workbench(studyData.workbench, studyData.ui); this.setWorkbench(workbench); - workbench.setStudy(this); - this.setUi(new osparc.data.model.StudyUI(studyData.ui)); + const workbenchUi = new osparc.data.model.StudyUI(studyData.ui); + this.setUi(workbenchUi); }, serialize: function(clean = true) { From fe692385579644b646f6c72bfb5399b2cf14c9e5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 14:43:19 +0200 Subject: [PATCH 16/48] patchWorkbench --- .../source/class/osparc/data/model/Study.js | 12 +++++- .../class/osparc/data/model/Workbench.js | 38 +++++++++++-------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 0653c8d66b9..27811e5da18 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -601,12 +601,20 @@ qx.Class.define("osparc.data.model.Study", { patchStudy: function(studyChanges) { return new Promise((resolve, reject) => { - const patchData = studyChanges; + const promises = []; + let workbenchChanges = {}; + if ("workbench" in studyChanges) { + workbenchChanges = studyChanges["workbench"]; + promises.push(this.getWorkbench().patchWorkbench(workbenchChanges)); + delete studyChanges["workbench"]; + } + console.log("studyChanges", studyChanges); + console.log("workbenchChanges", workbenchChanges); const params = { url: { "studyId": this.getUuid() }, - data: patchData + data: studyChanges }; osparc.data.Resources.fetch("studies", "patch", params) .then(() => { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 01da1153297..f47266f2e65 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -694,21 +694,6 @@ qx.Class.define("osparc.data.model.Workbench", { } }, - __getAveragePosition: function(nodes) { - let avgX = 0; - let avgY = 0; - nodes.forEach(node => { - avgX += node.getPosition().x; - avgY += node.getPosition().y; - }); - avgX /= nodes.length; - avgY /= nodes.length; - return { - x: avgX, - y: avgY - }; - }, - serialize: function(clean = true) { if (this.__workbenchInitData !== null) { // workbench is not initialized @@ -745,6 +730,29 @@ qx.Class.define("osparc.data.model.Workbench", { } } return workbenchUI; + }, + + patchWorkbench: function(workbenchChanges) { + return new Promise((resolve, reject) => { + console.log("workbenchChanges", workbenchChanges); + const promises = []; + Object.keys(workbenchChanges).forEach(nodeId => { + const params = { + url: { + "studyId": this.getStudy().getUuid(), + "nodeId": nodeId + }, + data: workbenchChanges + }; + promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); + }) + Promise.all(promises) + .then(() => { + const workbenchData = this.serialize(); + resolve(workbenchData); + }) + .catch(err => reject(err)); + }); } } }); From 71f92aadafc302240147da3f051ad5704c376ba5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 15:45:45 +0200 Subject: [PATCH 17/48] refactor --- .../class/osparc/data/model/Workbench.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index f47266f2e65..7783f73d543 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -636,7 +636,8 @@ qx.Class.define("osparc.data.model.Workbench", { } // Then populate them (this will avoid issues of connecting nodes that might not be created yet) - this.__populateNodesData(workbenchData, workbenchUIData); + this.__populateNodesData(workbenchData); + this.__populateNodesUIData(workbenchUIData); nodeIds.forEach(nodeId => { const node = this.getNode(nodeId); @@ -657,18 +658,25 @@ qx.Class.define("osparc.data.model.Workbench", { } }, - __populateNodesData: function(workbenchData, workbenchUIData) { + __populateNodesData: function(workbenchData) { Object.entries(workbenchData).forEach(([nodeId, nodeData]) => { this.getNode(nodeId).populateNodeData(nodeData); + if ("position" in nodeData) { + // old way for storing the position this.getNode(nodeId).populateNodeUIData(nodeData); } - if (workbenchUIData && "workbench" in workbenchUIData && nodeId in workbenchUIData.workbench) { - this.getNode(nodeId).populateNodeUIData(workbenchUIData.workbench[nodeId]); - } }); }, + __populateNodesUIData: function(workbenchUIData) { + if ("workbench" in workbenchUIData) { + Object.keys(workbenchUIData["workbench"]).forEach(nodeId => { + this.getNode(nodeId).populateNodeUIData(workbenchUIData.workbench[nodeId]); + }); + } + }, + __deserializeEdges: function(workbenchData) { for (const nodeId in workbenchData) { const nodeData = workbenchData[nodeId]; From fdc07ab14d83b0af2d656548bde2c3ced0f0b238 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 16:02:52 +0200 Subject: [PATCH 18/48] minor --- .../client/source/class/osparc/data/model/Workbench.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 7783f73d543..e8035f1ae28 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -637,7 +637,7 @@ qx.Class.define("osparc.data.model.Workbench", { // Then populate them (this will avoid issues of connecting nodes that might not be created yet) this.__populateNodesData(workbenchData); - this.__populateNodesUIData(workbenchUIData); + this.populateNodesUIData(workbenchUIData); nodeIds.forEach(nodeId => { const node = this.getNode(nodeId); @@ -669,7 +669,7 @@ qx.Class.define("osparc.data.model.Workbench", { }); }, - __populateNodesUIData: function(workbenchUIData) { + populateNodesUIData: function(workbenchUIData) { if ("workbench" in workbenchUIData) { Object.keys(workbenchUIData["workbench"]).forEach(nodeId => { this.getNode(nodeId).populateNodeUIData(workbenchUIData.workbench[nodeId]); From be45b463617b3a2106387b2f72cf56af77c1ad71 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 16:22:24 +0200 Subject: [PATCH 19/48] more promises --- .../source/class/osparc/data/model/Study.js | 18 ++++++++++-------- .../class/osparc/data/model/Workbench.js | 7 ++----- .../source/class/osparc/desktop/StudyEditor.js | 1 - 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 27811e5da18..770c9c893bf 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -609,14 +609,16 @@ qx.Class.define("osparc.data.model.Study", { delete studyChanges["workbench"]; } console.log("studyChanges", studyChanges); - console.log("workbenchChanges", workbenchChanges); - const params = { - url: { - "studyId": this.getUuid() - }, - data: studyChanges - }; - osparc.data.Resources.fetch("studies", "patch", params) + if (Object.keys(studyChanges).length) { + const params = { + url: { + "studyId": this.getUuid() + }, + data: studyChanges + }; + promises.push(osparc.data.Resources.fetch("studies", "patch", params)) + } + Promise.all() .then(() => { Object.keys(studyChanges).forEach(fieldKey => { const upKey = qx.lang.String.firstUp(fieldKey); diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index e8035f1ae28..3a1526a2aa3 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -750,15 +750,12 @@ qx.Class.define("osparc.data.model.Workbench", { "studyId": this.getStudy().getUuid(), "nodeId": nodeId }, - data: workbenchChanges + data: workbenchChanges[nodeId] }; promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); }) Promise.all(promises) - .then(() => { - const workbenchData = this.serialize(); - resolve(workbenchData); - }) + .then(() => resolve()) .catch(err => reject(err)); }); } diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 11ade4a8f61..1d99827c545 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -762,7 +762,6 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy++; const studyChanges = this.__getStudyChanges(); - console.log("studyChanges", studyChanges); return this.getStudy().patchStudy(studyChanges) .then(studyData => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); From ef81b48ea4a75b7c9c57a02274f6d053d016822e Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 16:52:49 +0200 Subject: [PATCH 20/48] deltaToPatchObj --- .../client/source/class/osparc/data/model/Study.js | 2 +- .../source/class/osparc/desktop/StudyEditor.js | 12 +++--------- .../source/class/osparc/wrapper/JsonDiffPatch.js | 14 +++++++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 770c9c893bf..e286649182b 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -618,7 +618,7 @@ qx.Class.define("osparc.data.model.Study", { }; promises.push(osparc.data.Resources.fetch("studies", "patch", params)) } - Promise.all() + Promise.all(promises) .then(() => { Object.keys(studyChanges).forEach(fieldKey => { const upKey = qx.lang.String.firstUp(fieldKey); diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 1d99827c545..ab079493957 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -720,21 +720,15 @@ qx.Class.define("osparc.desktop.StudyEditor", { __getStudyChanges: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); - const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); + let delta = diffPatcher.diff(this.__studyDataInBackend, newObj); if (delta) { // lastChangeDate and creationDate should not be taken into account as data change delete delta["creationDate"]; delete delta["lastChangeDate"]; - Object.entries(delta).forEach(([key, data]) => { - // keep only the new value - // JsonDiffPatch returns {key: [old_value, ney_value]} - if (data.length > 1) { - delta[key] = data[1]; - } - }); + delta = osparc.wrapper.JsonDiffPatch.deltaToPatchObj(delta); return delta; } - return []; + return {}; }, didStudyChange: function() { diff --git a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js index 92e998ccb3f..bb40b3d07fc 100644 --- a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js +++ b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js @@ -34,7 +34,19 @@ qx.Class.define("osparc.wrapper.JsonDiffPatch", { statics: { NAME: "jsondiffpatch", VERSION: "0.3.11", - URL: "https://github.com/benjamine/jsondiffpatch" + URL: "https://github.com/benjamine/jsondiffpatch", + + deltaToPatchObj: function(delta) { + // keep only the new value + // JsonDiffPatch returns {key: key2: key3: [old_value, ney_value]} + // And we want {key: key2: key3: ney_value} + Object.entries(delta).forEach(([key, data]) => { + if (data.length > 1) { + delta[key] = data[1]; + } + }); + return delta; + } }, construct: function() { From 8ada7451b523cdff4c1256e8ff4995de03caa069 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 16:55:43 +0200 Subject: [PATCH 21/48] comments --- .../class/osparc/wrapper/JsonDiffPatch.js | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js index bb40b3d07fc..95b4a768183 100644 --- a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js +++ b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js @@ -38,8 +38,35 @@ qx.Class.define("osparc.wrapper.JsonDiffPatch", { deltaToPatchObj: function(delta) { // keep only the new value - // JsonDiffPatch returns {key: key2: key3: [old_value, ney_value]} - // And we want {key: key2: key3: ney_value} + /** + * JsonDiffPatch returns something like + * { + * key1: { + * key2: { + * key3: [old_value, new_value] + * } + * }, + * key4: { + * key5: { + * key6: [old_value, new_value] + * } + * } + * } + * + * While we want {key: key2: key3: ney_value} + * { + * key1: { + * key2: { + * key3: new_value + * } + * }, + * key4: { + * key5: { + * key6: new_value + * } + * } + * } + */ Object.entries(delta).forEach(([key, data]) => { if (data.length > 1) { delta[key] = data[1]; From 75cf9de3da004348c4d4b0c04cb1f8745eb095cc Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 17:22:06 +0200 Subject: [PATCH 22/48] patchStudy2 --- .../source/class/osparc/data/model/Study.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index e286649182b..3197cd8241d 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -600,6 +600,32 @@ qx.Class.define("osparc.data.model.Study", { }, patchStudy: function(studyChanges) { + return new Promise((resolve, reject) => { + const params = { + url: { + "studyId": this.getUuid() + }, + data: studyChanges + }; + osparc.data.Resources.fetch("studies", "patch", params) + .then(() => { + Object.keys(studyChanges).forEach(fieldKey => { + const upKey = qx.lang.String.firstUp(fieldKey); + const setter = "set" + upKey; + this[setter](studyChanges[fieldKey]); + }) + // A bit hacky, but it's not sent back to the backend + this.set({ + lastChangeDate: new Date() + }); + const studyData = this.serialize(); + resolve(studyData); + }) + .catch(err => reject(err)); + }); + }, + + patchStudy2: function(studyChanges) { return new Promise((resolve, reject) => { const promises = []; let workbenchChanges = {}; From efaef363a39aaf6891b61eba76b64826ecbfaeca Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 5 Jun 2024 17:24:22 +0200 Subject: [PATCH 23/48] minor --- .../client/source/class/osparc/data/model/Study.js | 2 +- .../client/source/class/osparc/desktop/StudyEditor.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 3197cd8241d..6ed8b6bd61f 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -625,7 +625,7 @@ qx.Class.define("osparc.data.model.Study", { }); }, - patchStudy2: function(studyChanges) { + patchStudyDelayed: function(studyChanges) { return new Promise((resolve, reject) => { const promises = []; let workbenchChanges = {}; diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index ab079493957..c475e2747db 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -756,7 +756,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy++; const studyChanges = this.__getStudyChanges(); - return this.getStudy().patchStudy(studyChanges) + return this.getStudy().patchStudyDelayed(studyChanges) .then(studyData => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); }) From 23be5fcc6258943c731955b3a59133dde591fb91 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 6 Jun 2024 10:49:52 +0200 Subject: [PATCH 24/48] delayed patches --- .../source/class/osparc/data/model/Study.js | 26 ++++++++++++------- .../class/osparc/data/model/Workbench.js | 7 +++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 6ed8b6bd61f..cf2320232fe 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -625,32 +625,40 @@ qx.Class.define("osparc.data.model.Study", { }); }, + /** + * Call patch Study, but the changes were already applied on the frontend + */ patchStudyDelayed: function(studyChanges) { return new Promise((resolve, reject) => { const promises = []; let workbenchChanges = {}; if ("workbench" in studyChanges) { workbenchChanges = studyChanges["workbench"]; - promises.push(this.getWorkbench().patchWorkbench(workbenchChanges)); + promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchChanges)); delete studyChanges["workbench"]; } console.log("studyChanges", studyChanges); - if (Object.keys(studyChanges).length) { + const fieldKeys = Object.keys(studyChanges); + if (fieldKeys.length) { const params = { url: { "studyId": this.getUuid() }, - data: studyChanges + data: {} }; - promises.push(osparc.data.Resources.fetch("studies", "patch", params)) + fieldKeys.forEach(fieldKey => { + if (fieldKey === "ui") { + params["data"][fieldKey] = this.getUi.serialize(); + } else { + const upKey = qx.lang.String.firstUp(fieldKey); + const getter = "get" + upKey; + params["data"][fieldKey] = this[getter](studyChanges[fieldKey]); + } + promises.push(osparc.data.Resources.fetch("studies", "patch", params)) + }); } Promise.all(promises) .then(() => { - Object.keys(studyChanges).forEach(fieldKey => { - const upKey = qx.lang.String.firstUp(fieldKey); - const setter = "set" + upKey; - this[setter](studyChanges[fieldKey]); - }) // A bit hacky, but it's not sent back to the backend this.set({ lastChangeDate: new Date() diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 3a1526a2aa3..a9c2401b83c 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -740,7 +740,10 @@ qx.Class.define("osparc.data.model.Workbench", { return workbenchUI; }, - patchWorkbench: function(workbenchChanges) { + /** + * Call patch Node, but the changes were already applied on the frontend + */ + patchWorkbenchDelayed: function(workbenchChanges) { return new Promise((resolve, reject) => { console.log("workbenchChanges", workbenchChanges); const promises = []; @@ -750,7 +753,7 @@ qx.Class.define("osparc.data.model.Workbench", { "studyId": this.getStudy().getUuid(), "nodeId": nodeId }, - data: workbenchChanges[nodeId] + data: this.getNode(nodeId).serialize() }; promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); }) From 7a9b0b72cdb92c0e47c016575ac5cd5a87a3e525 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 6 Jun 2024 10:53:08 +0200 Subject: [PATCH 25/48] diffs, not changes --- .../source/class/osparc/data/model/Study.js | 19 ++++++++++--------- .../class/osparc/data/model/Workbench.js | 7 ++++--- .../class/osparc/desktop/StudyEditor.js | 10 +++++----- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index cf2320232fe..d1c5c0d4359 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -627,18 +627,19 @@ qx.Class.define("osparc.data.model.Study", { /** * Call patch Study, but the changes were already applied on the frontend + * @param studyDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes. */ - patchStudyDelayed: function(studyChanges) { + patchStudyDelayed: function(studyDiffs) { return new Promise((resolve, reject) => { const promises = []; - let workbenchChanges = {}; - if ("workbench" in studyChanges) { - workbenchChanges = studyChanges["workbench"]; - promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchChanges)); - delete studyChanges["workbench"]; + let workbenchDiffs = {}; + if ("workbench" in studyDiffs) { + workbenchDiffs = studyDiffs["workbench"]; + promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchDiffs)); + delete studyDiffs["workbench"]; } - console.log("studyChanges", studyChanges); - const fieldKeys = Object.keys(studyChanges); + console.log("studyChanges", studyDiffs); + const fieldKeys = Object.keys(studyDiffs); if (fieldKeys.length) { const params = { url: { @@ -652,7 +653,7 @@ qx.Class.define("osparc.data.model.Study", { } else { const upKey = qx.lang.String.firstUp(fieldKey); const getter = "get" + upKey; - params["data"][fieldKey] = this[getter](studyChanges[fieldKey]); + params["data"][fieldKey] = this[getter](studyDiffs[fieldKey]); } promises.push(osparc.data.Resources.fetch("studies", "patch", params)) }); diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index a9c2401b83c..92599a617e7 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -742,12 +742,13 @@ qx.Class.define("osparc.data.model.Workbench", { /** * Call patch Node, but the changes were already applied on the frontend + * @param workbenchDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes. */ - patchWorkbenchDelayed: function(workbenchChanges) { + patchWorkbenchDelayed: function(workbenchDiffs) { return new Promise((resolve, reject) => { - console.log("workbenchChanges", workbenchChanges); + console.log("workbenchChanges", workbenchDiffs); const promises = []; - Object.keys(workbenchChanges).forEach(nodeId => { + Object.keys(workbenchDiffs).forEach(nodeId => { const params = { url: { "studyId": this.getStudy().getUuid(), diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index c475e2747db..7abb7b81fd3 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -717,7 +717,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__stopAutoSaveTimer(); }, - __getStudyChanges: function() { + __getStudyDiffs: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); let delta = diffPatcher.diff(this.__studyDataInBackend, newObj); @@ -732,8 +732,8 @@ qx.Class.define("osparc.desktop.StudyEditor", { }, didStudyChange: function() { - const studyChanges = this.__getStudyChanges(); - return Boolean(Object.keys(studyChanges).length); + const studyDiffs = this.__getStudyDiffs(); + return Boolean(Object.keys(studyDiffs).length); }, __checkStudyChanges: function() { @@ -755,8 +755,8 @@ qx.Class.define("osparc.desktop.StudyEditor", { } this.__updatingStudy++; - const studyChanges = this.__getStudyChanges(); - return this.getStudy().patchStudyDelayed(studyChanges) + const studyDiffs = this.__getStudyDiffs(); + return this.getStudy().patchStudyDelayed(studyDiffs) .then(studyData => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); }) From 3b598c715f1634b743615f7241ad3c0699c3c03a Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 6 Jun 2024 14:23:20 +0200 Subject: [PATCH 26/48] minor --- .../client/source/class/osparc/data/model/Study.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index d1c5c0d4359..b4c8caf7c0e 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -649,7 +649,7 @@ qx.Class.define("osparc.data.model.Study", { }; fieldKeys.forEach(fieldKey => { if (fieldKey === "ui") { - params["data"][fieldKey] = this.getUi.serialize(); + params["data"][fieldKey] = this.getUi().serialize(); } else { const upKey = qx.lang.String.firstUp(fieldKey); const getter = "get" + upKey; From f6b705607cedf52bd5f60b8cb5886e82f57998a8 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 6 Jun 2024 14:32:44 +0200 Subject: [PATCH 27/48] patch only what changed --- .../client/source/class/osparc/data/model/Workbench.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 92599a617e7..6c0707a49ea 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -749,12 +749,19 @@ qx.Class.define("osparc.data.model.Workbench", { console.log("workbenchChanges", workbenchDiffs); const promises = []; Object.keys(workbenchDiffs).forEach(nodeId => { + // serialize the whole node + const nodeData = this.getNode(nodeId).serialize(); + // patch only what changed + const patchData = {}; + Object.keys(workbenchDiffs[nodeId]).forEach(fieldKey => { + patchData[fieldKey] = nodeData[fieldKey]; + }); const params = { url: { "studyId": this.getStudy().getUuid(), "nodeId": nodeId }, - data: this.getNode(nodeId).serialize() + data: patchData }; promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); }) From 7e79f3367093704a860e2bdae4a7d893fa30e1e1 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 6 Jun 2024 14:37:51 +0200 Subject: [PATCH 28/48] cleanup --- .../source/class/osparc/data/model/Study.js | 70 +++++++------------ .../class/osparc/data/model/Workbench.js | 1 - .../class/osparc/desktop/StudyEditor.js | 3 +- .../class/osparc/wrapper/JsonDiffPatch.js | 41 +---------- 4 files changed, 26 insertions(+), 89 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index b4c8caf7c0e..64f315df3e1 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -42,9 +42,30 @@ qx.Class.define("osparc.data.model.Study", { construct: function(studyData) { this.base(arguments); - this.__studyDataToModel(studyData); - - this.getWorkbench().setStudy(this); + this.set({ + uuid: studyData.uuid || this.getUuid(), + name: studyData.name || this.getName(), + description: studyData.description || this.getDescription(), + thumbnail: studyData.thumbnail || this.getThumbnail(), + prjOwner: studyData.prjOwner || this.getPrjOwner(), + accessRights: studyData.accessRights || this.getAccessRights(), + creationDate: studyData.creationDate ? new Date(studyData.creationDate) : this.getCreationDate(), + lastChangeDate: studyData.lastChangeDate ? new Date(studyData.lastChangeDate) : this.getLastChangeDate(), + classifiers: studyData.classifiers || this.getClassifiers(), + tags: studyData.tags || this.getTags(), + state: studyData.state || this.getState(), + quality: studyData.quality || this.getQuality(), + permalink: studyData.permalink || this.getPermalink(), + dev: studyData.dev || this.getDev() + }); + + const wbData = studyData.workbench || this.getWorkbench(); + const workbench = new osparc.data.model.Workbench(wbData, studyData.ui); + this.setWorkbench(workbench); + workbench.setStudy(this); + + const workbenchUi = new osparc.data.model.StudyUI(studyData.ui); + this.setUi(workbenchUi); this.__buildWorkbench(); }, @@ -296,48 +317,6 @@ qx.Class.define("osparc.data.model.Study", { }, members: { - /** - * @param studyData {Object} Object containing the (total or partial) serialized Study Data - */ - __studyDataToModel: function(studyData) { - [ - "uuid", - "name", - "description", - "thumbnail", - "accessRights", - "classifiers", - "tags", - "state", - "quality", - "permalink", - "dev" - ].forEach(sameKey => { - if (sameKey in studyData) { - this.set({ - [sameKey]: studyData[sameKey], - }); - } - }); - - if ("creationDate" in studyData) { - this.set({ - "creationDate": new Date(studyData.creationDate) - }); - } - if ("lastChangeDate" in studyData) { - this.set({ - "lastChangeDate": new Date(studyData.lastChangeDate) - }); - } - - const workbench = new osparc.data.model.Workbench(studyData.workbench, studyData.ui); - this.setWorkbench(workbench); - - const workbenchUi = new osparc.data.model.StudyUI(studyData.ui); - this.setUi(workbenchUi); - }, - serialize: function(clean = true) { let jsonObject = {}; const propertyKeys = this.self().getProperties(); @@ -638,7 +617,6 @@ qx.Class.define("osparc.data.model.Study", { promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchDiffs)); delete studyDiffs["workbench"]; } - console.log("studyChanges", studyDiffs); const fieldKeys = Object.keys(studyDiffs); if (fieldKeys.length) { const params = { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 6c0707a49ea..382d70ec55b 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -746,7 +746,6 @@ qx.Class.define("osparc.data.model.Workbench", { */ patchWorkbenchDelayed: function(workbenchDiffs) { return new Promise((resolve, reject) => { - console.log("workbenchChanges", workbenchDiffs); const promises = []; Object.keys(workbenchDiffs).forEach(nodeId => { // serialize the whole node diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 7abb7b81fd3..bce364bfb42 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -720,12 +720,11 @@ qx.Class.define("osparc.desktop.StudyEditor", { __getStudyDiffs: function() { const newObj = this.getStudy().serialize(); const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance(); - let delta = diffPatcher.diff(this.__studyDataInBackend, newObj); + const delta = diffPatcher.diff(this.__studyDataInBackend, newObj); if (delta) { // lastChangeDate and creationDate should not be taken into account as data change delete delta["creationDate"]; delete delta["lastChangeDate"]; - delta = osparc.wrapper.JsonDiffPatch.deltaToPatchObj(delta); return delta; } return {}; diff --git a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js index 95b4a768183..92e998ccb3f 100644 --- a/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js +++ b/services/static-webserver/client/source/class/osparc/wrapper/JsonDiffPatch.js @@ -34,46 +34,7 @@ qx.Class.define("osparc.wrapper.JsonDiffPatch", { statics: { NAME: "jsondiffpatch", VERSION: "0.3.11", - URL: "https://github.com/benjamine/jsondiffpatch", - - deltaToPatchObj: function(delta) { - // keep only the new value - /** - * JsonDiffPatch returns something like - * { - * key1: { - * key2: { - * key3: [old_value, new_value] - * } - * }, - * key4: { - * key5: { - * key6: [old_value, new_value] - * } - * } - * } - * - * While we want {key: key2: key3: ney_value} - * { - * key1: { - * key2: { - * key3: new_value - * } - * }, - * key4: { - * key5: { - * key6: new_value - * } - * } - * } - */ - Object.entries(delta).forEach(([key, data]) => { - if (data.length > 1) { - delta[key] = data[1]; - } - }); - return delta; - } + URL: "https://github.com/benjamine/jsondiffpatch" }, construct: function() { From ac0425286a8bd8cde32d6e827140a2c8ebd570fe Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 13:33:44 +0200 Subject: [PATCH 29/48] patch only in master isDevelopmentPlatform --- .../client/source/class/osparc/desktop/StudyEditor.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index bce364bfb42..0431eb9c11f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -754,8 +754,15 @@ qx.Class.define("osparc.desktop.StudyEditor", { } this.__updatingStudy++; - const studyDiffs = this.__getStudyDiffs(); - return this.getStudy().patchStudyDelayed(studyDiffs) + let updatePromise = null; + if (osparc.utils.Utils.isDevelopmentPlatform()) { + const studyDiffs = this.__getStudyDiffs(); + updatePromise = this.getStudy().patchStudyDelayed(studyDiffs) + } else { + const newObj = this.getStudy().serialize(); + updatePromise = this.getStudy().updateStudy(newObj); + } + updatePromise .then(studyData => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); }) From 3210ed353410fbaca91f7c2db48dafa64cb58520 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 13:42:32 +0200 Subject: [PATCH 30/48] minor --- .../client/source/class/osparc/desktop/StudyEditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 0431eb9c11f..a1942ebbe6c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -762,7 +762,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { const newObj = this.getStudy().serialize(); updatePromise = this.getStudy().updateStudy(newObj); } - updatePromise + return updatePromise .then(studyData => { this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); }) From ed075cb86ac88d588e60d062c7aeb5155bac6693 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 14:14:36 +0200 Subject: [PATCH 31/48] minor fix --- .../client/source/class/osparc/share/Collaborators.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index c0ed320a402..5db53dd414d 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -148,12 +148,12 @@ qx.Class.define("osparc.share.Collaborators", { return vBox; }, - getEveryoneObj: function() { + getEveryoneObj: function(thumbnailSize=32) { return { "gid": 1, "label": qx.locale.Manager.tr("Public"), "description": "", - "thumbnail": null, + "thumbnail": "@FontAwesome5Solid/globe/"+thumbnailSize, "collabType": 0 } } @@ -380,6 +380,9 @@ qx.Class.define("osparc.share.Collaborators", { `${"last_name" in collaborator && collaborator["last_name"] ? collaborator["last_name"] : ""}` ); + } else if (gid === this.self().getEveryoneObj()["gid"]) { + collaborator["name"] = collaborator["label"].toLocaleString(); + delete collaborator["label"]; } collaborator["accessRights"] = accessRights[gid]; collaborator["showOptions"] = (this._resourceType === "service") ? this._canIWrite() : this._canIDelete(); From 1283c7202be5223879baaec681e899c2e35b9c8c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 14:17:28 +0200 Subject: [PATCH 32/48] minor --- .../client/source/class/osparc/utils/Utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/utils/Utils.js b/services/static-webserver/client/source/class/osparc/utils/Utils.js index c791cec625b..f44ddbb7c1b 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Utils.js +++ b/services/static-webserver/client/source/class/osparc/utils/Utils.js @@ -572,7 +572,7 @@ qx.Class.define("osparc.utils.Utils", { return L > 0.35 ? "#FFF" : "#000"; }, - bytesToSize: function(bytes, decimals = 2, isDecimalColapsed = true) { + bytesToSize: function(bytes, decimals = 2, isDecimalCollapsed = true) { if (!+bytes) { return "0 Bytes"; } @@ -581,7 +581,7 @@ qx.Class.define("osparc.utils.Utils", { const dm = decimals < 0 ? 0 : decimals; const i = Math.floor(Math.log(bytes) / Math.log(k)) - return `${isDecimalColapsed ? parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) : (bytes / Math.pow(k, i)).toFixed(dm)} ${sizes[i]}` + return `${isDecimalCollapsed ? parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) : (bytes / Math.pow(k, i)).toFixed(dm)} ${sizes[i]}` }, bytesToGB: function(bytes) { From 5d8b6696770724a52c48c6c6029825a930ced02d Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 15:03:45 +0200 Subject: [PATCH 33/48] the change was that it was deleted --- .../source/class/osparc/data/model/Workbench.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 382d70ec55b..e5a985e7e23 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -746,13 +746,19 @@ qx.Class.define("osparc.data.model.Workbench", { */ patchWorkbenchDelayed: function(workbenchDiffs) { return new Promise((resolve, reject) => { + const changedNodeIds = Object.keys(workbenchDiffs); const promises = []; - Object.keys(workbenchDiffs).forEach(nodeId => { + changedNodeIds.forEach(nodeId => { + const node = this.getNode(nodeId); + if (node === null) { + // the change was that it was deleted + return; + } // serialize the whole node - const nodeData = this.getNode(nodeId).serialize(); + const nodeData = node.serialize(); // patch only what changed const patchData = {}; - Object.keys(workbenchDiffs[nodeId]).forEach(fieldKey => { + changedNodeIds.forEach(fieldKey => { patchData[fieldKey] = nodeData[fieldKey]; }); const params = { From a1ae1828bd52b2ec92568b473f0d4f9a557432e9 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 15:37:58 +0200 Subject: [PATCH 34/48] if workbenchDiffs is an array means that the node was either added or removed --- .../source/class/osparc/data/model/Study.js | 7 +++--- .../class/osparc/data/model/Workbench.js | 25 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 64f315df3e1..6802da93a3b 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -619,19 +619,20 @@ qx.Class.define("osparc.data.model.Study", { } const fieldKeys = Object.keys(studyDiffs); if (fieldKeys.length) { + const patchData = {}; const params = { url: { "studyId": this.getUuid() }, - data: {} + data: patchData }; fieldKeys.forEach(fieldKey => { if (fieldKey === "ui") { - params["data"][fieldKey] = this.getUi().serialize(); + patchData[fieldKey] = this.getUi().serialize(); } else { const upKey = qx.lang.String.firstUp(fieldKey); const getter = "get" + upKey; - params["data"][fieldKey] = this[getter](studyDiffs[fieldKey]); + patchData[fieldKey] = this[getter](studyDiffs[fieldKey]); } promises.push(osparc.data.Resources.fetch("studies", "patch", params)) }); diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index e5a985e7e23..46f6236259d 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -746,21 +746,28 @@ qx.Class.define("osparc.data.model.Workbench", { */ patchWorkbenchDelayed: function(workbenchDiffs) { return new Promise((resolve, reject) => { - const changedNodeIds = Object.keys(workbenchDiffs); const promises = []; - changedNodeIds.forEach(nodeId => { + Object.keys(workbenchDiffs).forEach(nodeId => { const node = this.getNode(nodeId); if (node === null) { - // the change was that it was deleted + // the node was removed return; } - // serialize the whole node + const nodeData = node.serialize(); - // patch only what changed - const patchData = {}; - changedNodeIds.forEach(fieldKey => { - patchData[fieldKey] = nodeData[fieldKey]; - }); + let patchData = {}; + if (workbenchDiffs[nodeId] instanceof Array) { + // if workbenchDiffs is an array means that the node was either added or removed + // the node was added + patchData = nodeData; + // key can't be patched + delete patchData["key"]; + } else { + // patch only what was changed + Object.keys(workbenchDiffs[nodeId]).forEach(changedFieldKey => { + patchData[changedFieldKey] = nodeData[changedFieldKey]; + }); + } const params = { url: { "studyId": this.getStudy().getUuid(), From eea4731ade674f732eb221b3d4e68cbe1e1983d6 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 16:18:15 +0200 Subject: [PATCH 35/48] @ignapas reviews --- .../source/class/osparc/data/model/Study.js | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 6802da93a3b..c0482818bc5 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -609,45 +609,42 @@ qx.Class.define("osparc.data.model.Study", { * @param studyDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes. */ patchStudyDelayed: function(studyDiffs) { - return new Promise((resolve, reject) => { - const promises = []; - let workbenchDiffs = {}; - if ("workbench" in studyDiffs) { - workbenchDiffs = studyDiffs["workbench"]; - promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchDiffs)); - delete studyDiffs["workbench"]; - } - const fieldKeys = Object.keys(studyDiffs); - if (fieldKeys.length) { - const patchData = {}; - const params = { - url: { - "studyId": this.getUuid() - }, - data: patchData - }; - fieldKeys.forEach(fieldKey => { - if (fieldKey === "ui") { - patchData[fieldKey] = this.getUi().serialize(); - } else { - const upKey = qx.lang.String.firstUp(fieldKey); - const getter = "get" + upKey; - patchData[fieldKey] = this[getter](studyDiffs[fieldKey]); - } - promises.push(osparc.data.Resources.fetch("studies", "patch", params)) + const promises = []; + let workbenchDiffs = {}; + if ("workbench" in studyDiffs) { + workbenchDiffs = studyDiffs["workbench"]; + promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchDiffs)); + delete studyDiffs["workbench"]; + } + const fieldKeys = Object.keys(studyDiffs); + if (fieldKeys.length) { + const patchData = {}; + const params = { + url: { + "studyId": this.getUuid() + }, + data: patchData + }; + fieldKeys.forEach(fieldKey => { + if (fieldKey === "ui") { + patchData[fieldKey] = this.getUi().serialize(); + } else { + const upKey = qx.lang.String.firstUp(fieldKey); + const getter = "get" + upKey; + patchData[fieldKey] = this[getter](studyDiffs[fieldKey]); + } + promises.push(osparc.data.Resources.fetch("studies", "patch", params)) + }); + } + return Promise.all(promises) + .then(() => { + // A bit hacky, but it's not sent back to the backend + this.set({ + lastChangeDate: new Date() }); - } - Promise.all(promises) - .then(() => { - // A bit hacky, but it's not sent back to the backend - this.set({ - lastChangeDate: new Date() - }); - const studyData = this.serialize(); - resolve(studyData); - }) - .catch(err => reject(err)); - }); + const studyData = this.serialize(); + return studyData; + }); }, updateStudy: function(params) { From 727de13469af287c632191acc5876826917ec249 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 7 Jun 2024 16:19:40 +0200 Subject: [PATCH 36/48] @ignapas reviews: less promises --- .../class/osparc/data/model/Workbench.js | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 46f6236259d..61e84dfc5d2 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -745,42 +745,38 @@ qx.Class.define("osparc.data.model.Workbench", { * @param workbenchDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes. */ patchWorkbenchDelayed: function(workbenchDiffs) { - return new Promise((resolve, reject) => { - const promises = []; - Object.keys(workbenchDiffs).forEach(nodeId => { - const node = this.getNode(nodeId); - if (node === null) { - // the node was removed - return; - } + const promises = []; + Object.keys(workbenchDiffs).forEach(nodeId => { + const node = this.getNode(nodeId); + if (node === null) { + // the node was removed + return; + } - const nodeData = node.serialize(); - let patchData = {}; - if (workbenchDiffs[nodeId] instanceof Array) { - // if workbenchDiffs is an array means that the node was either added or removed - // the node was added - patchData = nodeData; - // key can't be patched - delete patchData["key"]; - } else { - // patch only what was changed - Object.keys(workbenchDiffs[nodeId]).forEach(changedFieldKey => { - patchData[changedFieldKey] = nodeData[changedFieldKey]; - }); - } - const params = { - url: { - "studyId": this.getStudy().getUuid(), - "nodeId": nodeId - }, - data: patchData - }; - promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); - }) - Promise.all(promises) - .then(() => resolve()) - .catch(err => reject(err)); - }); + const nodeData = node.serialize(); + let patchData = {}; + if (workbenchDiffs[nodeId] instanceof Array) { + // if workbenchDiffs is an array means that the node was either added or removed + // the node was added + patchData = nodeData; + // key can't be patched + delete patchData["key"]; + } else { + // patch only what was changed + Object.keys(workbenchDiffs[nodeId]).forEach(changedFieldKey => { + patchData[changedFieldKey] = nodeData[changedFieldKey]; + }); + } + const params = { + url: { + "studyId": this.getStudy().getUuid(), + "nodeId": nodeId + }, + data: patchData + }; + promises.push(osparc.data.Resources.fetch("studies", "patchNode", params)); + }) + return Promise.all(promises); } } }); From c62d374bd9d599c317ee508e2f1a0c055d6f19ff Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 10 Jun 2024 08:54:52 +0200 Subject: [PATCH 37/48] minor --- .../client/source/class/osparc/data/model/StudyUI.js | 5 +++++ .../client/source/class/osparc/data/model/Workbench.js | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js b/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js index d7144921f9b..85a3e70139b 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js +++ b/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js @@ -103,6 +103,11 @@ qx.Class.define("osparc.data.model.StudyUI", { } }, + removeNode: function(nodeId) { + // remove it from slideshow + this.getSlideshow().removeNode(nodeId); + }, + serialize: function() { const currentStudy = osparc.store.Store.getInstance().getCurrentStudy(); let jsonObject = {}; diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 61e84dfc5d2..dcc2e48f37c 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -536,10 +536,9 @@ qx.Class.define("osparc.data.model.Workbench", { delete this.__rootNodes[nodeId]; } - // remove it from slideshow + // remove it from ui model if (this.getStudy()) { - this.getStudy().getUi().getSlideshow() - .removeNode(nodeId); + this.getStudy().getUi().removeNode(nodeId); } this.fireEvent("pipelineChanged"); From ed1600eebf28a8090b81aeb5f464742c2e6892e0 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 10 Jun 2024 09:08:45 +0200 Subject: [PATCH 38/48] minor --- .../client/source/class/osparc/data/model/StudyUI.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js b/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js index 85a3e70139b..d6451f158e3 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js +++ b/services/static-webserver/client/source/class/osparc/data/model/StudyUI.js @@ -42,6 +42,7 @@ qx.Class.define("osparc.data.model.StudyUI", { }, properties: { + // stores position and/or marker workbench: { check: "Object", init: {}, From 1b3b5a6f34ec7109395b8178753ad5f254239567 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 10 Jun 2024 09:36:51 +0200 Subject: [PATCH 39/48] minor --- .../client/source/class/osparc/dashboard/ResourceFilter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.js index 28f34825cb2..282c17707e6 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.js @@ -132,7 +132,7 @@ qx.Class.define("osparc.dashboard.ResourceFilter", { if (this.__tagButtons.length >= maxTags) { - const showAllButton = new qx.ui.form.Button(this.tr("Show all Tags..."), "@FontAwesome5Solid/tags/20"); + const showAllButton = new qx.ui.form.Button(this.tr("All Tags..."), "@FontAwesome5Solid/tags/20"); showAllButton.set({ appearance: "filter-toggle-button" }); @@ -140,11 +140,11 @@ qx.Class.define("osparc.dashboard.ResourceFilter", { showAllButton.addListener("execute", () => { if (showAllButton.showingAll) { this.__tagButtons.forEach((btn, idx) => btn.setVisibility(idx >= maxTags ? "excluded" : "visible")); - showAllButton.setLabel(this.tr("Show all Tags...")); + showAllButton.setLabel(this.tr("All Tags...")); showAllButton.showingAll = false; } else { this.__tagButtons.forEach(btn => btn.setVisibility("visible")); - showAllButton.setLabel(this.tr("Show less Tags...")); + showAllButton.setLabel(this.tr("Less Tags...")); showAllButton.showingAll = true; } }); From 07fc5cd4ef555c4d0155850c69a6b5d2471425e7 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 10 Jun 2024 11:43:57 +0200 Subject: [PATCH 40/48] let the backend set the nodeId --- .../client/source/class/osparc/data/model/Workbench.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index dcc2e48f37c..57ac89862ca 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -276,18 +276,16 @@ qx.Class.define("osparc.data.model.Workbench", { this.fireEvent("restartAutoSaveTimer"); // create the node in the backend first - const nodeId = osparc.utils.Utils.uuidV4() const params = { url: { studyId: this.getStudy().getUuid() }, data: { - "service_id": nodeId, "service_key": key, "service_version": version } }; - await osparc.data.Resources.fetch("studies", "addNode", params).catch(err => { + const resp = await osparc.data.Resources.fetch("studies", "addNode", params).catch(err => { let errorMsg = qx.locale.Manager.tr("Error creating ") + key + ":" + version; if ("status" in err && err.status === 406) { errorMsg = key + ":" + version + qx.locale.Manager.tr(" is retired"); @@ -300,6 +298,7 @@ qx.Class.define("osparc.data.model.Workbench", { osparc.FlashMessenger.getInstance().logAs(errorMsg, "ERROR"); return null; }); + const nodeId = resp["nodeId"]; this.fireEvent("restartAutoSaveTimer"); const node = this.__createNode(this.getStudy(), key, version, nodeId); @@ -671,7 +670,10 @@ qx.Class.define("osparc.data.model.Workbench", { populateNodesUIData: function(workbenchUIData) { if ("workbench" in workbenchUIData) { Object.keys(workbenchUIData["workbench"]).forEach(nodeId => { - this.getNode(nodeId).populateNodeUIData(workbenchUIData.workbench[nodeId]); + const node = this.getNode(nodeId); + if (node) { + node.populateNodeUIData(workbenchUIData.workbench[nodeId]); + } }); } }, From 12c2afae2e890ae8788d98060e82f221dd28f624 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 17 Jun 2024 09:59:26 +0200 Subject: [PATCH 41/48] minor fix --- .../client/source/class/osparc/service/ServiceListItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/static-webserver/client/source/class/osparc/service/ServiceListItem.js b/services/static-webserver/client/source/class/osparc/service/ServiceListItem.js index 2de25faf1f3..c2bf481e19e 100644 --- a/services/static-webserver/client/source/class/osparc/service/ServiceListItem.js +++ b/services/static-webserver/client/source/class/osparc/service/ServiceListItem.js @@ -29,6 +29,7 @@ qx.Class.define("osparc.service.ServiceListItem", { allowGrowX: true }); + this.setResourceType("service"); if (serviceModel) { this.setServiceModel(serviceModel); } From 452f96abbbdd6d3744066da79f635bb15b6b5788 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 11 Jul 2024 13:57:23 +0200 Subject: [PATCH 42/48] node_id --- .../client/source/class/osparc/data/model/Workbench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 7aa416f5a4f..cda2ffe532a 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -298,7 +298,7 @@ qx.Class.define("osparc.data.model.Workbench", { osparc.FlashMessenger.getInstance().logAs(errorMsg, "ERROR"); return null; }); - const nodeId = resp["nodeId"]; + const nodeId = resp["node_id"]; this.fireEvent("restartAutoSaveTimer"); const node = this.__createNode(this.getStudy(), key, version, nodeId); From d0a00148bf123d32607a7cff449fa77ad3c35839 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 11 Jul 2024 15:14:30 +0200 Subject: [PATCH 43/48] postRemoveNodeId --- .../class/osparc/data/model/Workbench.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index cda2ffe532a..9349be7b394 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -527,7 +527,7 @@ qx.Class.define("osparc.data.model.Workbench", { // remove first the connected edges const connectedEdges = this.getConnectedEdges(nodeId); connectedEdges.forEach(connectedEdgeId => { - this.removeEdge(connectedEdgeId); + this.removeEdge(connectedEdgeId, nodeId); }); const isTopLevel = Object.prototype.hasOwnProperty.call(this.__rootNodes, nodeId); @@ -586,28 +586,32 @@ qx.Class.define("osparc.data.model.Workbench", { return node; }, - removeEdge: function(edgeId) { + removeEdge: function(edgeId, postRemoveNodeId) { if (!osparc.data.Permissions.getInstance().canDo("study.edge.delete", true)) { return false; } const edge = this.getEdge(edgeId); if (edge) { - const inputNodeId = edge.getInputNodeId(); - const outputNodeId = edge.getOutputNodeId(); - const node = this.getNode(outputNodeId); - if (node) { - node.removeInputNode(inputNodeId); - node.removeNodePortConnections(inputNodeId); + const rightNodeId = edge.getOutputNodeId(); + const leftNodeId = edge.getInputNodeId(); + const rightNode = this.getNode(rightNodeId); + if (rightNode) { + if (rightNodeId !== postRemoveNodeId) { + // no need to make any changes to a just removed node (it would trigger a patch call) + rightNode.removeInputNode(leftNodeId); + rightNode.removeNodePortConnections(leftNodeId); + } + delete this.__edges[edgeId]; const edges = Object.values(this.__edges); - if (edges.findIndex(edg => edg.getInputNodeId() === inputNodeId) === -1) { - const nodeLeft = this.getNode(inputNodeId); + if (edges.findIndex(edg => edg.getInputNodeId() === leftNodeId) === -1) { + const nodeLeft = this.getNode(leftNodeId); nodeLeft.setOutputConnected(false); } - if (edges.findIndex(edg => edg.getOutputNodeId() === outputNodeId) === -1) { - const nodeRight = this.getNode(outputNodeId); + if (edges.findIndex(edg => edg.getOutputNodeId() === rightNodeId) === -1) { + const nodeRight = this.getNode(rightNodeId); nodeRight.setInputConnected(false); } From ae6fd22d4a40bb2dfb59fde7405976237a4eeef6 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 11 Jul 2024 15:59:42 +0200 Subject: [PATCH 44/48] minor --- .../source/class/osparc/data/model/Workbench.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 9349be7b394..9f1462ba074 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -76,7 +76,7 @@ qx.Class.define("osparc.data.model.Workbench", { members: { __workbenchInitData: null, __workbenchUIInitData: null, - __rootNodes: null, + __nodes: null, __edges: null, getWorkbenchInitData: function() { @@ -85,7 +85,7 @@ qx.Class.define("osparc.data.model.Workbench", { // deserializes the workbenchInitData buildWorkbench: function() { - this.__rootNodes = {}; + this.__nodes = {}; this.__edges = {}; this.__deserialize(this.__workbenchInitData, this.__workbenchUIInitData); this.__workbenchInitData = null; @@ -181,7 +181,7 @@ qx.Class.define("osparc.data.model.Workbench", { }, getNodes: function() { - let nodes = Object.assign({}, this.__rootNodes); + let nodes = Object.assign({}, this.__nodes); return nodes; }, @@ -504,7 +504,7 @@ qx.Class.define("osparc.data.model.Workbench", { __addNode: function(node) { const nodeId = node.getNodeId(); - this.__rootNodes[nodeId] = node; + this.__nodes[nodeId] = node; this.fireEvent("pipelineChanged"); }, @@ -530,10 +530,7 @@ qx.Class.define("osparc.data.model.Workbench", { this.removeEdge(connectedEdgeId, nodeId); }); - const isTopLevel = Object.prototype.hasOwnProperty.call(this.__rootNodes, nodeId); - if (isTopLevel) { - delete this.__rootNodes[nodeId]; - } + delete this.__nodes[nodeId]; // remove it from ui model if (this.getStudy()) { From 7f065e9959099635ec8452c5ece3b4349fed3f45 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 11 Jul 2024 16:07:51 +0200 Subject: [PATCH 45/48] refactoring --- .../class/osparc/data/model/Workbench.js | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 9f1462ba074..cbc558027bd 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -524,14 +524,15 @@ qx.Class.define("osparc.data.model.Workbench", { const removed = await node.removeNode(); if (removed) { this.fireEvent("restartAutoSaveTimer"); + + delete this.__nodes[nodeId]; + // remove first the connected edges const connectedEdges = this.getConnectedEdges(nodeId); connectedEdges.forEach(connectedEdgeId => { - this.removeEdge(connectedEdgeId, nodeId); + this.removeEdge(connectedEdgeId); }); - delete this.__nodes[nodeId]; - // remove it from ui model if (this.getStudy()) { this.getStudy().getUi().removeNode(nodeId); @@ -583,7 +584,7 @@ qx.Class.define("osparc.data.model.Workbench", { return node; }, - removeEdge: function(edgeId, postRemoveNodeId) { + removeEdge: function(edgeId) { if (!osparc.data.Permissions.getInstance().canDo("study.edge.delete", true)) { return false; } @@ -592,28 +593,31 @@ qx.Class.define("osparc.data.model.Workbench", { if (edge) { const rightNodeId = edge.getOutputNodeId(); const leftNodeId = edge.getInputNodeId(); + const rightNode = this.getNode(rightNodeId); if (rightNode) { - if (rightNodeId !== postRemoveNodeId) { - // no need to make any changes to a just removed node (it would trigger a patch call) - rightNode.removeInputNode(leftNodeId); - rightNode.removeNodePortConnections(leftNodeId); - } + // no need to make any changes to a just removed node (it would trigger a patch call) + rightNode.removeInputNode(leftNodeId); + rightNode.removeNodePortConnections(leftNodeId); + } - delete this.__edges[edgeId]; + delete this.__edges[edgeId]; - const edges = Object.values(this.__edges); - if (edges.findIndex(edg => edg.getInputNodeId() === leftNodeId) === -1) { - const nodeLeft = this.getNode(leftNodeId); - nodeLeft.setOutputConnected(false); + // update the port decorations (remove dot if there are no more connections) + const edges = Object.values(this.__edges); + if (edges.findIndex(edg => edg.getInputNodeId() === leftNodeId) === -1) { + const leftNode = this.getNode(leftNodeId); + if (leftNode) { + leftNode.setOutputConnected(false); } - if (edges.findIndex(edg => edg.getOutputNodeId() === rightNodeId) === -1) { - const nodeRight = this.getNode(rightNodeId); - nodeRight.setInputConnected(false); + } + if (edges.findIndex(edg => edg.getOutputNodeId() === rightNodeId) === -1) { + if (rightNode) { + rightNode.setInputConnected(false); } - - return true; } + + return true; } return false; }, From 37bc617361f3f8aa113bd80c7be27d19817a7a24 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 12 Jul 2024 11:17:44 +0200 Subject: [PATCH 46/48] no need to trigger the retrieve inputs calls chain if it's not dynamic --- .../client/source/class/osparc/data/model/Node.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Node.js b/services/static-webserver/client/source/class/osparc/data/model/Node.js index ee64755ec17..b414933df58 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Node.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Node.js @@ -1006,7 +1006,9 @@ qx.Class.define("osparc.data.model.Node", { node: this, portKey }; - this.fireDataEvent("retrieveInputs", data); + if (this.isDynamic()) { + this.fireDataEvent("retrieveInputs", data); + } }, retrieveInputs: function(portKey) { From 04e026feb2a765ed9a2f4a50a2daeed3b15280c1 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 15 Jul 2024 13:02:56 +0200 Subject: [PATCH 47/48] minor --- .../client/source/class/osparc/data/model/Study.js | 7 +++++-- .../client/source/class/osparc/desktop/StudyEditor.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index 70aea4650b6..ae4b5cf83d9 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -230,13 +230,16 @@ qx.Class.define("osparc.data.model.Study", { }, // deep clones object with study-only properties - deepCloneStudyObject: function(src) { - const studyObject = osparc.utils.Utils.deepCloneObject(src); + deepCloneStudyObject: function(obj, ignoreExtra = false) { + const studyObject = osparc.utils.Utils.deepCloneObject(obj); const studyPropKeys = osparc.data.model.Study.getProperties(); Object.keys(studyObject).forEach(key => { if (!studyPropKeys.includes(key)) { delete studyObject[key]; } + if (ignoreExtra && osparc.data.model.Study.IgnoreSerializationProps.includes(key)) { + delete studyObject[key]; + } }); return studyObject; }, diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index eb0a620dc54..f34ea294774 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -756,6 +756,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__updatingStudy++; let updatePromise = null; if (osparc.utils.Utils.isDevelopmentPlatform()) { + // For now, master deployment only const studyDiffs = this.__getStudyDiffs(); updatePromise = this.getStudy().patchStudyDelayed(studyDiffs) } else { @@ -764,7 +765,7 @@ qx.Class.define("osparc.desktop.StudyEditor", { } return updatePromise .then(studyData => { - this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(studyData); + this.__studyDataInBackend = osparc.data.model.Study.deepCloneStudyObject(studyData, true); }) .catch(error => { if ("status" in error && error.status === 409) { From d316c7fd560995b97f5dd38f0be5371bbd4b2c8c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Mon, 15 Jul 2024 13:51:39 +0200 Subject: [PATCH 48/48] init studyDataInBackend --- .../client/source/class/osparc/desktop/StudyEditor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index f34ea294774..e8649304154 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -168,8 +168,8 @@ qx.Class.define("osparc.desktop.StudyEditor", { this.__reloadSnapshotsAndIterations(); study.openStudy() - .then(() => { - this.__studyDataInBackend = osparc.utils.Utils.deepCloneObject(study.serialize()); + .then(studyData => { + this.__studyDataInBackend = studyData; this.__workbenchView.setStudy(study); this.__slideshowView.setStudy(study);