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) => {
| Stato | -Totale | -
|---|---|
| Stato | +Totale | +
| + | |
| {{ item.label }} - | -{{ item.total }} | -{{ item.total }} | +
| ID | -Categoria | -Indirizzo | -Area | -Stato | -Operatore | -Aggiornata | -
|---|---|---|---|---|---|---|
| ID | +Categoria | +Indirizzo | +Area | +Stato | +Operatore | +Aggiornata | +
| #{{ 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) }} | +