btcpayserver/BTCPayServer/Components/AppSales/Default.cshtml.js
d11n 492512f527
Dashboard: Show revenue data for keypad (#5317)
* POS: Display fixes

* Dashboard: Fix Top Items component

* Dashboard: Fix App Sales component

* Dashboard: Show revenue data for keypad

Closes #5303.
2023-09-14 09:26:47 +09:00

43 lines
1.5 KiB
JavaScript

if (!window.appSales) {
window.appSales = {
dataLoaded (model) {
const id = `AppSales-${model.id}`;
const appId = model.id;
const period = model.period;
const baseUrl = model.dataUrl;
const data = model;
const render = (data, period) => {
const series = data.series.map(s => s.salesCount);
const labels = data.series.map((s, i) => period === 'Month' ? (i % 5 === 0 ? s.label : '') : s.label);
const min = Math.min(...series);
const max = Math.max(...series);
const low = min === max ? 0 : Math.max(min - ((max - min) / 5), 0);
document.querySelectorAll(`#${id} .sales-count`).innerText = data.salesCount;
new Chartist.Bar(`#${id} .ct-chart`, {
labels,
series: [series]
}, {
low
});
};
render(data, period);
const update = async period => {
const url = `${baseUrl}/${period}`;
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
render(data, period);
}
};
delegate('change', `#${id} [name="AppSalesPeriod-${appId}"]`, async e => {
const type = e.target.value;
await update(type);
});
}
};
}