Skip to content

Commit d4b0756

Browse files
committed
bring back old way
1 parent e220eac commit d4b0756

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

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

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

5252
events: {
5353
"updateStudyDocument": "qx.event.type.Data",
54+
"restartAutoSaveTimer": "qx.event.type.Event",
5455
"pipelineChanged": "qx.event.type.Event",
5556
"reloadModel": "qx.event.type.Event",
5657
"retrieveInputs": "qx.event.type.Data",
@@ -292,6 +293,7 @@ qx.Class.define("osparc.data.model.Workbench", {
292293
return null;
293294
}
294295

296+
this.fireEvent("restartAutoSaveTimer");
295297
// create the node in the backend first
296298
const params = {
297299
url: {
@@ -308,6 +310,7 @@ qx.Class.define("osparc.data.model.Workbench", {
308310
const resp = await osparc.data.Resources.fetch("studies", "addNode", params);
309311
const nodeId = resp["node_id"];
310312

313+
this.fireEvent("restartAutoSaveTimer");
311314
const node = this.__createNode(this.getStudy(), metadata, nodeId);
312315
this.__initNodeSignals(node);
313316
this.__addNode(node);
@@ -539,11 +542,14 @@ qx.Class.define("osparc.data.model.Workbench", {
539542
return false;
540543
}
541544

545+
this.fireEvent("restartAutoSaveTimer");
542546
let node = this.getNode(nodeId);
543547
if (node) {
544548
// remove the node in the backend first
545549
const removed = await node.removeNode();
546550
if (removed) {
551+
this.fireEvent("restartAutoSaveTimer");
552+
547553
delete this.__nodes[nodeId];
548554

549555
// remove first the connected edges

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
104104
},
105105

106106
statics: {
107+
AUTO_SAVE_INTERVAL: 3000,
108+
DIFF_CHECK_INTERVAL: 300,
107109
READ_ONLY_TEXT: qx.locale.Manager.tr("You do not have writing permissions.<br>Your changes will not be saved."),
108110
},
109111

@@ -112,6 +114,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
112114
__viewsStack: null,
113115
__workbenchView: null,
114116
__slideshowView: null,
117+
__autoSaveTimer: null,
118+
__savingTimer: null,
115119
__studyEditorIdlingTracker: null,
116120
__studyDataInBackend: null,
117121
__updatingStudy: null,
@@ -220,7 +224,10 @@ qx.Class.define("osparc.desktop.StudyEditor", {
220224
}
221225
}
222226

223-
if (!osparc.data.model.Study.canIWrite(study.getAccessRights())) {
227+
if (osparc.data.model.Study.canIWrite(study.getAccessRights())) {
228+
this.__startAutoSaveTimer();
229+
this.__startSavingTimer();
230+
} else {
224231
const msg = this.self().READ_ONLY_TEXT;
225232
osparc.FlashMessenger.logAs(msg, "WARNING");
226233
}
@@ -241,6 +248,10 @@ qx.Class.define("osparc.desktop.StudyEditor", {
241248
const nodeId = e.getData();
242249
this.nodeSelected(nodeId);
243250
}, this);
251+
252+
// listener already added in __applyStudy
253+
// workbench.addListener("updateStudyDocument", () => this.updateStudyDocument());
254+
workbench.addListener("restartAutoSaveTimer", () => this.__restartAutoSaveTimer());
244255
},
245256

246257
__setStudyDataInBackend: function(studyData) {
@@ -793,8 +804,57 @@ qx.Class.define("osparc.desktop.StudyEditor", {
793804
},
794805
// ------------------ IDLING TRACKER ------------------
795806

807+
// ------------------ AUTO SAVER ------------------
808+
__startAutoSaveTimer: function() {
809+
// Save every 3 seconds
810+
const timer = this.__autoSaveTimer = new qx.event.Timer(this.self().AUTO_SAVE_INTERVAL);
811+
timer.addListener("interval", () => {
812+
if (!osparc.wrapper.WebSocket.getInstance().isConnected()) {
813+
return;
814+
}
815+
this.__checkStudyChanges();
816+
}, this);
817+
timer.start();
818+
},
819+
820+
__stopAutoSaveTimer: function() {
821+
if (this.__autoSaveTimer && this.__autoSaveTimer.isEnabled()) {
822+
this.__autoSaveTimer.stop();
823+
this.__autoSaveTimer.setEnabled(false);
824+
}
825+
},
826+
827+
__restartAutoSaveTimer: function() {
828+
if (this.__autoSaveTimer && this.__autoSaveTimer.isEnabled()) {
829+
this.__autoSaveTimer.restart();
830+
}
831+
},
832+
// ------------------ AUTO SAVER ------------------
833+
834+
// ---------------- SAVING TIMER ------------------
835+
__startSavingTimer: function() {
836+
const timer = this.__savingTimer = new qx.event.Timer(this.self().DIFF_CHECK_INTERVAL);
837+
timer.addListener("interval", () => {
838+
if (!osparc.wrapper.WebSocket.getInstance().isConnected()) {
839+
return;
840+
}
841+
this.getStudy().setSavePending(this.didStudyChange());
842+
}, this);
843+
timer.start();
844+
},
845+
846+
__stopSavingTimer: function() {
847+
if (this.__savingTimer && this.__savingTimer.isEnabled()) {
848+
this.__savingTimer.stop();
849+
this.__savingTimer.setEnabled(false);
850+
}
851+
},
852+
// ---------------- SAVING TIMER ------------------
853+
796854
__stopTimers: function() {
797855
this.__stopIdlingTracker();
856+
this.__stopAutoSaveTimer();
857+
this.__stopSavingTimer();
798858
},
799859

800860
__getStudyDiffs: function() {
@@ -813,7 +873,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
813873
return studyDiffs;
814874
},
815875

816-
// this takes around 0.5ms
876+
// didStudyChange takes around 0.5ms
817877
didStudyChange: function() {
818878
const studyDiffs = this.__getStudyDiffs();
819879
const changed = Boolean(Object.keys(studyDiffs.delta).length);

0 commit comments

Comments
 (0)