Skip to content

Commit 1fbd9df

Browse files
authored
🎨 [Frontend] Patch study from Study Editor (#5916)
1 parent 3b512b7 commit 1fbd9df

File tree

10 files changed

+221
-143
lines changed

10 files changed

+221
-143
lines changed

services/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,19 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
143143

144144

145145
if (this.__tagButtons.length >= maxTags) {
146-
const showAllButton = new qx.ui.form.Button(this.tr("Show all Tags..."), "@FontAwesome5Solid/tags/20");
146+
const showAllButton = new qx.ui.form.Button(this.tr("All Tags..."), "@FontAwesome5Solid/tags/20");
147147
showAllButton.set({
148148
appearance: "filter-toggle-button"
149149
});
150150
showAllButton.showingAll = false;
151151
showAllButton.addListener("execute", () => {
152152
if (showAllButton.showingAll) {
153153
this.__tagButtons.forEach((btn, idx) => btn.setVisibility(idx >= maxTags ? "excluded" : "visible"));
154-
showAllButton.setLabel(this.tr("Show all Tags..."));
154+
showAllButton.setLabel(this.tr("All Tags..."));
155155
showAllButton.showingAll = false;
156156
} else {
157157
this.__tagButtons.forEach(btn => btn.setVisibility("visible"));
158-
showAllButton.setLabel(this.tr("Show less Tags..."));
158+
showAllButton.setLabel(this.tr("Less Tags..."));
159159
showAllButton.showingAll = true;
160160
}
161161
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,9 @@ qx.Class.define("osparc.data.model.Node", {
10061006
node: this,
10071007
portKey
10081008
};
1009-
this.fireDataEvent("retrieveInputs", data);
1009+
if (this.isDynamic()) {
1010+
this.fireDataEvent("retrieveInputs", data);
1011+
}
10101012
},
10111013

10121014
retrieveInputs: function(portKey) {

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

Lines changed: 84 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ qx.Class.define("osparc.data.model.Study", {
6464
this.setWorkbench(workbench);
6565
workbench.setStudy(this);
6666

67-
this.setUi(new osparc.data.model.StudyUI(studyData.ui));
67+
const workbenchUi = new osparc.data.model.StudyUI(studyData.ui);
68+
this.setUi(workbenchUi);
6869

6970
this.getWorkbench().buildWorkbench();
7071
},
@@ -229,13 +230,16 @@ qx.Class.define("osparc.data.model.Study", {
229230
},
230231

231232
// deep clones object with study-only properties
232-
deepCloneStudyObject: function(src) {
233-
const studyObject = osparc.utils.Utils.deepCloneObject(src);
233+
deepCloneStudyObject: function(obj, ignoreExtra = false) {
234+
const studyObject = osparc.utils.Utils.deepCloneObject(obj);
234235
const studyPropKeys = osparc.data.model.Study.getProperties();
235236
Object.keys(studyObject).forEach(key => {
236237
if (!studyPropKeys.includes(key)) {
237238
delete studyObject[key];
238239
}
240+
if (ignoreExtra && osparc.data.model.Study.IgnoreSerializationProps.includes(key)) {
241+
delete studyObject[key];
242+
}
239243
});
240244
return studyObject;
241245
},
@@ -316,6 +320,30 @@ qx.Class.define("osparc.data.model.Study", {
316320
},
317321

318322
members: {
323+
serialize: function(clean = true) {
324+
let jsonObject = {};
325+
const propertyKeys = this.self().getProperties();
326+
propertyKeys.forEach(key => {
327+
if (this.self().IgnoreSerializationProps.includes(key)) {
328+
return;
329+
}
330+
if (key === "workbench") {
331+
jsonObject[key] = this.getWorkbench().serialize(clean);
332+
return;
333+
}
334+
if (key === "ui") {
335+
jsonObject[key] = this.getUi().serialize();
336+
return;
337+
}
338+
const value = this.get(key);
339+
if (value !== null) {
340+
// only put the value in the payload if there is a value
341+
jsonObject[key] = value;
342+
}
343+
});
344+
return jsonObject;
345+
},
346+
319347
initStudy: function() {
320348
this.getWorkbench().initWorkbench();
321349
},
@@ -549,80 +577,80 @@ qx.Class.define("osparc.data.model.Study", {
549577
return !this.getUi().getSlideshow().isEmpty();
550578
},
551579

552-
serializeStudyData: function() {
553-
let studyData = {};
554-
const propertyKeys = this.self().getProperties();
555-
propertyKeys.forEach(key => {
556-
if (key === "workbench") {
557-
studyData[key] = this.getWorkbench().serialize();
558-
return;
559-
}
560-
if (key === "ui") {
561-
studyData[key] = this.getUi().serialize();
562-
return;
563-
}
564-
const value = this.get(key);
565-
studyData[key] = value;
566-
});
567-
return studyData;
568-
},
569-
570-
serialize: function(clean = true) {
571-
let jsonObject = {};
572-
const propertyKeys = this.self().getProperties();
573-
propertyKeys.forEach(key => {
574-
if (this.self().IgnoreSerializationProps.includes(key)) {
575-
return;
576-
}
577-
if (key === "workbench") {
578-
jsonObject[key] = this.getWorkbench().serialize(clean);
579-
return;
580-
}
581-
if (key === "ui") {
582-
jsonObject[key] = this.getUi().serialize();
583-
return;
584-
}
585-
const value = this.get(key);
586-
if (value !== null) {
587-
// only put the value in the payload if there is a value
588-
jsonObject[key] = value;
589-
}
590-
});
591-
return jsonObject;
592-
},
593-
594-
patchStudy: function(fieldKey, value) {
580+
patchStudy: function(studyChanges) {
595581
return new Promise((resolve, reject) => {
596-
const patchData = {};
597-
patchData[fieldKey] = value;
598582
const params = {
599583
url: {
600584
"studyId": this.getUuid()
601585
},
602-
data: patchData
586+
data: studyChanges
603587
};
604588
osparc.data.Resources.fetch("studies", "patch", params)
605589
.then(() => {
606-
const upKey = qx.lang.String.firstUp(fieldKey);
607-
const setter = "set" + upKey;
608-
this[setter](value);
590+
Object.keys(studyChanges).forEach(fieldKey => {
591+
const upKey = qx.lang.String.firstUp(fieldKey);
592+
const setter = "set" + upKey;
593+
this[setter](studyChanges[fieldKey]);
594+
})
609595
// A bit hacky, but it's not sent back to the backend
610596
this.set({
611597
lastChangeDate: new Date()
612598
});
613-
const studyData = this.serializeStudyData();
599+
const studyData = this.serialize();
614600
resolve(studyData);
615601
})
616602
.catch(err => reject(err));
617603
});
618604
},
619605

620-
updateStudy: function(params, run = false) {
606+
/**
607+
* Call patch Study, but the changes were already applied on the frontend
608+
* @param studyDiffs {Object} Diff Object coming from the JsonDiffPatch lib. Use only the keys, not the changes.
609+
*/
610+
patchStudyDelayed: function(studyDiffs) {
611+
const promises = [];
612+
let workbenchDiffs = {};
613+
if ("workbench" in studyDiffs) {
614+
workbenchDiffs = studyDiffs["workbench"];
615+
promises.push(this.getWorkbench().patchWorkbenchDelayed(workbenchDiffs));
616+
delete studyDiffs["workbench"];
617+
}
618+
const fieldKeys = Object.keys(studyDiffs);
619+
if (fieldKeys.length) {
620+
const patchData = {};
621+
const params = {
622+
url: {
623+
"studyId": this.getUuid()
624+
},
625+
data: patchData
626+
};
627+
fieldKeys.forEach(fieldKey => {
628+
if (fieldKey === "ui") {
629+
patchData[fieldKey] = this.getUi().serialize();
630+
} else {
631+
const upKey = qx.lang.String.firstUp(fieldKey);
632+
const getter = "get" + upKey;
633+
patchData[fieldKey] = this[getter](studyDiffs[fieldKey]);
634+
}
635+
promises.push(osparc.data.Resources.fetch("studies", "patch", params))
636+
});
637+
}
638+
return Promise.all(promises)
639+
.then(() => {
640+
// A bit hacky, but it's not sent back to the backend
641+
this.set({
642+
lastChangeDate: new Date()
643+
});
644+
const studyData = this.serialize();
645+
return studyData;
646+
});
647+
},
648+
649+
updateStudy: function(params) {
621650
return new Promise((resolve, reject) => {
622651
osparc.data.Resources.fetch("studies", "put", {
623652
url: {
624-
"studyId": this.getUuid(),
625-
run
653+
"studyId": this.getUuid()
626654
},
627655
data: {
628656
...this.serialize(),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
4242
},
4343

4444
properties: {
45+
// stores position and/or marker
4546
workbench: {
4647
check: "Object",
4748
init: {},
@@ -103,6 +104,11 @@ qx.Class.define("osparc.data.model.StudyUI", {
103104
}
104105
},
105106

107+
removeNode: function(nodeId) {
108+
// remove it from slideshow
109+
this.getSlideshow().removeNode(nodeId);
110+
},
111+
106112
serialize: function() {
107113
const currentStudy = osparc.store.Store.getInstance().getCurrentStudy();
108114
let jsonObject = {};

0 commit comments

Comments
 (0)