Skip to content

Commit 1a917c9

Browse files
committed
wiring debt
1 parent b6567ef commit 1a917c9

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,26 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
732732
this.resetSelection();
733733
this.setMultiSelection(false);
734734
});
735-
osparc.store.Store.getInstance().addListener("changeTags", () => {
735+
736+
const store = osparc.store.Store.getInstance();
737+
store.addListener("changeTags", () => {
736738
this.invalidateStudies();
737739
this.__reloadStudies();
738740
}, this);
741+
store.addListener("studyStateChanged", e => {
742+
const {
743+
studyId,
744+
state,
745+
} = e.getData();
746+
this.__studyStateChanged(studyId, state);
747+
});
748+
store.addListener("studyDebtChanged", e => {
749+
const {
750+
studyId,
751+
debt,
752+
} = e.getData();
753+
this.__studyDebtChanged(studyId, debt);
754+
});
739755

740756
qx.event.message.Bus.subscribe("reloadStudies", () => {
741757
this.invalidateStudies();
@@ -1420,6 +1436,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
14201436

14211437
__studyStateReceived: function(studyId, state, errors) {
14221438
osparc.store.Store.getInstance().setStudyState(studyId, state);
1439+
if (errors && errors.length) {
1440+
console.error(errors);
1441+
}
1442+
},
1443+
1444+
__studyStateChanged: function(studyId, state) {
14231445
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
14241446
if (idx > -1) {
14251447
this._resourcesList[idx]["state"] = state;
@@ -1428,8 +1450,17 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
14281450
if (studyItem) {
14291451
studyItem.setState(state);
14301452
}
1431-
if (errors && errors.length) {
1432-
console.error(errors);
1453+
},
1454+
1455+
__studyDebtChanged: function(studyId, debt) {
1456+
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
1457+
if (idx > -1) {
1458+
this._resourcesList[idx]["debt"] = debt;
1459+
}
1460+
const studyItem = this._resourcesContainer.getCards().find(card => osparc.dashboard.ResourceBrowserBase.isCardButtonItem(card) && card.getUuid() === studyId);
1461+
if (studyItem) {
1462+
// OM: here
1463+
studyItem.setDebt(debt);
14331464
}
14341465
},
14351466

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ qx.Class.define("osparc.data.model.Study", {
206206
event: "changePipelineRunning"
207207
},
208208

209-
inDebt: {
209+
debt: {
210210
check: "Number",
211211
nullable: true,
212212
init: 0,
213-
event: "changeInDebt"
213+
event: "changeDebt"
214214
},
215215

216216
readOnly: {
@@ -240,7 +240,7 @@ qx.Class.define("osparc.data.model.Study", {
240240
"permalink",
241241
"state",
242242
"pipelineRunning",
243-
"inDebt",
243+
"debt",
244244
"readOnly",
245245
"trashedAt",
246246
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
188188
msg = err["message"];
189189
const debt = err["debtAmount"];
190190
msg += "<br>" + debt + "$";
191-
study.setInDebt(debt);
191+
study.setDebt(debt);
192192
osparc.store.Store.getInstance().setStudyDebt(study.getUuid(), debt);
193193
} else if (err["status"] == 409) { // max_open_studies_per_user
194194
msg = err["message"];

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ qx.Class.define("osparc.store.Store", {
228228
},
229229
},
230230

231+
events: {
232+
"studyStateChanged": "qx.event.type.Data",
233+
"studyDebtChanged": "qx.event.type.Data",
234+
},
235+
231236
members: {
232237
// fetch resources that do not require log in
233238
preloadCalls: async function() {
@@ -422,19 +427,30 @@ qx.Class.define("osparc.store.Store", {
422427
if (currentStudy && currentStudy.getUuid() === studyId) {
423428
currentStudy.setState(state);
424429
}
430+
431+
this.fireDataEvent("studyStateChanged", {
432+
studyId,
433+
state,
434+
});
425435
},
426436

427437
setStudyDebt: function(studyId, debt) {
428438
const studiesWStateCache = this.getStudies();
429439
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
430440
if (idx !== -1) {
431-
studiesWStateCache[idx]["inDebt"] = debt;
441+
studiesWStateCache[idx]["debt"] = debt;
432442
}
433443

434444
const currentStudy = this.getCurrentStudy();
435445
if (currentStudy && currentStudy.getUuid() === studyId) {
436-
currentStudy.setInDebt(debt);
446+
currentStudy.setDebt(debt);
437447
}
448+
449+
450+
this.fireDataEvent("studyDebtChanged", {
451+
studyId,
452+
debt,
453+
});
438454
},
439455

440456
setTemplateState: function(templateId, state) {

0 commit comments

Comments
 (0)