Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
case "template":
case "tutorial":
case "hypertool":
// when getting the latest study data, the debt information was lost
if (osparc.study.Utils.isInDebt(this.__resourceData)) {
const mainStore = osparc.store.Store.getInstance();
this.__resourceData["debt"] = mainStore.getStudyDebt(this.__resourceData["uuid"]);
}
osparc.store.Services.getStudyServicesMetadata(latestResourceData)
.finally(() => {
this.__resourceModel = new osparc.data.model.Study(latestResourceData);
Expand Down Expand Up @@ -89,6 +94,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
"updateService": "qx.event.type.Data",
"updateHypertool": "qx.event.type.Data",
"publishTemplate": "qx.event.type.Data",
"closeWindow": "qx.event.type.Event",
},


Expand All @@ -107,6 +113,9 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
width: this.WIDTH,
height: this.HEIGHT,
});
resourceDetails.addListener("closeWindow", () => {
win.close();
});
return win;
},

Expand Down Expand Up @@ -479,6 +488,9 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
const enabled = osparc.study.Utils.canBeOpened(resourceData);
page.openButton.setEnabled(enabled);
})
billingSettings.addListener("closeWindow", () => {
this.fireEvent("closeWindow");
}, this);
const billingScroll = new qx.ui.container.Scroll(billingSettings);
page.addToContent(billingScroll);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
if ("status" in err && err["status"]) {
if (err["status"] == 402) {
msg = err["message"];
// The backend might have thrown a 402 because the wallet was negative
const match = msg.match(/last transaction of\s([-]?\d+(\.\d+)?)\sresulted/);
let debt = null;
if ("debtAmount" in err) {
// the study has some debt that needs to be paid
debt = err["debtAmount"];
} else if (match) {
// the study has some debt that needs to be paid
debt = parseFloat(match[1]); // Convert the captured string to a number
}
if (debt) {
// if get here, it means that the 402 was thrown due to the debt
osparc.store.Store.getInstance().setStudyDebt(study.getUuid(), debt);
}
osparc.study.Utils.extractDebtFromError(study.getUuid(), err);
} else if (err["status"] == 409) { // max_open_studies_per_user
msg = err["message"];
} else if (err["status"] == 423) { // Locked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ qx.Class.define("osparc.store.Store", {
},

members: {
__studiesInDebt: null,

// fetch resources that do not require log in
preloadCalls: async function() {
await osparc.data.Resources.get("config");
Expand Down Expand Up @@ -454,6 +456,16 @@ qx.Class.define("osparc.store.Store", {
},

setStudyDebt: function(studyId, debt) {
// init object if it does not exist
if (this.__studiesInDebt === null) {
this.__studiesInDebt = {};
}
if (debt) {
this.__studiesInDebt[studyId] = debt;
} else {
delete this.__studiesInDebt[studyId];
}

const studiesWStateCache = this.getStudies();
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
if (idx !== -1) {
Expand All @@ -470,6 +482,17 @@ qx.Class.define("osparc.store.Store", {
});
},

getStudyDebt: function(studyId) {
if (this.__studiesInDebt && studyId in this.__studiesInDebt) {
return this.__studiesInDebt[studyId];
}
return null;
},

isStudyInDebt: function(studyId) {
return Boolean(this.getStudyDebt(studyId));
},

trashStudy: function(studyId) {
const params = {
url: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ qx.Class.define("osparc.study.BillingSettings", {

events: {
"debtPayed": "qx.event.type.Event",
"closeWindow": "qx.event.type.Event",
},

members: {
Expand Down Expand Up @@ -286,7 +287,13 @@ qx.Class.define("osparc.study.BillingSettings", {
const msg = this.tr("Credit Account saved");
osparc.FlashMessenger.logAs(msg, "INFO");
})
.catch(err => osparc.FlashMessenger.logError(err))
.catch(err => {
if ("status" in err && err["status"] == 402) {
osparc.study.Utils.extractDebtFromError(this.__studyData["uuid"], err);
}
osparc.FlashMessenger.logError(err);
this.fireEvent("closeWindow");
})
.finally(() => {
creditAccountBox.setEnabled(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,26 @@ qx.Class.define("osparc.study.Utils", {
},

isInDebt: function(studyData) {
return Boolean("debt" in studyData && studyData["debt"] < 0);
return osparc.store.Store.getInstance().isStudyInDebt(studyData["uuid"]);
},

extractDebtFromError: function(studyId, err) {
const msg = err["message"];
// The backend might have thrown a 402 because the wallet was negative
const match = msg.match(/last transaction of\s([-]?\d+(\.\d+)?)\sresulted/);
let debt = null;
if ("debtAmount" in err) {
// the study has some debt that needs to be paid
debt = err["debtAmount"];
} else if (match) {
// the study has some debt that needs to be paid
debt = parseFloat(match[1]); // Convert the captured string to a number
}
if (debt) {
// if get here, it means that the 402 was thrown due to the debt
osparc.store.Store.getInstance().setStudyDebt(studyId, debt);
}
return debt;
},

getUiMode: function(studyData) {
Expand Down
Loading