Skip to content

Commit 6acc97b

Browse files
authored
♻️🎨 [Frontend] Study Store (#8087)
1 parent 3e05de4 commit 6acc97b

32 files changed

+267
-339
lines changed

services/static-webserver/client/source/class/osparc/conversation/AddMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ qx.Class.define("osparc.conversation.AddMessage", {
193193
const newCollaborators = {
194194
[userGid]: osparc.data.Roles.STUDY["write"].accessRights
195195
};
196-
osparc.store.Study.addCollaborators(this.__studyData, newCollaborators)
196+
osparc.store.Study.getInstance().addCollaborators(this.__studyData, newCollaborators)
197197
.then(() => {
198198
this.__addNotify(userGid);
199199
const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators()

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
121121

122122
const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
123123
if (walletsEnabled) {
124-
const params = {
125-
url: {
126-
studyId
127-
}
128-
};
129-
osparc.data.Resources.fetch("studies", "getWallet", params)
124+
osparc.store.Study.getInstance().getWallet(studyId)
130125
.then(wallet => {
131126
if (
132127
isStudyCreation ||
@@ -164,8 +159,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
164159
} else {
165160
openStudy();
166161
}
167-
})
168-
.catch(err => osparc.FlashMessenger.logError(err));
162+
});
169163
} else {
170164
openStudy();
171165
}
@@ -671,10 +665,10 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
671665
const arCopy = osparc.utils.Utils.deepCloneObject(templateData["accessRights"]);
672666
// remove collaborator
673667
delete arCopy[myGid];
674-
operationPromise = osparc.store.Study.patchStudyData(templateData, "accessRights", arCopy);
668+
operationPromise = osparc.store.Study.getInstance().patchStudyData(templateData, "accessRights", arCopy);
675669
} else {
676670
// delete study
677-
operationPromise = osparc.store.Store.getInstance().deleteStudy(templateData.uuid);
671+
operationPromise = osparc.store.Study.getInstance().deleteStudy(templateData.uuid);
678672
}
679673
operationPromise
680674
.then(() => this.__removeFromTemplateList(templateData.uuid))
@@ -754,12 +748,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
754748
};
755749
const cancelCB = () => {
756750
this._hideLoadingPage();
757-
const params = {
758-
url: {
759-
studyId
760-
}
761-
};
762-
osparc.data.Resources.fetch("studies", "delete", params);
751+
osparc.store.Study.getInstance().deleteStudy(studyId);
763752
};
764753

765754
const promises = [];
@@ -788,7 +777,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
788777
const nodeId = nodesIdsListed[idx];
789778
const pricingPlanId = nodePricingUnits.getPricingPlanId();
790779
const selectedUnit = nodePricingUnits.getPricingUnits().getSelectedUnit();
791-
promises.push(osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedUnit));
780+
promises.push(osparc.store.Study.getInstance().updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedUnit));
792781
}
793782
});
794783

