Skip to content

Commit 83c06b5

Browse files
authored
♻️🎨 [Frontend] Study Store II (#8090)
1 parent 2bdc986 commit 83c06b5

File tree

13 files changed

+204
-189
lines changed

13 files changed

+204
-189
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
6060
case "function":
6161
// when getting the latest study data, the debt information was lost
6262
if (osparc.study.Utils.isInDebt(this.__resourceData)) {
63-
const mainStore = osparc.store.Store.getInstance();
64-
this.__resourceData["debt"] = mainStore.getStudyDebt(this.__resourceData["uuid"]);
63+
const studyStore = osparc.store.Study.getInstance();
64+
this.__resourceData["debt"] = studyStore.getStudyDebt(this.__resourceData["uuid"]);
6565
}
6666
osparc.store.Services.getStudyServicesMetadata(latestResourceData)
6767
.finally(() => {

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -742,15 +742,15 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
742742
this.__reloadStudies();
743743
}, this);
744744

745-
const store = osparc.store.Store.getInstance();
746-
store.addListener("studyStateChanged", e => {
745+
const studyStore = osparc.store.Study.getInstance();
746+
studyStore.addListener("studyStateChanged", e => {
747747
const {
748748
studyId,
749749
state,
750750
} = e.getData();
751751
this.__studyStateChanged(studyId, state);
752752
});
753-
store.addListener("studyDebtChanged", e => {
753+
studyStore.addListener("studyDebtChanged", e => {
754754
const {
755755
studyId,
756756
debt,
@@ -924,7 +924,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
924924
},
925925

926926
invalidateStudies: function() {
927-
osparc.store.Store.getInstance().invalidate("studies");
927+
osparc.store.Study.getInstance().invalidateStudies();
928928
this.__resetStudiesList();
929929
if (this._resourcesContainer.getFlatList()) {
930930
this._resourcesContainer.getFlatList().nextRequest = null;
@@ -1506,7 +1506,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
15061506
// LAYOUT //
15071507

15081508
__studyStateReceived: function(studyId, state, errors) {
1509-
osparc.store.Store.getInstance().setStudyState(studyId, state);
1509+
osparc.store.Study.getInstance().setStudyState(studyId, state);
15101510
if (errors && errors.length) {
15111511
console.error(errors);
15121512
}
@@ -1542,10 +1542,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
15421542
minStudyData["workspaceId"] = this.getCurrentWorkspaceId();
15431543
minStudyData["folderId"] = this.getCurrentFolderId();
15441544
this._showLoadingPage(this.tr("Creating ") + (minStudyData.name || osparc.product.Utils.getStudyAlias()));
1545-
const params = {
1546-
data: minStudyData
1547-
};
1548-
osparc.study.Utils.createStudyAndPoll(params)
1545+
osparc.study.Utils.createStudyAndPoll(minStudyData)
15491546
.then(studyData => this.__startStudyAfterCreating(studyData["uuid"]))
15501547
.catch(err => {
15511548
this._hideLoadingPage();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ qx.Class.define("osparc.data.Resources", {
149149
method: "GET",
150150
url: statics.API + "/projects:search?filters={%22trashed%22:%22true%22}&offset={offset}&limit={limit}&order_by={orderBy}&type=user"
151151
},
152-
postToTemplate: {
153-
method: "POST",
154-
url: statics.API + "/projects?from_study={study_id}&as_template=true&copy_data={copy_data}&hidden={hidden}"
155-
},
156152
open: {
157153
method: "POST",
158154
url: statics.API + "/projects/{studyId}:open"
@@ -620,6 +616,10 @@ qx.Class.define("osparc.data.Resources", {
620616
method: "GET",
621617
url: statics.API + "/projects:search?type=template&offset={offset}&limit={limit}&order_by={orderBy}&template_type={templateType}&text={text}"
622618
},
619+
postToTemplate: {
620+
method: "POST",
621+
url: statics.API + "/projects?from_study={study_id}&as_template=true&copy_data={copy_data}&hidden={hidden}"
622+
},
623623
}
624624
},
625625
/*

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -587,21 +587,14 @@ qx.Class.define("osparc.data.model.Study", {
587587
if ("disableServiceAutoStart" in this.getDev()) {
588588
return this.getDev()["disableServiceAutoStart"];
589589
}
590-
return null;
590+
return false;
591591
},
592592

593593
openStudy: function() {
594-
const params = {
595-
url: {
596-
"studyId": this.getUuid()
597-
},
598-
data: osparc.utils.Utils.getClientSessionID()
599-
};
600-
if (this.getDisableServiceAutoStart() !== null) {
601-
params["url"]["disableServiceAutoStart"] = this.getDisableServiceAutoStart();
602-
return osparc.data.Resources.fetch("studies", "openDisableAutoStart", params);
594+
if (this.getDisableServiceAutoStart()) {
595+
return osparc.store.Study.getInstance().openStudy(this.getUuid(), false);
603596
}
604-
return osparc.data.Resources.fetch("studies", "open", params);
597+
return osparc.store.Study.getInstance().openStudy(this.getUuid());
605598
},
606599

607600
stopStudy: function() {

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,13 @@ qx.Class.define("osparc.desktop.MainPage", {
236236
const studyId = data["studyData"].uuid;
237237
const studyName = data["studyData"].name;
238238
const copyData = data["copyData"];
239+
const hidden = false;
239240
const templateAccessRights = data["accessRights"];
240241
const templateType = data["templateType"];
241242

242-
const params = {
243-
url: {
244-
"study_id": studyId,
245-
"copy_data": copyData,
246-
"hidden": false,
247-
},
248-
};
249-
const options = {
250-
pollTask: true
251-
};
252-
const fetchPromise = osparc.data.Resources.fetch("studies", "postToTemplate", params, options);
243+
const pollPromise = osparc.store.Templates.createTemplate(studyId, copyData, hidden);
253244
const pollTasks = osparc.store.PollTasks.getInstance();
254-
pollTasks.createPollingTask(fetchPromise)
245+
pollTasks.createPollingTask(pollPromise)
255246
.then(task => {
256247
const tutorialBrowser = this.__dashboard.getTutorialBrowser();
257248
if (tutorialBrowser && templateType === osparc.data.model.StudyUI.TUTORIAL_TYPE) {
@@ -318,7 +309,7 @@ qx.Class.define("osparc.desktop.MainPage", {
318309
const currentStudy = store.getCurrentStudy();
319310
while (currentStudy.isLocked()) {
320311
await osparc.utils.Utils.sleep(1000);
321-
store.getStudyState(studyId);
312+
osparc.store.Study.getInstance().getStudyState(studyId);
322313
}
323314
this.__loadingPage.setMessages([]);
324315
this.__openSnapshot(studyId, snapshotId);
@@ -364,7 +355,7 @@ qx.Class.define("osparc.desktop.MainPage", {
364355
const currentStudy = store.getCurrentStudy();
365356
while (currentStudy.isLocked()) {
366357
await osparc.utils.Utils.sleep(1000);
367-
store.getStudyState(studyId);
358+
osparc.store.Study.getInstance().getStudyState(studyId);
368359
}
369360
this.__loadingPage.setMessages([]);
370361
this.__openIteration(iterationUuid);

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
628628
/* If no projectStateUpdated comes in 60 seconds, client must
629629
check state of pipeline and update button accordingly. */
630630
const timer = setTimeout(() => {
631-
osparc.store.Store.getInstance().getStudyState(pipelineId);
631+
osparc.store.Study.getInstance().getStudyState(pipelineId);
632632
}, 60000);
633633
const socket = osparc.wrapper.WebSocket.getInstance();
634634
socket.getSocket().once("projectStateUpdated", ({ "project_uuid": projectUuid }) => {
@@ -928,13 +928,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
928928
},
929929

930930
__closeStudy: function() {
931-
const params = {
932-
url: {
933-
"studyId": this.getStudy().getUuid()
934-
},
935-
data: osparc.utils.Utils.getClientSessionID()
936-
};
937-
osparc.data.Resources.fetch("studies", "close", params)
931+
osparc.store.Study.getInstance().closeStudy(this.getStudy().getUuid())
938932
.catch(err => console.error(err));
939933
},
940934

services/static-webserver/client/source/class/osparc/store/Store.js

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,7 @@ qx.Class.define("osparc.store.Store", {
249249
},
250250
},
251251

252-
events: {
253-
"studyStateChanged": "qx.event.type.Data",
254-
"studyDebtChanged": "qx.event.type.Data",
255-
},
256-
257252
members: {
258-
__studiesInDebt: null,
259-
260253
// fetch resources that do not require log in
261254
preloadCalls: async function() {
262255
await osparc.data.Resources.get("config");
@@ -436,73 +429,6 @@ qx.Class.define("osparc.store.Store", {
436429
return null;
437430
},
438431

439-
getStudyState: function(studyId) {
440-
osparc.data.Resources.fetch("studies", "state", {
441-
url: {
442-
"studyId": studyId
443-
}
444-
})
445-
.then(({state}) => {
446-
this.setStudyState(studyId, state);
447-
});
448-
},
449-
450-
setStudyState: function(studyId, state) {
451-
const studiesWStateCache = this.getStudies();
452-
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
453-
if (idx !== -1) {
454-
studiesWStateCache[idx]["state"] = state;
455-
}
456-
457-
const currentStudy = this.getCurrentStudy();
458-
if (currentStudy && currentStudy.getUuid() === studyId) {
459-
currentStudy.setState(state);
460-
}
461-
462-
this.fireDataEvent("studyStateChanged", {
463-
studyId,
464-
state,
465-
});
466-
},
467-
468-
setStudyDebt: function(studyId, debt) {
469-
// init object if it does not exist
470-
if (this.__studiesInDebt === null) {
471-
this.__studiesInDebt = {};
472-
}
473-
if (debt) {
474-
this.__studiesInDebt[studyId] = debt;
475-
} else {
476-
delete this.__studiesInDebt[studyId];
477-
}
478-
479-
const studiesWStateCache = this.getStudies();
480-
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
481-
if (idx !== -1) {
482-
if (debt) {
483-
studiesWStateCache[idx]["debt"] = debt;
484-
} else {
485-
delete studiesWStateCache[idx]["debt"];
486-
}
487-
}
488-
489-
this.fireDataEvent("studyDebtChanged", {
490-
studyId,
491-
debt,
492-
});
493-
},
494-
495-
getStudyDebt: function(studyId) {
496-
if (this.__studiesInDebt && studyId in this.__studiesInDebt) {
497-
return this.__studiesInDebt[studyId];
498-
}
499-
return null;
500-
},
501-
502-
isStudyInDebt: function(studyId) {
503-
return Boolean(this.getStudyDebt(studyId));
504-
},
505-
506432
reloadCreditPrice: function() {
507433
const store = osparc.store.Store.getInstance();
508434
store.setCreditPrice(null);

0 commit comments

Comments
 (0)