From 14d5ff97f3be0e69cfa1e0e7537dbb71348d157a Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Fri, 6 Mar 2026 23:27:46 +0100 Subject: [PATCH] fix(prospecting): add missing pagination computed properties to JS components The pagination() macro expects startIndex, endIndex, pageNumbers, totalPages, nextPage(), and previousPage() to be defined in the Alpine.js component. Added these to scan-jobs.js, prospects.js, and leads.js. Co-Authored-By: Claude Opus 4.6 --- .../prospecting/static/admin/js/leads.js | 36 +++++++++++++++++++ .../prospecting/static/admin/js/prospects.js | 36 +++++++++++++++++++ .../prospecting/static/admin/js/scan-jobs.js | 36 +++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/app/modules/prospecting/static/admin/js/leads.js b/app/modules/prospecting/static/admin/js/leads.js index 946e7be4..4736a43f 100644 --- a/app/modules/prospecting/static/admin/js/leads.js +++ b/app/modules/prospecting/static/admin/js/leads.js @@ -81,11 +81,47 @@ function leadsList() { window.location.href = '/admin/prospecting/prospects/' + lead.id + '#campaigns'; }, + get startIndex() { + if (this.pagination.total === 0) return 0; + return (this.pagination.page - 1) * this.pagination.per_page + 1; + }, + + get endIndex() { + const end = this.pagination.page * this.pagination.per_page; + return end > this.pagination.total ? this.pagination.total : end; + }, + + get totalPages() { + return this.pagination.pages; + }, + + get pageNumbers() { + const pages = []; + const total = this.totalPages; + const current = this.pagination.page; + if (total <= 7) { for (let i = 1; i <= total; i++) pages.push(i); return pages; } + pages.push(1); + if (current > 3) pages.push('...'); + for (let i = Math.max(2, current - 1); i <= Math.min(total - 1, current + 1); i++) pages.push(i); + if (current < total - 2) pages.push('...'); + pages.push(total); + return pages; + }, + goToPage(page) { + if (page === '...' || page < 1 || page > this.totalPages) return; this.pagination.page = page; this.loadLeads(); }, + nextPage() { + if (this.pagination.page < this.totalPages) { this.pagination.page++; this.loadLeads(); } + }, + + previousPage() { + if (this.pagination.page > 1) { this.pagination.page--; this.loadLeads(); } + }, + tierBadgeClass(tier) { const classes = { top_priority: 'text-red-700 bg-red-100 dark:text-red-100 dark:bg-red-700', diff --git a/app/modules/prospecting/static/admin/js/prospects.js b/app/modules/prospecting/static/admin/js/prospects.js index 762ed36d..aa946af2 100644 --- a/app/modules/prospecting/static/admin/js/prospects.js +++ b/app/modules/prospecting/static/admin/js/prospects.js @@ -111,11 +111,47 @@ function prospectsList() { }; }, + get startIndex() { + if (this.pagination.total === 0) return 0; + return (this.pagination.page - 1) * this.pagination.per_page + 1; + }, + + get endIndex() { + const end = this.pagination.page * this.pagination.per_page; + return end > this.pagination.total ? this.pagination.total : end; + }, + + get totalPages() { + return this.pagination.pages; + }, + + get pageNumbers() { + const pages = []; + const total = this.totalPages; + const current = this.pagination.page; + if (total <= 7) { for (let i = 1; i <= total; i++) pages.push(i); return pages; } + pages.push(1); + if (current > 3) pages.push('...'); + for (let i = Math.max(2, current - 1); i <= Math.min(total - 1, current + 1); i++) pages.push(i); + if (current < total - 2) pages.push('...'); + pages.push(total); + return pages; + }, + goToPage(page) { + if (page === '...' || page < 1 || page > this.totalPages) return; this.pagination.page = page; this.loadProspects(); }, + nextPage() { + if (this.pagination.page < this.totalPages) { this.pagination.page++; this.loadProspects(); } + }, + + previousPage() { + if (this.pagination.page > 1) { this.pagination.page--; this.loadProspects(); } + }, + statusBadgeClass(status) { const classes = { pending: 'text-yellow-700 bg-yellow-100 dark:text-yellow-100 dark:bg-yellow-700', diff --git a/app/modules/prospecting/static/admin/js/scan-jobs.js b/app/modules/prospecting/static/admin/js/scan-jobs.js index e64e9c82..62c570f4 100644 --- a/app/modules/prospecting/static/admin/js/scan-jobs.js +++ b/app/modules/prospecting/static/admin/js/scan-jobs.js @@ -57,11 +57,47 @@ function scanJobs() { } }, + get startIndex() { + if (this.pagination.total === 0) return 0; + return (this.pagination.page - 1) * this.pagination.per_page + 1; + }, + + get endIndex() { + const end = this.pagination.page * this.pagination.per_page; + return end > this.pagination.total ? this.pagination.total : end; + }, + + get totalPages() { + return this.pagination.pages; + }, + + get pageNumbers() { + const pages = []; + const total = this.totalPages; + const current = this.pagination.page; + if (total <= 7) { for (let i = 1; i <= total; i++) pages.push(i); return pages; } + pages.push(1); + if (current > 3) pages.push('...'); + for (let i = Math.max(2, current - 1); i <= Math.min(total - 1, current + 1); i++) pages.push(i); + if (current < total - 2) pages.push('...'); + pages.push(total); + return pages; + }, + goToPage(page) { + if (page === '...' || page < 1 || page > this.totalPages) return; this.pagination.page = page; this.loadJobs(); }, + nextPage() { + if (this.pagination.page < this.totalPages) { this.pagination.page++; this.loadJobs(); } + }, + + previousPage() { + if (this.pagination.page > 1) { this.pagination.page--; this.loadJobs(); } + }, + jobStatusClass(status) { const classes = { pending: 'text-yellow-700 bg-yellow-100 dark:text-yellow-100 dark:bg-yellow-700',