Skip to content

Commit

Permalink
wiring debt
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Jan 20, 2025
1 parent b6567ef commit 1a917c9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,26 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
this.resetSelection();
this.setMultiSelection(false);
});
osparc.store.Store.getInstance().addListener("changeTags", () => {

const store = osparc.store.Store.getInstance();
store.addListener("changeTags", () => {
this.invalidateStudies();
this.__reloadStudies();
}, this);
store.addListener("studyStateChanged", e => {
const {
studyId,
state,
} = e.getData();
this.__studyStateChanged(studyId, state);
});
store.addListener("studyDebtChanged", e => {
const {
studyId,
debt,
} = e.getData();
this.__studyDebtChanged(studyId, debt);
});

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

__studyStateReceived: function(studyId, state, errors) {
osparc.store.Store.getInstance().setStudyState(studyId, state);
if (errors && errors.length) {
console.error(errors);
}
},

__studyStateChanged: function(studyId, state) {
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
if (idx > -1) {
this._resourcesList[idx]["state"] = state;
Expand All @@ -1428,8 +1450,17 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
if (studyItem) {
studyItem.setState(state);
}
if (errors && errors.length) {
console.error(errors);
},

__studyDebtChanged: function(studyId, debt) {
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
if (idx > -1) {
this._resourcesList[idx]["debt"] = debt;
}
const studyItem = this._resourcesContainer.getCards().find(card => osparc.dashboard.ResourceBrowserBase.isCardButtonItem(card) && card.getUuid() === studyId);
if (studyItem) {
// OM: here
studyItem.setDebt(debt);
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ qx.Class.define("osparc.data.model.Study", {
event: "changePipelineRunning"
},

inDebt: {
debt: {
check: "Number",
nullable: true,
init: 0,
event: "changeInDebt"
event: "changeDebt"
},

readOnly: {
Expand Down Expand Up @@ -240,7 +240,7 @@ qx.Class.define("osparc.data.model.Study", {
"permalink",
"state",
"pipelineRunning",
"inDebt",
"debt",
"readOnly",
"trashedAt",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
msg = err["message"];
const debt = err["debtAmount"];
msg += "<br>" + debt + "$";
study.setInDebt(debt);
study.setDebt(debt);
osparc.store.Store.getInstance().setStudyDebt(study.getUuid(), debt);
} else if (err["status"] == 409) { // max_open_studies_per_user
msg = err["message"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ qx.Class.define("osparc.store.Store", {
},
},

events: {
"studyStateChanged": "qx.event.type.Data",
"studyDebtChanged": "qx.event.type.Data",
},

members: {
// fetch resources that do not require log in
preloadCalls: async function() {
Expand Down Expand Up @@ -422,19 +427,30 @@ qx.Class.define("osparc.store.Store", {
if (currentStudy && currentStudy.getUuid() === studyId) {
currentStudy.setState(state);
}

this.fireDataEvent("studyStateChanged", {
studyId,
state,
});
},

setStudyDebt: function(studyId, debt) {
const studiesWStateCache = this.getStudies();
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
if (idx !== -1) {
studiesWStateCache[idx]["inDebt"] = debt;
studiesWStateCache[idx]["debt"] = debt;
}

const currentStudy = this.getCurrentStudy();
if (currentStudy && currentStudy.getUuid() === studyId) {
currentStudy.setInDebt(debt);
currentStudy.setDebt(debt);
}


this.fireDataEvent("studyDebtChanged", {
studyId,
debt,
});
},

setTemplateState: function(templateId, state) {
Expand Down

0 comments on commit 1a917c9

Please sign in to comment.