Skip to content

Commit a98b2fb

Browse files
authored
🎨 [Frontend] Event-driven patch regardless of whether RTC is enabled (#8328)
1 parent 8a512a9 commit a98b2fb

File tree

7 files changed

+7
-181
lines changed

7 files changed

+7
-181
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ qx.Class.define("osparc.data.model.Node", {
196196
},
197197

198198
events: {
199-
"updateStudyDocument": "qx.event.type.Event",
200199
"projectDocumentChanged": "qx.event.type.Data",
201200
"reloadModel": "qx.event.type.Event",
202201
"retrieveInputs": "qx.event.type.Data",
@@ -490,6 +489,7 @@ qx.Class.define("osparc.data.model.Node", {
490489
this.populateNodeUIData(nodeData);
491490
// new place to store the position and marker
492491
this.populateNodeUIData(nodeUiData);
492+
this.listenToChanges();
493493
})
494494
.catch(err => {
495495
console.log(err);

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

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ qx.Class.define("osparc.data.model.Workbench", {
5050
},
5151

5252
events: {
53-
"updateStudyDocument": "qx.event.type.Event",
5453
"projectDocumentChanged": "qx.event.type.Data",
55-
"restartAutoSaveTimer": "qx.event.type.Event",
5654
"pipelineChanged": "qx.event.type.Event",
5755
"nodeAdded": "qx.event.type.Data",
5856
"nodeRemoved": "qx.event.type.Data",
@@ -352,7 +350,6 @@ qx.Class.define("osparc.data.model.Workbench", {
352350
return null;
353351
}
354352

355-
this.fireEvent("restartAutoSaveTimer");
356353
// create the node in the backend first
357354
const params = {
358355
url: {
@@ -368,7 +365,6 @@ qx.Class.define("osparc.data.model.Workbench", {
368365
const resp = await osparc.data.Resources.fetch("studies", "addNode", params);
369366
const nodeId = resp["node_id"];
370367

371-
this.fireEvent("restartAutoSaveTimer");
372368
const node = this.__createNode(key, version, nodeId);
373369
node.fetchMetadataAndPopulate()
374370
.then(() => {
@@ -394,15 +390,10 @@ qx.Class.define("osparc.data.model.Workbench", {
394390
},
395391

396392
__initNodeSignals: function(node) {
397-
if (osparc.utils.Utils.eventDrivenPatch()) {
398-
node.listenToChanges();
399-
node.addListener("projectDocumentChanged", e => this.fireDataEvent("projectDocumentChanged", e.getData()), this);
400-
}
393+
node.addListener("projectDocumentChanged", e => this.fireDataEvent("projectDocumentChanged", e.getData()), this);
401394
node.addListener("keyChanged", () => this.fireEvent("reloadModel"), this);
402395
node.addListener("changeInputNodes", () => this.fireDataEvent("pipelineChanged"), this);
403396
node.addListener("reloadModel", () => this.fireEvent("reloadModel"), this);
404-
node.addListener("updateStudyDocument", () => this.fireEvent("updateStudyDocument"), this);
405-
406397
node.addListener("showInLogger", e => this.fireDataEvent("showInLogger", e.getData()), this);
407398
node.addListener("retrieveInputs", e => this.fireDataEvent("retrieveInputs", e.getData()), this);
408399
node.addListener("fileRequested", e => this.fireDataEvent("fileRequested", e.getData()), this);
@@ -633,7 +624,6 @@ qx.Class.define("osparc.data.model.Workbench", {
633624
return;
634625
}
635626

636-
this.fireEvent("restartAutoSaveTimer");
637627
let node = this.getNode(nodeId);
638628
if (node) {
639629
// remove the node in the backend first
@@ -645,8 +635,6 @@ qx.Class.define("osparc.data.model.Workbench", {
645635
},
646636

647637
__nodeRemoved: function(nodeId) {
648-
this.fireEvent("restartAutoSaveTimer");
649-
650638
delete this.__nodes[nodeId];
651639

652640
// remove first the connected edges
@@ -955,82 +943,5 @@ qx.Class.define("osparc.data.model.Workbench", {
955943
node.updateNodeFromPatch(nodePatches);
956944
});
957945
},
958-
959-
/**
960-
* @deprecated This method is deprecated and will be removed in a future release.
961-
* Please use `__deserialize` instead for deserializing workbench data.
962-
* Migration: Replace calls to `__deserializeOld` with `__deserialize`.
963-
*/
964-
__deserializeOld: function(workbenchInitData, workbenchUIInitData) {
965-
this.__deserializeNodesOld(workbenchInitData, workbenchUIInitData)
966-
.then(() => {
967-
this.__deserializeEdges(workbenchInitData);
968-
workbenchInitData = null;
969-
workbenchUIInitData = null;
970-
this.setDeserialized(true);
971-
});
972-
},
973-
974-
__deserializeNodesOld: function(workbenchData, workbenchUIData = {}) {
975-
const nodeIds = Object.keys(workbenchData);
976-
const serviceMetadataPromises = [];
977-
nodeIds.forEach(nodeId => {
978-
const nodeData = workbenchData[nodeId];
979-
serviceMetadataPromises.push(osparc.store.Services.getService(nodeData.key, nodeData.version));
980-
});
981-
return Promise.allSettled(serviceMetadataPromises)
982-
.then(results => {
983-
const missing = results.filter(result => result.status === "rejected" || result.value === null)
984-
if (missing.length) {
985-
const errorMsg = qx.locale.Manager.tr("Service metadata missing");
986-
osparc.FlashMessenger.logError(errorMsg);
987-
return;
988-
}
989-
const values = results.map(result => result.value);
990-
// Create first all the nodes
991-
for (let i=0; i<nodeIds.length; i++) {
992-
const metadata = values[i];
993-
const nodeId = nodeIds[i];
994-
this.__createNodeOld(metadata, nodeId);
995-
}
996-
997-
// Then populate them (this will avoid issues of connecting nodes that might not be created yet)
998-
this.__populateNodesDataOld(workbenchData, workbenchUIData);
999-
});
1000-
},
1001-
1002-
__createNodeOld: function(metadata, nodeId) {
1003-
const node = new osparc.data.model.Node(this.getStudy(), metadata["key"], metadata["version"], nodeId);
1004-
node.setMetadata(metadata);
1005-
if (osparc.utils.Utils.eventDrivenPatch()) {
1006-
node.listenToChanges();
1007-
node.addListener("projectDocumentChanged", e => this.fireDataEvent("projectDocumentChanged", e.getData()), this);
1008-
}
1009-
node.addListener("keyChanged", () => this.fireEvent("reloadModel"), this);
1010-
node.addListener("changeInputNodes", () => this.fireDataEvent("pipelineChanged"), this);
1011-
node.addListener("reloadModel", () => this.fireEvent("reloadModel"), this);
1012-
node.addListener("updateStudyDocument", () => this.fireEvent("updateStudyDocument"), this);
1013-
osparc.utils.Utils.localCache.serviceToFavs(metadata["key"]);
1014-
1015-
this.__initNodeSignals(node);
1016-
this.__addNode(node);
1017-
1018-
return node;
1019-
},
1020-
1021-
__populateNodesDataOld: function(workbenchData, workbenchUIData) {
1022-
Object.entries(workbenchData).forEach(([nodeId, nodeData]) => {
1023-
this.getNode(nodeId).populateNodeData(nodeData);
1024-
1025-
if ("position" in nodeData) {
1026-
// old place to store the position
1027-
this.getNode(nodeId).populateNodeUIData(nodeData);
1028-
}
1029-
if (workbenchUIData && "workbench" in workbenchUIData && nodeId in workbenchUIData["workbench"]) {
1030-
// new place to store the position and marker
1031-
this.getNode(nodeId).populateNodeUIData(workbenchUIData["workbench"][nodeId]);
1032-
}
1033-
});
1034-
},
1035946
}
1036947
});

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

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ qx.Class.define("osparc.desktop.StudyEditor", {
155155
__viewsStack: null,
156156
__workbenchView: null,
157157
__slideshowView: null,
158-
__autoSaveTimer: null,
159-
__savingTimer: null,
160158
__studyEditorIdlingTracker: null,
161159
__lastSyncedProjectDocument: null,
162160
__lastSyncedProjectVersion: null,
@@ -267,10 +265,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
267265
}
268266
}
269267

270-
if (osparc.data.model.Study.canIWrite(study.getAccessRights())) {
271-
this.__startAutoSaveTimer();
272-
this.__startSavingTimer();
273-
} else {
268+
if (!osparc.data.model.Study.canIWrite(study.getAccessRights())) {
274269
const msg = this.self().READ_ONLY_TEXT;
275270
osparc.FlashMessenger.logAs(msg, "WARNING");
276271
}
@@ -292,13 +287,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
292287
this.nodeSelected(nodeId);
293288
}, this);
294289

295-
if (osparc.utils.Utils.eventDrivenPatch()) {
296-
study.listenToChanges(); // this includes the listener on the workbench and ui
297-
study.addListener("projectDocumentChanged", e => this.projectDocumentChanged(e.getData()), this);
298-
} else {
299-
workbench.addListener("updateStudyDocument", () => this.updateStudyDocument());
300-
workbench.addListener("restartAutoSaveTimer", () => this.__restartAutoSaveTimer());
301-
}
290+
study.listenToChanges(); // this includes the listener on the workbench and ui
291+
study.addListener("projectDocumentChanged", e => this.projectDocumentChanged(e.getData()), this);
302292

303293
if (osparc.utils.DisabledPlugins.isRTCEnabled()) {
304294
this.__listenToProjectDocument();
@@ -953,67 +943,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
953943
},
954944
// ------------------ IDLING TRACKER ------------------
955945

956-
// ------------------ AUTO SAVER ------------------
957-
__startAutoSaveTimer: function() {
958-
if (osparc.utils.Utils.eventDrivenPatch()) {
959-
// If event driven patch is enabled, auto save is not needed
960-
return;
961-
}
962-
963-
// Save every 3 seconds
964-
const timer = this.__autoSaveTimer = new qx.event.Timer(this.self().AUTO_SAVE_INTERVAL);
965-
timer.addListener("interval", () => {
966-
if (!osparc.wrapper.WebSocket.getInstance().isConnected()) {
967-
return;
968-
}
969-
this.__checkStudyChanges();
970-
}, this);
971-
timer.start();
972-
},
973-
974-
__stopAutoSaveTimer: function() {
975-
if (this.__autoSaveTimer && this.__autoSaveTimer.isEnabled()) {
976-
this.__autoSaveTimer.stop();
977-
this.__autoSaveTimer.setEnabled(false);
978-
}
979-
},
980-
981-
__restartAutoSaveTimer: function() {
982-
if (this.__autoSaveTimer && this.__autoSaveTimer.isEnabled()) {
983-
this.__autoSaveTimer.restart();
984-
}
985-
},
986-
// ------------------ AUTO SAVER ------------------
987-
988-
// ---------------- SAVING TIMER ------------------
989-
__startSavingTimer: function() {
990-
if (osparc.utils.Utils.eventDrivenPatch()) {
991-
// If event driven patch is enabled, saving timer indicator is not needed
992-
return;
993-
}
994-
995-
const timer = this.__savingTimer = new qx.event.Timer(this.self().DIFF_CHECK_INTERVAL);
996-
timer.addListener("interval", () => {
997-
if (!osparc.wrapper.WebSocket.getInstance().isConnected()) {
998-
return;
999-
}
1000-
this.getStudy().setSavePending(this.didStudyChange());
1001-
}, this);
1002-
timer.start();
1003-
},
1004-
1005-
__stopSavingTimer: function() {
1006-
if (this.__savingTimer && this.__savingTimer.isEnabled()) {
1007-
this.__savingTimer.stop();
1008-
this.__savingTimer.setEnabled(false);
1009-
}
1010-
},
1011-
// ---------------- SAVING TIMER ------------------
1012-
1013946
__stopTimers: function() {
1014947
this.__stopIdlingTracker();
1015-
this.__stopAutoSaveTimer();
1016-
this.__stopSavingTimer();
1017948
},
1018949

1019950
__getStudyDiffs: function() {
@@ -1040,17 +971,6 @@ qx.Class.define("osparc.desktop.StudyEditor", {
1040971
return changed;
1041972
},
1042973

1043-
__checkStudyChanges: function() {
1044-
if (this.didStudyChange()) {
1045-
if (this.__updatingStudy > 0) {
1046-
// throttle update
1047-
this.__updateThrottled = true;
1048-
} else {
1049-
this.updateStudyDocument();
1050-
}
1051-
}
1052-
},
1053-
1054974
/**
1055975
* @param {JSON Patch} data It will soon be used to patch the project document https://datatracker.ietf.org/doc/html/rfc6902
1056976
*/

services/static-webserver/client/source/class/osparc/node/BootOptionsView.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ qx.Class.define("osparc.node.BootOptionsView", {
5454
"boot_mode": newBootModeId
5555
};
5656
node.setBootOptions(data);
57-
node.fireEvent("updateStudyDocument");
5857
node.fireDataEvent("projectDocumentChanged", {
5958
"op": "replace",
6059
"path": `/workbench/${nodeId}/bootOptions`,

services/static-webserver/client/source/class/osparc/node/LifeCycleView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ qx.Class.define("osparc.node.LifeCycleView", {
119119
newData["version"] = latestCompatible["version"];
120120
}
121121
node.set(newData);
122-
node.fireEvent("updateStudyDocument");
122+
const nodeId = node.getNodeId();
123123
node.fireDataEvent("projectDocumentChanged", [{
124124
"op": "replace",
125125
"path": `/workbench/${nodeId}/key`,

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,6 @@ qx.Class.define("osparc.utils.Utils", {
542542
return (["dev", "master"].includes(platformName));
543543
},
544544

545-
eventDrivenPatch: function() {
546-
return osparc.utils.DisabledPlugins.isRTCEnabled();
547-
},
548-
549545
getEditButton: function(isVisible = true) {
550546
return new qx.ui.form.Button(null, "@FontAwesome5Solid/pencil-alt/12").set({
551547
appearance: "form-button-outlined",

services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
540540

541541
nodeUI.addListener("dbltap", e => {
542542
this.fireDataEvent("nodeSelected", nodeUI.getNodeId());
543-
if (nodeUI.getNode().canNodeStart()) {
543+
if (nodeUI.getNode().canNodeStart() && !nodeUI.getNode().getStudy().getDisableServiceAutoStart()) {
544544
nodeUI.getNode().requestStartNode();
545545
}
546546
e.stopPropagation();

0 commit comments

Comments
 (0)