Skip to content

Commit d361314

Browse files
authored
✨ Frontend: Select resources & Credits workflow (#4322)
1 parent cb607cd commit d361314

File tree

16 files changed

+1566
-13
lines changed

16 files changed

+1566
-13
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2023 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.component.resourceUsage.CreditsLeft", {
19+
extend: qx.ui.core.Widget,
20+
21+
construct: function() {
22+
this.base(arguments);
23+
24+
this._setLayout(new qx.ui.layout.HBox());
25+
26+
this.__buildLayout();
27+
},
28+
29+
statics: {
30+
createCreditsLeftInidcator: function(supportTap = false) {
31+
const store = osparc.store.Store.getInstance();
32+
33+
const progressBar = new qx.ui.indicator.ProgressBar().set({
34+
maximum: 1,
35+
width: 50,
36+
height: 20,
37+
allowGrowY: false,
38+
alignY:"middle"
39+
});
40+
const logBase = (n, base) => Math.log(n) / Math.log(base);
41+
store.bind("credits", progressBar, "value", {
42+
converter: val => {
43+
let normalized = logBase(val, 10000) + 0.01;
44+
normalized = Math.min(Math.max(normalized, 0), 1);
45+
return normalized;
46+
}
47+
});
48+
progressBar.bind("value", progressBar.getChildControl("progress"), "backgroundColor", {
49+
converter: val => {
50+
if (val > 0.4) {
51+
return "strong-main";
52+
} else if (val > 0.1) {
53+
return "warning-yellow";
54+
}
55+
return "danger-red";
56+
}
57+
});
58+
store.bind("credits", progressBar, "toolTipText", {
59+
converter: val => val + " credits left"
60+
});
61+
62+
if (supportTap) {
63+
progressBar.set({
64+
cursor: "pointer"
65+
});
66+
progressBar.addListener("tap", () => {
67+
const creditsWindow = osparc.desktop.credits.CreditsWindow.openWindow();
68+
creditsWindow.openBuyCredits();
69+
}, this);
70+
}
71+
72+
return progressBar;
73+
}
74+
},
75+
76+
members: {
77+
__buildLayout: function() {
78+
this.__addCredits();
79+
},
80+
81+
__addCredits: function() {
82+
const progressBar = this.self().createCreditsLeftInidcator(true);
83+
this._add(progressBar);
84+
},
85+
86+
__addButtons: function() {
87+
const buttonsLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
88+
89+
const buyCreditsBtn = new qx.ui.form.Button().set({
90+
label: this.tr("Buy credits")
91+
});
92+
buttonsLayout.add(buyCreditsBtn, {
93+
flex: 1
94+
});
95+
96+
const usageOverviewBtn = new qx.ui.form.Button().set({
97+
label: this.tr("Detailed")
98+
});
99+
usageOverviewBtn.addListener("execute", () => {
100+
const creditsWindow = osparc.desktop.credits.CreditsWindow.openWindow();
101+
creditsWindow.openUsageOverview();
102+
}, this);
103+
104+
buttonsLayout.add(usageOverviewBtn, {
105+
flex: 1
106+
});
107+
108+
this._add(buttonsLayout);
109+
}
110+
}
111+
});

0 commit comments

Comments
 (0)