Drop the news list and news stat card so the dashboard only shows category, banner, static, and currency counts. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
/**
|
|
* Dashboard: content count cards.
|
|
*/
|
|
(function () {
|
|
"use strict";
|
|
|
|
const CARDS = [
|
|
{ id: "stat-categories", endpoint: "/api/v1/admin/categories", listKey: "categories" },
|
|
{ id: "stat-banners", endpoint: "/api/v1/admin/banner", listKey: "banners" },
|
|
{ id: "stat-static", endpoint: "/api/v1/admin/static", listKey: "statics" },
|
|
{ id: "stat-currency", endpoint: "/api/v1/admin/currency", listKey: "currencies" },
|
|
];
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
if (document.body.dataset.page !== "dashboard") return;
|
|
if (!Auth.requireAuth()) return;
|
|
|
|
Auth.loadProfile();
|
|
Auth.bindLogoutButtons();
|
|
|
|
CARDS.forEach(async (card) => {
|
|
const valueEl = document.querySelector("#" + card.id + " [data-stat-value]");
|
|
if (!valueEl) return;
|
|
try {
|
|
const data = await Api.get(card.endpoint, { limit: 1, page: 1 });
|
|
valueEl.textContent = (data && data.count) || 0;
|
|
} catch (_) {
|
|
valueEl.textContent = "—";
|
|
}
|
|
});
|
|
});
|
|
})();
|