From ef92cd91b2dc5e4f32bcdfa75e18edf55d3cd0a2 Mon Sep 17 00:00:00 2001 From: ReLoia Date: Thu, 18 Jun 2026 22:18:00 +0200 Subject: [PATCH] feat: added pagination to /admin/reports Closes #13 --- app/pages/admin/reports.vue | 125 ++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 47 deletions(-) diff --git a/app/pages/admin/reports.vue b/app/pages/admin/reports.vue index f4e63bb..b4b7b0a 100644 --- a/app/pages/admin/reports.vue +++ b/app/pages/admin/reports.vue @@ -60,21 +60,40 @@ const activeReports = computed(() => reports.value.filter((report) => ['UNDER_RE const closedReports = computed(() => reports.value.filter((report) => ['RESOLVED', 'CLOSED'].includes(report.status)).length) const reportsByStatus = computed(() => - Object.entries(statusMeta) - .map(([status, meta]) => ({ - status: status as ReportStatus, - label: meta.label, - tone: meta.tone, - total: reports.value.filter((report) => report.status === status).length - })) - .filter((item) => item.total > 0) + Object.entries(statusMeta) + .map(([status, meta]) => ({ + status: status as ReportStatus, + label: meta.label, + tone: meta.tone, + total: reports.value.filter((report) => report.status === status).length + })) + .filter((item) => item.total > 0) ) -const recentReports = computed(() => - [...filteredReports.value] - .sort((a, b) => new Date(b.created_at || '').getTime() - new Date(a.created_at || '').getTime()) - .slice(0, 12) -) +// --- INIZIO LOGICA PAGINAZIONE --- +const currentPage = ref(1) +const itemsPerPage = ref(12) + +// Reset alla pagina 1 quando cambiano i filtri +watch([search, selectedStatus, selectedCategoryId, selectedAreaId], () => { + currentPage.value = 1 +}) + +const totalPages = computed(() => Math.ceil(filteredReports.value.length / itemsPerPage.value)) + +const paginatedReports = computed(() => { + const sorted = [...filteredReports.value].sort( + (a, b) => new Date(b.created_at || '').getTime() - new Date(a.created_at || '').getTime() + ) + const start = (currentPage.value - 1) * itemsPerPage.value + const end = start + itemsPerPage.value + return sorted.slice(start, end) +}) + +const handlePageChange = (page: number) => { + currentPage.value = page +} +// --- FINE LOGICA PAGINAZIONE --- const formatDate = (value?: string) => { if (!value) return '-' @@ -160,71 +179,83 @@ const truncate = (value?: string, max = 120) => {

Distribuzione stati

- {{ filteredReports.length }} elementi visibili + {{ filteredReports.length }} elementi trovati
- - - - + + + + - - + - - + + +
StatoTotale
StatoTotale
+
{{ item.label }} - {{ item.total }}
{{ item.total }}
-
+
Nessuna segnalazione trovata con filtri correnti.
-
+
- - - - - - - - - + + + + + + + + + - - - - - - + + + + + - - - + + + +
IDCategoriaIndirizzoAreaStatoOperatoreAggiornata
IDCategoriaIndirizzoAreaStatoOperatoreAggiornata
#{{ report.id }} -
{{ report.category_name || '-' }}
- {{ truncate(report.description, 72) }} -
{{ report.address || '-' }}{{ report.area_name || 'Non assegnata' }} +
#{{ report.id }} +
{{ report.category_name || '-' }}
+ {{ truncate(report.description, 72) }} +
{{ report.address || '-' }}{{ report.area_name || 'Non assegnata' }} {{ statusMeta[report.status].label }} - {{ report.assigned_operator_id ? `#${report.assigned_operator_id}` : '-' }}{{ formatDate(report.updated_at || report.created_at) }}
{{ report.assigned_operator_id ? `#${report.assigned_operator_id}` : '-' }}{{ formatDate(report.updated_at || report.created_at) }}
+ + +