From 8766e63120e5c28b22ce4f9a08bdc2ef1300d5ab Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sat, 6 Dec 2025 18:35:34 +0100 Subject: [PATCH] refactor: migrate code-quality-violations pagination to standard pattern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update pagination in code-quality-violations to match companies/vendors: - Add numbered page buttons with ellipsis for large page counts - Add startIndex and endIndex computed properties - Add goToPage(pageNum) method for direct page navigation - Use consistent grid layout (col-span-3, col-span-9) This standardizes pagination UI across all admin tables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../admin/code-quality-violations.html | 86 +++++++++++++------ static/admin/js/code-quality-violations.js | 62 +++++++++++++ 2 files changed, 120 insertions(+), 28 deletions(-) diff --git a/app/templates/admin/code-quality-violations.html b/app/templates/admin/code-quality-violations.html index 24643a97..c9f48707 100644 --- a/app/templates/admin/code-quality-violations.html +++ b/app/templates/admin/code-quality-violations.html @@ -194,34 +194,64 @@ - -
-
-
- - Showing - - of - - results - -
-
- - - Page of - - -
-
+ +
+ + + Showing - of + + + + + + +
{% endblock %} diff --git a/static/admin/js/code-quality-violations.js b/static/admin/js/code-quality-violations.js index fa190bec..438a41a8 100644 --- a/static/admin/js/code-quality-violations.js +++ b/static/admin/js/code-quality-violations.js @@ -96,6 +96,61 @@ function codeQualityViolations() { } }, + // Computed: Total number of pages + get totalPages() { + return this.pagination.total_pages; + }, + + // Computed: Start index for pagination display + get startIndex() { + if (this.pagination.total === 0) return 0; + return (this.pagination.page - 1) * this.pagination.page_size + 1; + }, + + // Computed: End index for pagination display + get endIndex() { + const end = this.pagination.page * this.pagination.page_size; + return end > this.pagination.total ? this.pagination.total : end; + }, + + // Computed: Generate page numbers array with ellipsis + get pageNumbers() { + const pages = []; + const totalPages = this.totalPages; + const current = this.pagination.page; + + if (totalPages <= 7) { + // Show all pages if 7 or fewer + for (let i = 1; i <= totalPages; i++) { + pages.push(i); + } + } else { + // Always show first page + pages.push(1); + + if (current > 3) { + pages.push('...'); + } + + // Show pages around current page + const start = Math.max(2, current - 1); + const end = Math.min(totalPages - 1, current + 1); + + for (let i = start; i <= end; i++) { + pages.push(i); + } + + if (current < totalPages - 2) { + pages.push('...'); + } + + // Always show last page + pages.push(totalPages); + } + + return pages; + }, + async previousPage() { if (this.pagination.page > 1) { this.pagination.page--; @@ -103,6 +158,13 @@ function codeQualityViolations() { } }, + goToPage(pageNum) { + if (pageNum !== '...' && pageNum >= 1 && pageNum <= this.totalPages) { + this.pagination.page = pageNum; + this.loadViolations(); + } + }, + updateURL() { const params = new URLSearchParams();