fixed
This commit is contained in:
1 parent
4194cef934
commit
363127fe9e
3350 files changed
+1284220
-1
No files matched your search
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Dashboard: content count cards and the latest news list.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const CARDS = [
|
||||
{ id: "stat-news", endpoint: "/v1/admin/news", listKey: "news" },
|
||||
{ id: "stat-categories", endpoint: "/v1/admin/categories", listKey: "categories" },
|
||||
{ id: "stat-banners", endpoint: "/v1/admin/banner", listKey: "banners" },
|
||||
{ id: "stat-static", endpoint: "/v1/admin/static", listKey: "statics" },
|
||||
{ id: "stat-currency", endpoint: "/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 = "—";
|
||||
}
|
||||
});
|
||||
|
||||
loadLatestNews();
|
||||
});
|
||||
|
||||
async function loadLatestNews() {
|
||||
const container = document.getElementById("latest-news");
|
||||
if (!container) return;
|
||||
try {
|
||||
const data = await Api.get("/v1/admin/news", { limit: 5, page: 1 });
|
||||
const items = (data && data.news) || [];
|
||||
if (!items.length) {
|
||||
container.innerHTML =
|
||||
'<li class="py-4 text-base-content/60">No news yet.</li>';
|
||||
return;
|
||||
}
|
||||
container.innerHTML = items
|
||||
.map(
|
||||
(item) => `
|
||||
<li class="flex items-center gap-3 py-3">
|
||||
${item.imagePath ? `<img src="${UI.escapeHtml(item.imagePath)}" alt="" class="h-10 w-14 rounded object-cover" loading="lazy">` : ""}
|
||||
<div class="min-w-0 flex-1">
|
||||
<a href="/admin/news/${item.Id}/edit" class="block truncate font-medium hover:text-primary">${UI.escapeHtml(langText(item.title))}</a>
|
||||
<span class="text-sm text-base-content/60">${UI.escapeHtml(UI.formatDate(item.dateRelease))}</span>
|
||||
</div>
|
||||
</li>`
|
||||
)
|
||||
.join("");
|
||||
} catch (error) {
|
||||
container.innerHTML = `<li class="py-4 text-error">${UI.escapeHtml(error.message)}</li>`;
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user