Skip to content

Commit 46d5ff5

Browse files
committed
Study State and debt moved to StudyStore
1 parent 46f2575 commit 46d5ff5

File tree

8 files changed

+85
-86
lines changed

8 files changed

+85
-86
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: 4 additions & 4 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,
@@ -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
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ qx.Class.define("osparc.desktop.MainPage", {
318318
const currentStudy = store.getCurrentStudy();
319319
while (currentStudy.isLocked()) {
320320
await osparc.utils.Utils.sleep(1000);
321-
store.getStudyState(studyId);
321+
osparc.store.Study().getInstance().getStudyState(studyId);
322322
}
323323
this.__loadingPage.setMessages([]);
324324
this.__openSnapshot(studyId, snapshotId);
@@ -364,7 +364,7 @@ qx.Class.define("osparc.desktop.MainPage", {
364364
const currentStudy = store.getCurrentStudy();
365365
while (currentStudy.isLocked()) {
366366
await osparc.utils.Utils.sleep(1000);
367-
store.getStudyState(studyId);
367+
osparc.store.Study().getInstance().getStudyState(studyId);
368368
}
369369
this.__loadingPage.setMessages([]);
370370
this.__openIteration(iterationUuid);

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

Lines changed: 1 addition & 1 deletion
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 }) => {

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);

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ qx.Class.define("osparc.store.Study", {
1919
extend: qx.core.Object,
2020
type: "singleton",
2121

22+
events: {
23+
"studyStateChanged": "qx.event.type.Data",
24+
"studyDebtChanged": "qx.event.type.Data",
25+
},
26+
2227
members: {
2328
__nodeResources: null,
2429
__nodePricingUnit: null,
30+
__studiesInDebt: null,
2531

2632
getPage: function(params, options) {
2733
return osparc.data.Resources.fetch("studies", "getPage", params, options)
@@ -112,6 +118,73 @@ qx.Class.define("osparc.store.Study", {
112118
return osparc.data.Resources.fetch("studies", "updateMetadata", params);
113119
},
114120

121+
getStudyState: function(studyId) {
122+
osparc.data.Resources.fetch("studies", "state", {
123+
url: {
124+
"studyId": studyId
125+
}
126+
})
127+
.then(({state}) => {
128+
this.setStudyState(studyId, state);
129+
});
130+
},
131+
132+
setStudyState: function(studyId, state) {
133+
const studiesWStateCache = this.getStudies();
134+
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
135+
if (idx !== -1) {
136+
studiesWStateCache[idx]["state"] = state;
137+
}
138+
139+
const currentStudy = this.getCurrentStudy();
140+
if (currentStudy && currentStudy.getUuid() === studyId) {
141+
currentStudy.setState(state);
142+
}
143+
144+
this.fireDataEvent("studyStateChanged", {
145+
studyId,
146+
state,
147+
});
148+
},
149+
150+
setStudyDebt: function(studyId, debt) {
151+
// init object if it does not exist
152+
if (this.__studiesInDebt === null) {
153+
this.__studiesInDebt = {};
154+
}
155+
if (debt) {
156+
this.__studiesInDebt[studyId] = debt;
157+
} else {
158+
delete this.__studiesInDebt[studyId];
159+
}
160+
161+
const studiesWStateCache = this.getStudies();
162+
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
163+
if (idx !== -1) {
164+
if (debt) {
165+
studiesWStateCache[idx]["debt"] = debt;
166+
} else {
167+
delete studiesWStateCache[idx]["debt"];
168+
}
169+
}
170+
171+
this.fireDataEvent("studyDebtChanged", {
172+
studyId,
173+
debt,
174+
});
175+
},
176+
177+
getStudyDebt: function(studyId) {
178+
if (this.__studiesInDebt && studyId in this.__studiesInDebt) {
179+
return this.__studiesInDebt[studyId];
180+
}
181+
return null;
182+
},
183+
184+
isStudyInDebt: function(studyId) {
185+
return Boolean(this.getStudyDebt(studyId));
186+
},
187+
115188
trashStudy: function(studyId) {
116189
const params = {
117190
url: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ qx.Class.define("osparc.study.BillingSettings", {
259259

260260
__debtPayed: function() {
261261
delete this.__studyData["debt"];
262-
osparc.store.Store.getInstance().setStudyDebt(this.__studyData["uuid"], 0);
262+
osparc.store.Study.getInstance().setStudyDebt(this.__studyData["uuid"], 0);
263263
this.fireEvent("debtPayed");
264264
if (this.__debtMessage) {
265265
this._remove(this.__debtMessage);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ qx.Class.define("osparc.study.Utils", {
368368
},
369369

370370
isInDebt: function(studyData) {
371-
return osparc.store.Store.getInstance().isStudyInDebt(studyData["uuid"]);
371+
return osparc.store.Study.getInstance().isStudyInDebt(studyData["uuid"]);
372372
},
373373

374374
extractDebtFromError: function(studyId, err) {
@@ -385,7 +385,7 @@ qx.Class.define("osparc.study.Utils", {
385385
}
386386
if (debt) {
387387
// if get here, it means that the 402 was thrown due to the debt
388-
osparc.store.Store.getInstance().setStudyDebt(studyId, debt);
388+
osparc.store.Study.getInstance().setStudyDebt(studyId, debt);
389389
}
390390
return debt;
391391
},

0 commit comments

Comments
 (0)