Skip to content

Commit 8527559

Browse files
authored
🎨 [Frontend] Credits summary: Show time (#6356)
1 parent 7f5e97c commit 8527559

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ qx.Class.define("osparc.desktop.credits.CreditsIndicatorButton", {
8484
},
8585

8686
__handleOutsideEvent: function(event) {
87+
const offset = 30;
8788
if (
88-
!osparc.utils.Utils.isMouseOnElement(this.__creditsContainer, event) &&
89-
!osparc.utils.Utils.isMouseOnElement(this, event)
89+
!osparc.utils.Utils.isMouseOnElement(this.__creditsContainer, event, offset) &&
90+
!osparc.utils.Utils.isMouseOnElement(this, event, offset)
9091
) {
9192
this.__hideCreditsContainer();
9293
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,31 @@ qx.Class.define("osparc.desktop.credits.CreditsPerService", {
6161
this._removeAll();
6262
if (entries && entries.length) {
6363
let totalCredits = 0;
64-
entries.forEach(entry => totalCredits+= entry["osparc_credits"]);
64+
let totalHours = 0;
65+
entries.forEach(entry => {
66+
totalHours += entry["running_time_in_hours"]
67+
totalCredits+= entry["osparc_credits"]
68+
});
6569
let datas = [];
6670
entries.forEach(entry => {
6771
datas.push({
6872
service: entry["service_key"],
6973
credits: -1*entry["osparc_credits"],
70-
percentage: 100*entry["osparc_credits"]/totalCredits,
74+
hours: entry["running_time_in_hours"],
75+
percentageHours: totalHours ? 100*entry["running_time_in_hours"]/totalHours : 0,
76+
percentageCredits: totalCredits ? 100*entry["osparc_credits"]/totalCredits : 0,
7177
});
7278
});
73-
datas.sort((a, b) => b.percentage - a.percentage);
79+
datas.sort((a, b) => {
80+
if (b.credits !== a.credits) {
81+
return b.credits - a.credits;
82+
}
83+
return b.hours - a.hours;
84+
});
7485
// top 5 services
7586
datas = datas.slice(0, 5);
7687
datas.forEach(data => {
77-
const uiEntry = new osparc.desktop.credits.CreditsServiceListItem(data.service, data.credits, data.percentage);
88+
const uiEntry = new osparc.desktop.credits.CreditsServiceListItem(data.service, data.credits, data.hours, totalCredits === 0 ? data.percentageHours : data.percentageCredits);
7889
this._add(uiEntry);
7990
});
8091
} else {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
qx.Class.define("osparc.desktop.credits.CreditsServiceListItem", {
1919
extend: osparc.ui.list.ListItem,
2020

21-
construct: function(serviceKey, credits, percentage) {
21+
construct: function(serviceKey, credits, hours, percentage) {
2222
this.base(arguments);
2323

2424
const layout = this._getLayout();
2525
layout.setSpacingX(12);
2626
layout.setSpacingY(4);
2727
layout.setColumnFlex(this.self().GRID.ICON.column, 0);
2828
layout.setColumnFlex(this.self().GRID.NAME.column, 1);
29+
layout.setColumnFlex(this.self().GRID.TIME.column, 0);
2930
layout.setColumnFlex(this.self().GRID.CREDITS.column, 0);
3031

3132
const icon = this.getChildControl("icon");
@@ -43,6 +44,7 @@ qx.Class.define("osparc.desktop.credits.CreditsServiceListItem", {
4344
maximum: 100,
4445
value: percentage
4546
});
47+
this.getChildControl("time").setValue(hours + " h");
4648
this.getChildControl("credits").setValue(credits + " used");
4749
},
4850

@@ -61,10 +63,15 @@ qx.Class.define("osparc.desktop.credits.CreditsServiceListItem", {
6163
column: 1,
6264
row: 1
6365
},
64-
CREDITS: {
66+
TIME: {
6567
column: 2,
6668
row: 0,
6769
rowSpan: 2
70+
},
71+
CREDITS: {
72+
column: 3,
73+
row: 0,
74+
rowSpan: 2
6875
}
6976
}
7077
},
@@ -109,6 +116,13 @@ qx.Class.define("osparc.desktop.credits.CreditsServiceListItem", {
109116
});
110117
this._add(control, this.self().GRID.PERCENTAGE);
111118
break;
119+
case "time":
120+
control = new qx.ui.basic.Label().set({
121+
font: "text-14",
122+
alignY: "middle"
123+
});
124+
this._add(control, this.self().GRID.TIME);
125+
break;
112126
case "credits":
113127
control = new qx.ui.basic.Label().set({
114128
font: "text-14",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ qx.Class.define("osparc.desktop.credits.CreditsSummary", {
2626
this.set({
2727
appearance: "floating-menu",
2828
padding: 8,
29-
maxWidth: this.self().WIDTH
29+
maxWidth: this.self().WIDTH,
30+
zIndex: osparc.utils.Utils.FLOATING_Z_INDEX,
3031
});
3132
osparc.utils.Utils.setIdToWidget(this, "creditsSummary");
3233

@@ -41,7 +42,7 @@ qx.Class.define("osparc.desktop.credits.CreditsSummary", {
4142

4243
statics: {
4344
BILLING_CENTER_BUTTON_SIZE: 26,
44-
WIDTH: 300,
45+
WIDTH: 350,
4546
TIME_RANGES: [{
4647
key: 1,
4748
label: "Today"

0 commit comments

Comments
 (0)