Skip to content

Commit 038f411

Browse files
committed
Show pruchases
1 parent 5488979 commit 038f411

File tree

3 files changed

+78
-148
lines changed

3 files changed

+78
-148
lines changed

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

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,15 @@ qx.Class.define("osparc.desktop.credits.Rentals", {
2222
construct: function() {
2323
this.base(arguments);
2424

25-
this._setLayout(new qx.ui.layout.VBox(15));
26-
27-
const store = osparc.store.Store.getInstance();
28-
this.__userWallets = store.getWallets();
25+
this._setLayout(new qx.ui.layout.VBox(5));
2926

3027
this.__buildLayout()
3128
},
3229

3330
members: {
3431
__buildLayout: function() {
35-
this._removeAll();
36-
37-
const container = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
38-
39-
const lbl = new qx.ui.basic.Label("Select a Credit Account:");
40-
container.add(lbl);
32+
const lbl = new qx.ui.basic.Label(this.tr("Select a Credit Account:"));
33+
this._add(lbl);
4134

4235
const selectBoxContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
4336
const walletSelectBox = new qx.ui.form.SelectBox().set({
@@ -53,7 +46,7 @@ qx.Class.define("osparc.desktop.credits.Rentals", {
5346
});
5447
this.__fetchingImg.getContentElement().addClass("rotate");
5548
selectBoxContainer.add(this.__fetchingImg);
56-
container.add(selectBoxContainer);
49+
this._add(selectBoxContainer);
5750

5851
const filterContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox(5))
5952
this.__dateFilters = new osparc.desktop.credits.DateFilters();
@@ -62,26 +55,13 @@ qx.Class.define("osparc.desktop.credits.Rentals", {
6255
this.__table.getTableModel().reloadData()
6356
});
6457
filterContainer.add(this.__dateFilters);
65-
filterContainer.add(new qx.ui.core.Spacer(), {
66-
flex: 1
67-
});
68-
this.__exportButton = new qx.ui.form.Button(this.tr("Export")).set({
69-
allowStretchY: false,
70-
alignY: "bottom"
71-
});
72-
this.__exportButton.addListener("execute", () => {
73-
this.__handleExport()
74-
});
75-
filterContainer.add(this.__exportButton);
7658
const refreshButton = new qx.ui.form.Button(this.tr("Reload"), "@FontAwesome5Solid/sync-alt/14").set({
7759
allowStretchY: false,
7860
alignY: "bottom"
7961
});
8062
refreshButton.addListener("execute", () => this.__table && this.__table.getTableModel().reloadData());
8163
filterContainer.add(refreshButton)
82-
container.add(filterContainer);
83-
84-
this._add(container);
64+
this._add(filterContainer);
8565

8666
walletSelectBox.addListener("changeSelection", e => {
8767
const selection = e.getData();
@@ -98,33 +78,27 @@ qx.Class.define("osparc.desktop.credits.Rentals", {
9878
this.__table.getTableModel().bind("isFetching", this.__fetchingImg, "visibility", {
9979
converter: isFetching => isFetching ? "visible" : "excluded"
10080
})
101-
container.add(this.__table, { flex: 1 })
81+
this._add(this.__table, { flex: 1 })
10282
}
10383
}
10484
});
10585

10686
if (osparc.desktop.credits.Utils.areWalletsEnabled()) {
107-
this.__userWallets.forEach(wallet => {
87+
const store = osparc.store.Store.getInstance();
88+
store.getWallets().forEach(wallet => {
10889
walletSelectBox.add(new qx.ui.form.ListItem(wallet.getName(), null, wallet));
10990
});
11091
} else {
11192
lbl.setVisibility("excluded")
11293
walletSelectBox.setVisibility("excluded")
113-
this.__exportButton.setVisibility("excluded")
11494
this.__table = new osparc.desktop.credits.RentalsTable(null, this.__dateFilters.getValue()).set({
11595
marginTop: 10
11696
})
11797
this.__table.getTableModel().bind("isFetching", this.__fetchingImg, "visibility", {
11898
converter: isFetching => isFetching ? "visible" : "excluded"
11999
})
120-
container.add(this.__table, { flex: 1 })
100+
this._add(this.__table, { flex: 1 })
121101
}
122102
},
123-
__handleExport() {
124-
const reportUrl = new URL("/v0/services/-/rentals-report", window.location.origin)
125-
reportUrl.searchParams.append("wallet_id", this.__selectedWallet.getWalletId())
126-
reportUrl.searchParams.append("filters", JSON.stringify({ "started_at": this.__dateFilters.getValue() }))
127-
window.open(reportUrl, "_blank")
128-
}
129103
}
130104
});

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

Lines changed: 34 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,106 +20,74 @@ qx.Class.define("osparc.desktop.credits.RentalsTable", {
2020
extend: qx.ui.table.Table,
2121

2222
construct: function(walletId, filters) {
23-
this.base(arguments)
24-
const model = new osparc.desktop.credits.RentalsTableModel(walletId, filters)
25-
this.setTableModel(model)
26-
this.setStatusBarVisible(false)
23+
this.base(arguments);
2724

28-
this.setHeaderCellHeight(26);
29-
this.setRowHeight(26);
25+
const model = new osparc.desktop.credits.RentalsTableModel(walletId, filters);
26+
this.setTableModel(model);
3027

31-
const columnModel = this.getTableColumnModel();
28+
this.set({
29+
statusBarVisible: false,
30+
headerCellHeight: 26,
31+
rowHeight: 26,
32+
});
3233

34+
const columnModel = this.getTableColumnModel();
35+
columnModel.setColumnVisible(this.self().COLS.PURCHASE_ID.column, false);
36+
columnModel.setColumnVisible(this.self().COLS.ITEM_ID.column, false);
3337
columnModel.setDataCellRenderer(this.self().COLS.COST.column, new qx.ui.table.cellrenderer.Number());
3438

35-
if (!osparc.desktop.credits.Utils.areWalletsEnabled()) {
36-
columnModel.setColumnVisible(this.self().COLS.COST.column, false);
37-
columnModel.setColumnVisible(this.self().COLS.USER.column, false);
38-
}
39-
columnModel.setColumnVisible(this.self().COLS.SERVICE.column, false);
40-
41-
// Array [0, 1, ..., N] where N is column_count - 1 (default column order)
42-
this.__columnOrder = [...Array(columnModel.getOverallColumnCount()).keys()]
43-
44-
if (
45-
osparc.Preferences.getInstance().getBillingCenterRentalsColumnOrder() &&
46-
osparc.Preferences.getInstance().getBillingCenterRentalsColumnOrder().length === this.__columnOrder.length
47-
) {
48-
columnModel.setColumnsOrder(osparc.Preferences.getInstance().getBillingCenterRentalsColumnOrder())
49-
this.__columnOrder = osparc.Preferences.getInstance().getBillingCenterRentalsColumnOrder()
50-
} else {
51-
osparc.Preferences.getInstance().setBillingCenterRentalsColumnOrder(this.__columnOrder)
52-
}
53-
54-
columnModel.addListener("orderChanged", e => {
55-
// Save new order into preferences
56-
if (e.getData()) {
57-
const { fromOverXPos, toOverXPos } = e.getData()
58-
// Edit current order
59-
this.__columnOrder = this.__columnOrder.toSpliced(toOverXPos, 0, this.__columnOrder.splice(fromOverXPos, 1)[0])
60-
// Save order
61-
osparc.Preferences.getInstance().setBillingCenterRentalsColumnOrder(this.__columnOrder)
62-
}
63-
}, this)
64-
6539
Object.values(this.self().COLS).forEach(col => columnModel.setColumnWidth(col.column, col.width));
6640
},
6741

6842
statics: {
6943
COLS: {
70-
PROJECT: {
71-
id: "project",
44+
PURCHASE_ID: {
45+
id: "purchaseId",
7246
column: 0,
73-
label: osparc.product.Utils.getStudyAlias({firstUpperCase: true}),
74-
width: 140
47+
label: qx.locale.Manager.tr("PurchaseId"),
48+
width: 150
7549
},
76-
NODE: {
77-
id: "node",
50+
ITEM_ID: {
51+
id: "itemId",
7852
column: 1,
79-
label: qx.locale.Manager.tr("Node"),
80-
width: 140
53+
label: qx.locale.Manager.tr("ItemId"),
54+
width: 150
8155
},
82-
SERVICE: {
83-
id: "service",
56+
ITEM_LABEL: {
57+
id: "itemLabel",
8458
column: 2,
85-
label: qx.locale.Manager.tr("Service"),
86-
width: 140
59+
label: qx.locale.Manager.tr("Name"),
60+
width: 150
8761
},
8862
START: {
8963
id: "start",
9064
column: 3,
9165
label: qx.locale.Manager.tr("Start"),
92-
width: 130
66+
width: 150
9367
},
94-
DURATION: {
95-
id: "duration",
68+
END: {
69+
id: "end",
9670
column: 4,
97-
label: qx.locale.Manager.tr("Duration"),
98-
width: 70
71+
label: qx.locale.Manager.tr("End"),
72+
width: 150
9973
},
100-
STATUS: {
101-
id: "status",
74+
SEATS: {
75+
id: "seats",
10276
column: 5,
103-
label: qx.locale.Manager.tr("Status"),
104-
width: 70
77+
label: qx.locale.Manager.tr("Seats"),
78+
width: 50
10579
},
10680
COST: {
10781
id: "cost",
10882
column: 6,
10983
label: qx.locale.Manager.tr("Credits"),
110-
width: 56
84+
width: 60
11185
},
11286
USER: {
11387
id: "user",
11488
column: 7,
11589
label: qx.locale.Manager.tr("User"),
116-
width: 140
117-
},
118-
TAGS: {
119-
id: "tags",
120-
column: 7,
121-
label: qx.locale.Manager.tr("Tags"),
122-
width: 140
90+
width: 100
12391
},
12492
}
12593
}

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

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
3232
this.setFilters(filters)
3333
}
3434
this.setSortColumnIndexWithoutSortingData(rentalsCols.START.column);
35-
this.setSortAscendingWithoutSortingData(false)
36-
this.setColumnSortable(rentalsCols.DURATION.column, false);
35+
this.setSortAscendingWithoutSortingData(false);
3736
},
3837

3938
properties: {
@@ -61,17 +60,22 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
6160

6261
statics: {
6362
SERVER_MAX_LIMIT: 49,
63+
COLUMN_ID_TO_DB_COLUMN_MAP: Object.values(osparc.desktop.credits.RentalsTable.COLS).reduce((acc, { id, column }) => {
64+
acc[column] = id;
65+
return acc;
66+
}, {}),
67+
/*
6468
COLUMN_ID_TO_DB_COLUMN_MAP: {
65-
0: "root_parent_project_name",
66-
1: "node_name",
67-
2: "service_key",
68-
3: "started_at",
69-
// 4: (not used) SORTING BY DURATION
70-
5: "service_run_status",
71-
6: "credit_cost",
72-
7: "user_email",
73-
8: "projects_tags",
74-
}
69+
0: "purchaseId",
70+
1: "itemId",
71+
2: "itemLabel",
72+
3: "start",
73+
4: "duration",
74+
5: "seats",
75+
6: "cost",
76+
7: "user",
77+
},
78+
*/
7579
},
7680

7781
members: {
@@ -86,7 +90,6 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
8690

8791
// overridden
8892
_loadRowCount() {
89-
const endpoint = this.getWalletId() == null ? "get" : "getWithWalletFiltered"
9093
const params = {
9194
url: {
9295
walletId: this.getWalletId(),
@@ -103,24 +106,23 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
103106
const options = {
104107
resolveWResponse: true
105108
};
106-
osparc.data.Resources.fetch("resourceRentals", endpoint, params, options)
109+
osparc.data.Resources.fetch("wallets", "purchases", params, options)
107110
.then(resp => {
108111
this._onRowCountLoaded(resp["_meta"].total)
109112
})
110113
.catch(() => {
111114
this._onRowCountLoaded(null)
112-
})
115+
});
113116
},
114117

115118
// overridden
116119
_loadRowData(firstRow, qxLastRow) {
117-
this.setIsFetching(true)
118-
// Please Qloocloox don't ask for more rows than there are
120+
this.setIsFetching(true);
121+
119122
const lastRow = Math.min(qxLastRow, this._rowCount - 1)
120123
// Returns a request promise with given offset and limit
121124
const getFetchPromise = (offset, limit=this.self().SERVER_MAX_LIMIT) => {
122-
const endpoint = this.getWalletId() == null ? "get" : "getWithWalletFiltered"
123-
return osparc.data.Resources.fetch("resourceRentals", endpoint, {
125+
return osparc.data.Resources.fetch("wallets", "purchases", {
124126
url: {
125127
walletId: this.getWalletId(),
126128
limit,
@@ -137,38 +139,24 @@ qx.Class.define("osparc.desktop.credits.RentalsTableModel", {
137139
const data = []
138140
const rentalsCols = osparc.desktop.credits.RentalsTable.COLS;
139141
rawData.forEach(rawRow => {
140-
let service = ""
141-
if (rawRow["service_key"]) {
142-
const serviceName = rawRow["service_key"].split("/").pop()
143-
service = `${serviceName}:${rawRow["service_version"]}`
144-
}
145-
let start = ""
146-
let duration = ""
147-
if (rawRow["started_at"]) {
148-
start = osparc.utils.Utils.formatDateAndTime(new Date(rawRow["started_at"]))
149-
if (rawRow["stopped_at"]) {
150-
duration = osparc.utils.Utils.formatMsToHHMMSS(new Date(rawRow["stopped_at"]) - new Date(rawRow["started_at"]))
151-
}
152-
}
153142
data.push({
154-
// root_parent_project is the same as project if it has no parent
155-
[rentalsCols.PROJECT.id]: rawRow["root_parent_project_name"] || rawRow["root_parent_project_id"] || rawRow["project_name"] || rawRow["project_id"],
156-
[rentalsCols.NODE.id]: rawRow["node_name"] || rawRow["node_id"],
157-
[rentalsCols.SERVICE.id]: service,
158-
[rentalsCols.START.id]: start,
159-
[rentalsCols.DURATION.id]: duration,
160-
[rentalsCols.STATUS.id]: qx.lang.String.firstUp(rawRow["service_run_status"].toLowerCase()),
161-
[rentalsCols.COST.id]: rawRow["credit_cost"] ? parseFloat(rawRow["credit_cost"]).toFixed(2) : "",
162-
[rentalsCols.USER.id]: rawRow["user_email"],
163-
[rentalsCols.TAGS.id]: rawRow["project_tags"],
143+
[rentalsCols.PURCHASE_ID.id]: rawRow["licensedItemPurchaseId"],
144+
[rentalsCols.ITEM_ID.id]: rawRow["licensedItemId"],
145+
[rentalsCols.ITEM_LABEL.id]: "Hello",
146+
[rentalsCols.START.id]: osparc.utils.Utils.formatDateAndTime(new Date(rawRow["startAt"])),
147+
[rentalsCols.END.id]: osparc.utils.Utils.formatDateAndTime(new Date(rawRow["expireAt"])),
148+
[rentalsCols.SEATS.id]: rawRow["numOfSeats"],
149+
[rentalsCols.COST.id]: rawRow["pricingUnitCost"] ? parseFloat(rawRow["pricingUnitCost"]).toFixed(2) : "",
150+
[rentalsCols.USER.id]: rawRow["purchasedByUser"],
164151
})
165152
})
166-
return data
167-
})
168-
}
153+
return data;
154+
});
155+
};
156+
169157
// Divides the model row request into several server requests to comply with the number of rows server limit
170-
const reqLimit = lastRow - firstRow + 1 // Number of requested rows
171-
const nRequests = Math.ceil(reqLimit / this.self().SERVER_MAX_LIMIT)
158+
const reqLimit = lastRow - firstRow + 1; // Number of requested rows
159+
const nRequests = Math.ceil(reqLimit / this.self().SERVER_MAX_LIMIT);
172160
if (nRequests > 1) {
173161
let requests = []
174162
for (let i=firstRow; i <= lastRow; i += this.self().SERVER_MAX_LIMIT) {

0 commit comments

Comments
 (0)