Skip to content

Commit

Permalink
✨ Billing settings in Home Page (ITISFoundation#4896)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Oct 21, 2023
1 parent 75b8098 commit 7813f7a
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,31 +310,49 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
return;
}

const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
if (walletsEnabled) {
const resourceSelector = new osparc.study.StudyOptions(studyId);
const win = osparc.study.StudyOptions.popUpInWindow(resourceSelector);
resourceSelector.addListener("startStudy", () => {
win.close();
if (openCB) {
openCB();
}
osparc.desktop.MainPageHandler.getInstance().startStudy(studyId);
});
resourceSelector.addListener("cancel", () => {
win.close();
if (cancelCB) {
cancelCB();
}
});
win.getChildControl("close-button").addListener("execute", () => {
cancelCB();
});
} else {
const openStudy = () => {
if (openCB) {
openCB();
}
osparc.desktop.MainPageHandler.getInstance().startStudy(studyId);
};

const walletsEnabled = osparc.desktop.credits.Utils.areWalletsEnabled();
if (walletsEnabled) {
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "getWallet", params)
.then(wallet => {
if (wallet === null || osparc.desktop.credits.Utils.getWallet(wallet["walletId"]) === null) {
// pop up study options only if it has no wallet assigned or user has no access to it
const resourceSelector = new osparc.study.StudyOptions(studyId);
const win = osparc.study.StudyOptions.popUpInWindow(resourceSelector);
resourceSelector.addListener("startStudy", () => {
win.close();
openStudy();
});
resourceSelector.addListener("cancel", () => {
win.close();
if (cancelCB) {
cancelCB();
}
});
win.getChildControl("close-button").addListener("execute", () => {
cancelCB();
});
} else {
openStudy();
}
})
.catch(err => {
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
});
} else {
openStudy();
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,16 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
// add Open service button
[
this.__getInfoPage,
this.__getCommentsPage,
this.__getBillingSettings,
this.__getServicesUpdatePage,
this.__getServicesBootOptionsPage,
this.__getDataPage,
this.__getCommentsPage,
this.__getPermissionsPage,
this.__getSaveAsTemplatePage,
this.__getTagsPage,
this.__getServicesUpdatePage,
this.__getServicesBootOptionsPage,
this.__getQualityPage,
this.__getClassifiersPage,
this.__getSaveAsTemplatePage
this.__getClassifiersPage
].forEach(pageCallee => {
if (pageCallee) {
const page = pageCallee.call(this);
Expand Down Expand Up @@ -333,6 +334,25 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
return page;
},

__getBillingSettings: function() {
const resourceData = this.__resourceData;
if (
!osparc.utils.Resources.isStudy(resourceData) ||
!osparc.desktop.credits.Utils.areWalletsEnabled()
) {
return null;
}

const id = "Billing";
const title = this.tr("Billing Settings");
const icon = "@FontAwesome5Solid/cogs";

const billingSettings = new osparc.study.BillingSettings(resourceData);

const page = this.self().createPage(title, billingSettings, icon, id);
return page;
},

__getCommentsPage: function() {
const resourceData = this.__resourceData;
if (osparc.utils.Resources.isService(resourceData)) {
Expand Down Expand Up @@ -498,7 +518,7 @@ qx.Class.define("osparc.dashboard.ResourceMoreOptions", {
const tagManager = new osparc.form.tag.TagManager(resourceData);
tagManager.addListener("updateTags", e => {
const updatedData = e.getData();
tagManager.setStudydata(updatedData);
tagManager.setStudyData(updatedData);
this.fireDataEvent("updateStudy", updatedData);
}, this);
const page = this.__tagsPage = this.self().createPage(title, tagManager, icon, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
osparc.desktop.WorkbenchView.decorateSplitter(this.getChildControl("splitter"));
osparc.desktop.WorkbenchView.decorateSlider(this.getChildControl("slider"));

this.__sidePanels = this.getChildControl("side-panels");
this.getChildControl("side-panels");
this.getChildControl("main-panel-tabs");
this.__workbenchPanel = new osparc.desktop.WorkbenchPanel();
this.__workbenchUI = this.__workbenchPanel.getMainView();
Expand All @@ -38,6 +38,7 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
},

statics: {
PRIMARY_COL_BG_COLOR: "background-main-2",
TAB_BUTTON_HEIGHT: 46,

decorateSplitter: function(splitter) {
Expand Down Expand Up @@ -93,11 +94,9 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
},

members: {
__sidePanels: null,
__nodesPage: null,
__studyTreeItem: null,
__nodesTree: null,
__filesTree: null,
__storagePage: null,
__studyOptionsPage: null,
__infoPage: null,
Expand Down Expand Up @@ -135,6 +134,8 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
minWidth: osparc.widget.CollapsibleViewLight.CARET_WIDTH,
width: Math.min(parseInt(window.innerWidth * 0.16), 240)
});
control.getChildControl("expand-button").setBackgroundColor(this.self().PRIMARY_COL_BG_COLOR);
control.getChildControl("collapse-button").setBackgroundColor(this.self().PRIMARY_COL_BG_COLOR);
const caretExpandedLayout = control.getChildControl("caret-expanded-layout");
caretExpandedLayout.addAt(this.__createCollapsibleViewSpacer(), 0);
const caretCollapsedLayout = control.getChildControl("caret-collapsed-layout");
Expand Down Expand Up @@ -195,13 +196,11 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
control = new qx.ui.tabview.TabView().set({
contentPadding: osparc.widget.CollapsibleViewLight.CARET_WIDTH + 2, // collapse bar + padding
contentPaddingRight: 2,
backgroundColor: this.self().PRIMARY_COL_BG_COLOR,
barPosition: "top"
});
const collapsibleViewLeft = this.getChildControl("collapsible-view-left");
collapsibleViewLeft.setContent(control);
control.setBackgroundColor("background-main-2");
collapsibleViewLeft.getChildControl("expand-button").setBackgroundColor("background-main-2");
collapsibleViewLeft.getChildControl("collapse-button").setBackgroundColor("background-main-2");
break;
}
case "side-panel-right-tabs": {
Expand Down Expand Up @@ -303,16 +302,11 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
},

__initPrimaryColumn: function() {
const primaryColumnBGColor = "background-main-2";
const study = this.getStudy();

const tabViewPrimary = this.getChildControl("side-panel-left-tabs");
this.__removePages(tabViewPrimary);
tabViewPrimary.setBackgroundColor(primaryColumnBGColor);
const collapsibleViewLeft = this.getChildControl("collapsible-view-left");
collapsibleViewLeft.getChildControl("expand-button").setBackgroundColor(primaryColumnBGColor);
collapsibleViewLeft.getChildControl("collapse-button").setBackgroundColor(primaryColumnBGColor);

tabViewPrimary.setBackgroundColor(this.self().PRIMARY_COL_BG_COLOR);

const topBar = tabViewPrimary.getChildControl("bar");
topBar.set({
Expand All @@ -323,20 +317,20 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
this.__addTopBarSpacer(topBar);

const homeAndNodesTree = new qx.ui.container.Composite(new qx.ui.layout.VBox(15)).set({
backgroundColor: primaryColumnBGColor
backgroundColor: "transparent"
});

const studyTreeItem = this.__studyTreeItem = new osparc.widget.StudyTitleOnlyTree().set({
alignY: "middle",
minHeight: 32,
maxHeight: 32,
backgroundColor: primaryColumnBGColor
backgroundColor: "transparent"
});
studyTreeItem.setStudy(study);
homeAndNodesTree.add(studyTreeItem);

const nodesTree = this.__nodesTree = new osparc.widget.NodesTree().set({
backgroundColor: primaryColumnBGColor,
backgroundColor: "transparent",
allowGrowY: true,
minHeight: 5
});
Expand All @@ -362,16 +356,16 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
});
homeAndNodesTree.add(addNewNodeBtn);

const nodesPage = this.__nodesPage = this.__createTabPage("@FontAwesome5Solid/list", this.tr("Nodes"), homeAndNodesTree, primaryColumnBGColor);
const nodesPage = this.__nodesPage = this.__createTabPage("@FontAwesome5Solid/list", this.tr("Nodes"), homeAndNodesTree, this.self().PRIMARY_COL_BG_COLOR);
tabViewPrimary.add(nodesPage);

const filesTree = this.__filesTree = new osparc.file.FilesTree().set({
backgroundColor: primaryColumnBGColor,
const filesTree = new osparc.file.FilesTree().set({
backgroundColor: "transparent",
dragMechanism: true,
hideRoot: true
});
filesTree.populateTree();
const storagePage = this.__storagePage = this.__createTabPage("@FontAwesome5Solid/database", this.tr("Storage"), filesTree, primaryColumnBGColor);
const storagePage = this.__storagePage = this.__createTabPage("@FontAwesome5Solid/database", this.tr("Storage"), filesTree, this.self().PRIMARY_COL_BG_COLOR);
tabViewPrimary.add(storagePage);

this.__addTopBarSpacer(topBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ qx.Class.define("osparc.desktop.credits.Utils", {
return parseInt(credits);
},

createWalletSelector: function(accessRight = "read", onlyActive = false, emptySelection = false) {
createWalletSelector: function(accessRight = "read", emptySelection = false) {
const store = osparc.store.Store.getInstance();

const walletSelector = new qx.ui.form.SelectBox();
Expand All @@ -67,9 +67,6 @@ qx.Class.define("osparc.desktop.credits.Utils", {
selectBox.add(sbItem);
}
wallets.forEach(wallet => {
if (onlyActive && wallet.getStatus() !== "ACTIVE") {
return;
}
const found = wallet.getMyAccessRights();
if (found && found[accessRight]) {
const sbItem = new qx.ui.form.ListItem(wallet.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ qx.Class.define("osparc.form.tag.TagManager", {
this.__renderLayout();
this.__attachEventHandlers();

this.setStudydata(studyData);
this.setStudyData(studyData);
},

events: {
Expand Down Expand Up @@ -109,7 +109,7 @@ qx.Class.define("osparc.form.tag.TagManager", {
this._add(buttons);
},

setStudydata: function(studyData) {
setStudyData: function(studyData) {
this.__studyData = studyData;
this.__resourceId = studyData["uuid"];
this.__selectedTags.removeAll();
Expand Down
Loading

0 comments on commit 7813f7a

Please sign in to comment.