@@ -811,12 +800,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
811800
const openCB = () => this._hideLoadingPage();
812801
const cancelCB = () => {
813802
this._hideLoadingPage();
814-
const params = {
815-
url: {
816-
studyId
817-
}
818-
};
819-
osparc.data.Resources.fetch("studies", "delete", params);
803+
osparc.store.Study.getInstance().deleteStudy(studyId);
820804
};
821805
const isStudyCreation = true;
822806
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
@@ -841,12 +825,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
841825
const openCB = () => this._hideLoadingPage();
842826
const cancelCB = () => {
843827
this._hideLoadingPage();
844-
const params = {
845-
url: {
846-
studyId
847-
}
848-
};
849-
osparc.data.Resources.fetch("studies", "delete", params);
828+
osparc.store.Study.getInstance().deleteStudy(studyId);
850829
};
851830
const isStudyCreation = true;
852831
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserFilter", {
247247
}
248248
};
249249
Promise.all([
250-
osparc.data.Resources.fetch("studies", "getPageTrashed", studiesParams),
250+
osparc.store.Study.getInstance().getPageTrashed(studiesParams),
251251
osparc.data.Resources.fetch("folders", "getPageTrashed", foldersParams),
252252
osparc.data.Resources.fetch("workspaces", "getPageTrashed", workspacesParams),
253253
])

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
3030
case "template":
3131
case "tutorial":
3232
case "hypertool": {
33-
const params = {
34-
url: {
35-
"studyId": resourceData["uuid"]
36-
}
37-
};
38-
latestPromise = osparc.data.Resources.fetch("studies", "getOne", params);
33+
latestPromise = osparc.store.Study.getInstance().getOne(resourceData["uuid"]);
3934
break;
4035
}
4136
case "function": {
@@ -231,13 +226,8 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
231226
return;
232227
}
233228
openButton.setFetching(true);
234-
const params = {
235-
url: {
236-
"studyId": this.__resourceData["uuid"]
237-
}
238-
};
239229
Promise.all([
240-
osparc.data.Resources.fetch("studies", "getOne", params),
230+
osparc.store.Study.getInstance().getOne(this.__resourceData["uuid"]),
241231
osparc.store.Services.getStudyServices(this.__resourceData["uuid"]),
242232
])
243233
.then(values => {

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

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
144144
},
145145

146146
__getActiveStudy: function() {
147-
const params = {
148-
url: {
149-
tabId: osparc.utils.Utils.getClientSessionID()
150-
}
151-
};
152-
return osparc.data.Resources.fetch("studies", "getActive", params)
147+
return osparc.store.Study.getInstance().getActive(osparc.utils.Utils.getClientSessionID())
153148
.then(studyData => {
154149
if (studyData) {
155150
osparc.store.Store.getInstance().setCurrentStudyId(studyData["uuid"]);
@@ -406,12 +401,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
406401
const delay = 2000;
407402
const studyId = study["uuid"];
408403
setTimeout(() => {
409-
const params = {
410-
url: {
411-
studyId
412-
}
413-
};
414-
osparc.data.Resources.fetch("studies", "getOne", params)
404+
osparc.store.Study.getInstance().getOne(studyId)
415405
.then(studyData => {
416406
this.__studyStateReceived(study["uuid"], studyData["state"]);
417407
});
@@ -911,18 +901,18 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
911901
let request = null;
912902
switch (this.getCurrentContext()) {
913903
case osparc.dashboard.StudyBrowser.CONTEXT.PROJECTS:
914-
request = osparc.data.Resources.fetch("studies", "getPage", params, options);
904+
request = osparc.store.Study.getInstance().getPage(params, options);
915905
break;
916906
case osparc.dashboard.StudyBrowser.CONTEXT.TEMPLATES:
917907
case osparc.dashboard.StudyBrowser.CONTEXT.PUBLIC_TEMPLATES:
918908
// The distinction is done in the frontend
919909
request = osparc.store.Templates.fetchTemplatesPaginated(params, options);
920910
break;
921911
case osparc.dashboard.StudyBrowser.CONTEXT.TRASH:
922-
request = osparc.data.Resources.fetch("studies", "getPageTrashed", params, options);
912+
request = osparc.store.Study.getInstance().getPageTrashed(params, options);
923913
break;
924914
case osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_PROJECTS:
925-
request = osparc.data.Resources.fetch("studies", "getPageSearch", params, options);
915+
request = osparc.store.Study.getInstance().getPageSearch(params, options);
926916
break;
927917
case osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_TEMPLATES:
928918
case osparc.dashboard.StudyBrowser.CONTEXT.SEARCH_PUBLIC_TEMPLATES:
@@ -1600,12 +1590,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
16001590
const openCB = () => this._hideLoadingPage();
16011591
const cancelCB = () => {
16021592
this._hideLoadingPage();
1603-
const params = {
1604-
url: {
1605-
studyId
1606-
}
1607-
};
1608-
osparc.data.Resources.fetch("studies", "delete", params);
1593+
osparc.store.Study.getInstance().deleteStudy(studyId);
16091594
};
16101595
const isStudyCreation = true;
16111596
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
@@ -1794,13 +1779,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
17941779
},
17951780

17961781
__updateName: function(studyData, name) {
1797-
osparc.store.Study.patchStudyData(studyData, "name", name)
1782+
osparc.store.Study.getInstance().patchStudyData(studyData, "name", name)
17981783
.then(() => this._updateStudyData(studyData))
17991784
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Something went wrong while renaming")));
18001785
},
18011786

18021787
__updateThumbnail: function(studyData, url) {
1803-
osparc.store.Study.patchStudyData(studyData, "thumbnail", url)
1788+
osparc.store.Study.getInstance().patchStudyData(studyData, "thumbnail", url)
18041789
.then(() => this._updateStudyData(studyData))
18051790
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Something went wrong while updating the thumbnail")));
18061791
},
@@ -1867,13 +1852,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
18671852
// resolve right away
18681853
return new Promise(resolve => resolve());
18691854
}
1870-
const params = {
1871-
url: {
1872-
studyId: studyData["uuid"],
1873-
workspaceId: destWorkspaceId,
1874-
}
1875-
};
1876-
return osparc.data.Resources.fetch("studies", "moveToWorkspace", params)
1855+
return osparc.store.Study.getInstance().moveStudyToWorkspace(studyData["uuid"], destWorkspaceId)
18771856
.then(() => studyData["workspaceId"] = destWorkspaceId);
18781857
},
18791858

@@ -1882,13 +1861,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
18821861
// resolve right away
18831862
return new Promise(resolve => resolve());
18841863
}
1885-
const params = {
1886-
url: {
1887-
studyId: studyData["uuid"],
1888-
folderId: destFolderId,
1889-
}
1890-
};
1891-
return osparc.data.Resources.fetch("studies", "moveToFolder", params)
1864+
return osparc.store.Study.getInstance().moveStudyToFolder(studyData["uuid"], destFolderId)
18921865
.then(() => studyData["folderId"] = destFolderId);
18931866
},
18941867

@@ -1949,7 +1922,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
19491922
__updateUIMode: function(studyData, uiMode) {
19501923
const studyUI = osparc.utils.Utils.deepCloneObject(studyData["ui"]);
19511924
studyUI["mode"] = uiMode;
1952-
return osparc.store.Study.patchStudyData(studyData, "ui", studyUI)
1925+
return osparc.store.Study.getInstance().patchStudyData(studyData, "ui", studyUI)
19531926
.then(() => this._updateStudyData(studyData))
19541927
},
19551928

@@ -2114,12 +2087,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21142087
importTaskUI.setSubtitle(processingLabel);
21152088
importingStudyCard.getChildControl("progress-bar").exclude();
21162089
const data = JSON.parse(req.responseText);
2117-
const params = {
2118-
url: {
2119-
"studyId": data["data"]["uuid"]
2120-
}
2121-
};
2122-
osparc.data.Resources.fetch("studies", "getOne", params)
2090+
osparc.store.Study.getInstance().getOne(data["data"]["uuid"])
21232091
.then(studyData => this._updateStudyData(studyData))
21242092
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Something went wrong while fetching the study")))
21252093
.finally(() => {
@@ -2148,7 +2116,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21482116
},
21492117

21502118
__untrashStudy: function(studyData) {
2151-
osparc.store.Store.getInstance().untrashStudy(studyData.uuid)
2119+
osparc.store.Study.getInstance().untrashStudy(studyData.uuid)
21522120
.then(() => {
21532121
this.__removeFromStudyList(studyData.uuid);
21542122
const msg = this.tr("Successfully restored");
@@ -2160,7 +2128,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21602128
},
21612129

21622130
__trashStudy: function(studyData) {
2163-
osparc.store.Store.getInstance().trashStudy(studyData.uuid)
2131+
osparc.store.Study.getInstance().trashStudy(studyData.uuid)
21642132
.then(() => {
21652133
this.__removeFromStudyList(studyData.uuid);
21662134
const msg = this.tr("Successfully deleted");
@@ -2188,7 +2156,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21882156
// remove me from collaborators
21892157
const myGid = osparc.auth.Data.getInstance().getGroupId();
21902158
delete arCopy[myGid];
2191-
return osparc.store.Study.patchStudyData(studyData, "accessRights", arCopy);
2159+
return osparc.store.Study.getInstance().patchStudyData(studyData, "accessRights", arCopy);
21922160
},
21932161

21942162
__doDeleteStudy: function(studyData) {
@@ -2197,7 +2165,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
21972165
operationPromise = this.__removeMeFromCollaborators(studyData);
21982166
} else {
21992167
// delete study
2200-
operationPromise = osparc.store.Store.getInstance().deleteStudy(studyData.uuid);
2168+
operationPromise = osparc.store.Study.getInstance().deleteStudy(studyData.uuid);
22012169
}
22022170
operationPromise
22032171
.then(() => this.__removeFromStudyList(studyData.uuid))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ qx.Class.define("osparc.dashboard.TutorialBrowser", {
218218
if (node["version"] !== latestCompatible["version"]) {
219219
patchData["version"] = latestCompatible["version"];
220220
}
221-
templatePromises.push(osparc.store.Study.patchNodeData(uniqueTemplateData, nodeId, patchData));
221+
templatePromises.push(osparc.store.Study.getInstance().patchNodeData(uniqueTemplateData, nodeId, patchData));
222222
}
223223
}
224224
Promise.all(templatePromises)

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,7 @@ qx.Class.define("osparc.data.model.Study", {
680680
}
681681

682682
return new Promise((resolve, reject) => {
683-
const params = {
684-
url: {
685-
"studyId": this.getUuid()
686-
},
687-
data: studyChanges
688-
};
689-
osparc.data.Resources.fetch("studies", "patch", params)
683+
osparc.store.Study.getInstance().patchStudy(this.getUuid(), studyChanges)
690684
.then(() => {
691685
Object.keys(studyChanges).forEach(fieldKey => {
692686
const upKey = qx.lang.String.firstUp(fieldKey);
@@ -717,22 +711,17 @@ qx.Class.define("osparc.data.model.Study", {
717711
}
718712
const fieldKeys = Object.keys(studyDiffs);
719713
if (fieldKeys.length) {
720-
const patchData = {};
721-
const params = {
722-
url: {
723-
"studyId": this.getUuid()
724-
},
725-
data: patchData
726-
};
727714
fieldKeys.forEach(fieldKey => {
715+
// OM: can this be called all together?
716+
const patchData = {};
728717
if (fieldKey === "ui") {
729718
patchData[fieldKey] = this.getUi().serialize();
730719
} else {
731720
const upKey = qx.lang.String.firstUp(fieldKey);
732721
const getter = "get" + upKey;
733722
patchData[fieldKey] = this[getter](studyDiffs[fieldKey]);
734723
}
735-
promises.push(osparc.data.Resources.fetch("studies", "patch", params))
724+
promises.push(osparc.store.Study.getInstance().patchStudy(this.getUuid(), patchData))
736725
});
737726
}
738727
return Promise.all(promises)

0 commit comments

Comments
 (0)