Skip to content

Commit dfc7a78

Browse files
committed
listenToChanges Node
1 parent 889afcb commit dfc7a78

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

services/static-webserver/client/source/class/osparc/data/model/Node.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,23 @@ qx.Class.define("osparc.data.model.Node", {
12411241
}
12421242
},
12431243

1244+
listenToChanges: function() {
1245+
const propertyKeys = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Node))
1246+
propertyKeys.forEach(key => {
1247+
this.addListener("change" + qx.lang.String.firstUp(key), e => {
1248+
const nodeId = this.getNodeId();
1249+
const data = e.getData();
1250+
this.fireDataEvent("updateStudyDocument", {
1251+
"op": "replace",
1252+
"path": `/workbench/${nodeId}/` + key,
1253+
"value": data
1254+
});
1255+
}, this);
1256+
});
1257+
1258+
this.getWorkbench().addListener("updateStudyDocument", e => this.fireDataEvent("updateStudyDocument", e.getData()), this);
1259+
},
1260+
12441261
serialize: function(clean = true) {
12451262
// node generic
12461263
let nodeEntry = {

services/static-webserver/client/source/class/osparc/data/model/Study.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ qx.Class.define("osparc.data.model.Study", {
304304

305305
// deep clones object with study-only properties
306306
deepCloneStudyObject: function(obj, ignoreExtra = false) {
307-
const studyObject = osparc.utils.Utils.deepCloneObject(obj);
308307
const studyPropKeys = osparc.data.model.Study.getProperties();
308+
const studyObject = osparc.utils.Utils.deepCloneObject(obj);
309309
Object.keys(studyObject).forEach(key => {
310310
if (!studyPropKeys.includes(key)) {
311311
delete studyObject[key];
@@ -379,7 +379,7 @@ qx.Class.define("osparc.data.model.Study", {
379379
},
380380

381381
members: {
382-
listenToStudyChanges: function() {
382+
listenToChanges: function() {
383383
const propertyKeys = this.self().getProperties();
384384
propertyKeys.forEach(key => {
385385
if (!this.self().IgnoreSerializationProps.includes(key)) {
@@ -393,6 +393,8 @@ qx.Class.define("osparc.data.model.Study", {
393393
}, this);
394394
}
395395
});
396+
397+
this.getWorkbench().addListener("updateStudyDocument", e => this.fireDataEvent("updateStudyDocument", e.getData()), this);
396398
},
397399

398400
serialize: function(clean = true) {

services/static-webserver/client/source/class/osparc/data/model/Workbench.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ qx.Class.define("osparc.data.model.Workbench", {
272272

273273
__createNode: function(study, metadata, uuid) {
274274
const node = new osparc.data.model.Node(study, metadata, uuid);
275+
node.listenToChanges();
275276
node.addListener("keyChanged", () => this.fireEvent("reloadModel"), this);
276277
node.addListener("changeInputNodes", () => this.fireDataEvent("pipelineChanged"), this);
277278
node.addListener("reloadModel", () => this.fireEvent("reloadModel"), this);

services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ qx.Class.define("osparc.desktop.StudyEditor", {
146146

147147
study.openStudy()
148148
.then(studyData => {
149-
study.listenToStudyChanges();
150-
151149
this.__setStudyDataInBackend(studyData);
152150

151+
study.listenToChanges();
152+
study.addListener("updateStudyDocument", e => this.updateStudyDocument(e.getData()), this);
153+
153154
this.__workbenchView.setStudy(study);
154155
this.__slideshowView.setStudy(study);
155156

@@ -833,13 +834,15 @@ qx.Class.define("osparc.desktop.StudyEditor", {
833834
return changed;
834835
},
835836

836-
updateStudyDocument: function() {
837+
updateStudyDocument: function(data = null) {
837838
if (!osparc.data.model.Study.canIWrite(this.getStudy().getAccessRights())) {
838839
return new Promise(resolve => {
839840
resolve();
840841
});
841842
}
842843

844+
console.log("updateStudyDocument", data);
845+
843846
this.__updatingStudy++;
844847
const studyDiffs = this.__getStudyDiffs();
845848
return this.getStudy().patchStudyDelayed(studyDiffs.delta, studyDiffs.sourceStudy)

0 commit comments

Comments
 (0)