Skip to content

Commit 81916b8

Browse files
committed
osparc.store.Study
1 parent 15d54a6 commit 81916b8

File tree

10 files changed

+128
-122
lines changed

10 files changed

+128
-122
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
17441744
},
17451745

17461746
__updateName: function(studyData, name) {
1747-
osparc.info.StudyUtils.patchStudyData(studyData, "name", name)
1747+
osparc.store.Study.patchStudyData(studyData, "name", name)
17481748
.then(() => this._updateStudyData(studyData))
17491749
.catch(err => {
17501750
console.error(err);
@@ -1754,7 +1754,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
17541754
},
17551755

17561756
__updateThumbnail: function(studyData, url) {
1757-
osparc.info.StudyUtils.patchStudyData(studyData, "thumbnail", url)
1757+
osparc.store.Study.patchStudyData(studyData, "thumbnail", url)
17581758
.then(() => this._updateStudyData(studyData))
17591759
.catch(err => {
17601760
console.error(err);
@@ -2139,7 +2139,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21392139
// remove me from collaborators
21402140
const myGid = osparc.auth.Data.getInstance().getGroupId();
21412141
delete arCopy[myGid];
2142-
return osparc.info.StudyUtils.patchStudyData(studyData, "accessRights", arCopy);
2142+
return osparc.store.Study.patchStudyData(studyData, "accessRights", arCopy);
21432143
},
21442144

21452145
__doDeleteStudy: function(studyData) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
335335
if (node["version"] !== latestCompatible["version"]) {
336336
patchData["version"] = latestCompatible["version"];
337337
}
338-
templatePromises.push(osparc.info.StudyUtils.patchNodeData(uniqueTemplateData, nodeId, patchData));
338+
templatePromises.push(osparc.store.Study.patchNodeData(uniqueTemplateData, nodeId, patchData));
339339
}
340340
}
341341
Promise.all(templatePromises)
@@ -450,7 +450,7 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
450450
const arCopy = osparc.utils.Utils.deepCloneObject(studyData["accessRights"]);
451451
// remove collaborator
452452
delete arCopy[myGid];
453-
operationPromise = osparc.info.StudyUtils.patchStudyData(studyData, "accessRights", arCopy);
453+
operationPromise = osparc.store.Study.patchStudyData(studyData, "accessRights", arCopy);
454454
} else {
455455
// delete study
456456
operationPromise = osparc.store.Store.getInstance().deleteStudy(studyData.uuid);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ qx.Class.define("osparc.desktop.MainPage", {
236236
}
237237
task.addListener("resultReceived", e => {
238238
const templateData = e.getData();
239-
osparc.info.StudyUtils.addCollaborators(templateData, data["accessRights"]);
239+
osparc.store.Study.addCollaborators(templateData, data["accessRights"]);
240240
});
241241
})
242242
.catch(errMsg => {

services/static-webserver/client/source/class/osparc/info/StudyUtils.js

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -403,114 +403,5 @@ qx.Class.define("osparc.info.StudyUtils", {
403403
box.setLayout(new qx.ui.layout.VBox(10));
404404
return box;
405405
},
406-
407-
patchStudyData: function(studyData, fieldKey, value) {
408-
if (osparc.data.model.Study.OwnPatch.includes(fieldKey)) {
409-
console.error(fieldKey, "has it's own PATCH path");
410-
return null;
411-
}
412-
413-
const patchData = {};
414-
patchData[fieldKey] = value;
415-
const params = {
416-
url: {
417-
"studyId": studyData["uuid"]
418-
},
419-
data: patchData
420-
};
421-
return osparc.data.Resources.fetch("studies", "patch", params)
422-
.then(() => {
423-
studyData[fieldKey] = value;
424-
// A bit hacky, but it's not sent back to the backend
425-
studyData["lastChangeDate"] = new Date().toISOString();
426-
});
427-
},
428-
429-
patchNodeData: function(studyData, nodeId, patchData) {
430-
const params = {
431-
url: {
432-
"studyId": studyData["uuid"],
433-
"nodeId": nodeId
434-
},
435-
data: patchData
436-
};
437-
return osparc.data.Resources.fetch("studies", "patchNode", params)
438-
.then(() => {
439-
Object.keys(patchData).forEach(key => {
440-
studyData["workbench"][nodeId][key] = patchData[key];
441-
});
442-
// A bit hacky, but it's not sent back to the backend
443-
studyData["lastChangeDate"] = new Date().toISOString();
444-
});
445-
},
446-
447-
addCollaborator: function(studyData, gid, permissions) {
448-
const params = {
449-
url: {
450-
"studyId": studyData["uuid"],
451-
"gId": gid
452-
},
453-
data: permissions
454-
};
455-
return osparc.data.Resources.fetch("studies", "postAccessRights", params)
456-
.then(() => {
457-
studyData["accessRights"][gid] = permissions;
458-
studyData["lastChangeDate"] = new Date().toISOString();
459-
})
460-
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
461-
},
462-
463-
addCollaborators: function(studyData, newCollaborators) {
464-
const promises = [];
465-
Object.keys(newCollaborators).forEach(gid => {
466-
const params = {
467-
url: {
468-
"studyId": studyData["uuid"],
469-
"gId": gid
470-
},
471-
data: newCollaborators[gid]
472-
};
473-
promises.push(osparc.data.Resources.fetch("studies", "postAccessRights", params));
474-
});
475-
return Promise.all(promises)
476-
.then(() => {
477-
Object.keys(newCollaborators).forEach(gid => {
478-
studyData["accessRights"][gid] = newCollaborators[gid];
479-
});
480-
studyData["lastChangeDate"] = new Date().toISOString();
481-
})
482-
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
483-
},
484-
485-
removeCollaborator: function(studyData, gid) {
486-
const params = {
487-
url: {
488-
"studyId": studyData["uuid"],
489-
"gId": gid
490-
}
491-
};
492-
return osparc.data.Resources.fetch("studies", "deleteAccessRights", params)
493-
.then(() => {
494-
delete studyData["accessRights"][gid];
495-
studyData["lastChangeDate"] = new Date().toISOString();
496-
})
497-
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
498-
},
499-
500-
updateCollaborator: function(studyData, gid, newPermissions) {
501-
const params = {
502-
url: {
503-
"studyId": studyData["uuid"],
504-
"gId": gid
505-
},
506-
data: newPermissions
507-
};
508-
return osparc.data.Resources.fetch("studies", "putAccessRights", params)
509-
.then(() => {
510-
studyData["accessRights"][gid] = newPermissions;
511-
studyData["lastChangeDate"] = new Date().toISOString();
512-
})
513-
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
514-
},
515406
}
516407
});

services/static-webserver/client/source/class/osparc/metadata/ClassifiersEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ qx.Class.define("osparc.metadata.ClassifiersEditor", {
146146

147147
const newClassifiers = this.__classifiersTree.getCheckedClassifierIDs();
148148
if (osparc.utils.Resources.isStudy(this.__resourceData) || osparc.utils.Resources.isTemplate(this.__resourceData)) {
149-
osparc.info.StudyUtils.patchStudyData(this.__resourceData, "classifiers", newClassifiers)
149+
osparc.store.Study.patchStudyData(this.__resourceData, "classifiers", newClassifiers)
150150
.then(() => {
151151
osparc.FlashMessenger.getInstance().logAs(this.tr("Classifiers successfully edited"));
152152
saveBtn.setFetching(false);

services/static-webserver/client/source/class/osparc/metadata/QualityEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ qx.Class.define("osparc.metadata.QualityEditor", {
472472
})
473473
.finally(() => btn.setFetching(false));
474474
} else {
475-
osparc.info.StudyUtils.patchStudyData(this.__resourceData, "quality", newQuality)
475+
osparc.store.Study.patchStudyData(this.__resourceData, "quality", newQuality)
476476
.then(() => {
477477
this.__initResourceData(this.__resourceData);
478478
this.fireDataEvent("updateQuality", this.__resourceData);

services/static-webserver/client/source/class/osparc/metadata/ServicesInStudy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ qx.Class.define("osparc.metadata.ServicesInStudy", {
7676
}
7777
this.setEnabled(false);
7878

79-
osparc.info.StudyUtils.patchNodeData(this._studyData, nodeId, patchData)
79+
osparc.store.Study.patchNodeData(this._studyData, nodeId, patchData)
8080
.then(() => {
8181
this.fireDataEvent("updateService", this._studyData);
8282
this._populateLayout();

services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
114114
gids.forEach(gid => {
115115
newCollaborators[gid] = this._resourceType === "study" ? this.self().getCollaboratorAccessRight() : this.self().getViewerAccessRight();
116116
});
117-
osparc.info.StudyUtils.addCollaborators(this._serializedDataCopy, newCollaborators)
117+
osparc.store.Study.addCollaborators(this._serializedDataCopy, newCollaborators)
118118
.then(() => {
119119
const text = resourceAlias + this.tr(" successfully shared");
120120
osparc.FlashMessenger.getInstance().logAs(text);
@@ -135,7 +135,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
135135
item.setEnabled(false);
136136
}
137137

138-
return osparc.info.StudyUtils.removeCollaborator(this._serializedDataCopy, collaborator["gid"])
138+
return osparc.store.Study.removeCollaborator(this._serializedDataCopy, collaborator["gid"])
139139
.then(() => {
140140
this.fireDataEvent("updateAccessRights", this._serializedDataCopy);
141141
osparc.FlashMessenger.getInstance().logAs(collaborator["name"] + this.tr(" successfully removed"));
@@ -155,7 +155,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
155155
__make: function(collaboratorGId, newAccessRights, successMsg, failureMsg, item) {
156156
item.setEnabled(false);
157157

158-
osparc.info.StudyUtils.updateCollaborator(this._serializedDataCopy, collaboratorGId, newAccessRights)
158+
osparc.store.Study.updateCollaborator(this._serializedDataCopy, collaboratorGId, newAccessRights)
159159
.then(() => {
160160
this.fireDataEvent("updateAccessRights", this._serializedDataCopy);
161161
osparc.FlashMessenger.getInstance().logAs(successMsg);
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.Study", {
19+
type: "static",
20+
21+
statics: {
22+
patchStudyData: function(studyData, fieldKey, value) {
23+
if (osparc.data.model.Study.OwnPatch.includes(fieldKey)) {
24+
console.error(fieldKey, "has it's own PATCH path");
25+
return null;
26+
}
27+
28+
const patchData = {};
29+
patchData[fieldKey] = value;
30+
const params = {
31+
url: {
32+
"studyId": studyData["uuid"]
33+
},
34+
data: patchData
35+
};
36+
return osparc.data.Resources.fetch("studies", "patch", params)
37+
.then(() => {
38+
studyData[fieldKey] = value;
39+
// A bit hacky, but it's not sent back to the backend
40+
studyData["lastChangeDate"] = new Date().toISOString();
41+
});
42+
},
43+
44+
patchNodeData: function(studyData, nodeId, patchData) {
45+
const params = {
46+
url: {
47+
"studyId": studyData["uuid"],
48+
"nodeId": nodeId
49+
},
50+
data: patchData
51+
};
52+
return osparc.data.Resources.fetch("studies", "patchNode", params)
53+
.then(() => {
54+
Object.keys(patchData).forEach(key => {
55+
studyData["workbench"][nodeId][key] = patchData[key];
56+
});
57+
// A bit hacky, but it's not sent back to the backend
58+
studyData["lastChangeDate"] = new Date().toISOString();
59+
});
60+
},
61+
62+
addCollaborators: function(studyData, newCollaborators) {
63+
const promises = [];
64+
Object.keys(newCollaborators).forEach(gid => {
65+
const params = {
66+
url: {
67+
"studyId": studyData["uuid"],
68+
"gId": gid
69+
},
70+
data: newCollaborators[gid]
71+
};
72+
promises.push(osparc.data.Resources.fetch("studies", "postAccessRights", params));
73+
});
74+
return Promise.all(promises)
75+
.then(() => {
76+
Object.keys(newCollaborators).forEach(gid => {
77+
studyData["accessRights"][gid] = newCollaborators[gid];
78+
});
79+
studyData["lastChangeDate"] = new Date().toISOString();
80+
})
81+
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
82+
},
83+
84+
removeCollaborator: function(studyData, gid) {
85+
const params = {
86+
url: {
87+
"studyId": studyData["uuid"],
88+
"gId": gid
89+
}
90+
};
91+
return osparc.data.Resources.fetch("studies", "deleteAccessRights", params)
92+
.then(() => {
93+
delete studyData["accessRights"][gid];
94+
studyData["lastChangeDate"] = new Date().toISOString();
95+
})
96+
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
97+
},
98+
99+
updateCollaborator: function(studyData, gid, newPermissions) {
100+
const params = {
101+
url: {
102+
"studyId": studyData["uuid"],
103+
"gId": gid
104+
},
105+
data: newPermissions
106+
};
107+
return osparc.data.Resources.fetch("studies", "putAccessRights", params)
108+
.then(() => {
109+
studyData["accessRights"][gid] = newPermissions;
110+
studyData["lastChangeDate"] = new Date().toISOString();
111+
})
112+
.catch(err => osparc.FlashMessenger.logAs(err.message, "ERROR"));
113+
},
114+
}
115+
});

services/static-webserver/client/source/class/osparc/study/StudyOptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ qx.Class.define("osparc.study.StudyOptions", {
9191
},
9292

9393
updateName: function(studyData, name) {
94-
return osparc.info.StudyUtils.patchStudyData(studyData, "name", name)
94+
return osparc.store.Study.patchStudyData(studyData, "name", name)
9595
.catch(err => {
9696
console.error(err);
9797
const msg = err.message || qx.locale.Manager.tr("Something went wrong Renaming");

0 commit comments

Comments
 (0)