From d7e42772eac82641a3846c018883a5a1352a7a41 Mon Sep 17 00:00:00 2001
From: Floorb <132411956+Neetpone@users.noreply.github.com>
Date: Thu, 4 Nov 2021 10:41:37 -0400
Subject: [PATCH] Improve paginator JS
---
admin/dashboard.php | 2 -
admin/tasksqqq.php | 254 --------------------------------------
assets/bundle.js | 24 ++--
assets/bundle.min.js | 2 +-
assets/bundle.min.js.map | 2 +-
js/data_tables.js | 24 ++--
theme/bulma/css/paste.css | 23 ++++
7 files changed, 53 insertions(+), 278 deletions(-)
delete mode 100644 admin/tasksqqq.php
diff --git a/admin/dashboard.php b/admin/dashboard.php
index 8874454..7a6d760 100644
--- a/admin/dashboard.php
+++ b/admin/dashboard.php
@@ -8,8 +8,6 @@ use PonePaste\Models\PageView;
$today_users_count = 0;
$today_pastes_count = 0;
-
-
$query = $conn->query("SELECT @last_id := MAX(id) FROM page_view");
$row = $query->fetch(PDO::FETCH_NUM);
$page_last_id = intval($row[0]);
diff --git a/admin/tasksqqq.php b/admin/tasksqqq.php
deleted file mode 100644
index d80597e..0000000
--- a/admin/tasksqqq.php
+++ /dev/null
@@ -1,254 +0,0 @@
-
-
-
-
-
-
-
-
';
-
- } else {
- $msg = '
- All expired pastes have been deleted
-
';
- }
- }
- if (isset($_GET['all_pastes'])) {
- $query = "DELETE FROM pastes";
- mysqli_query($con, $query);
-
- if (mysqli_errno($con)) {
- $msg = '
- ' . mysqli_error($con) . '
-
';
-
- } else {
- $msg = '
- All pastes have been deleted
-
';
- }
-
- }
- if (isset($_GET['not_verfied'])) {
- $query = "DELETE FROM users where verified='0'";
- mysqli_query($con, $query);
-
- if (mysqli_errno($con)) {
- $msg = '
- ' . mysqli_error($con) . '
-
';
-
- } else {
- $msg = '
- All unverified accounts have been deleted
-
';
- }
- }
- if (isset($_GET['admin_history'])) {
- $query = "DELETE FROM admin_history";
- mysqli_query($con, $query);
-
- if (mysqli_errno($con)) {
- $msg = '
- ' . mysqli_error($con) . '
-
';
-
- } else {
- $msg = '
- Admin history has been cleared
-
';
- }
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/assets/bundle.js b/assets/bundle.js
index 3785690..a73a42a 100644
--- a/assets/bundle.js
+++ b/assets/bundle.js
@@ -144,21 +144,23 @@ class SimplePaginator {
/* First and last page in existence */
const firstPage = 0;
- const lastPage = Math.ceil(totalRecords / perPage); // ish?
- const numPagesToShow = 3;
+ const lastPage = Math.floor(totalRecords / perPage); // ish?
+ const numPagesToShow = 2;
/* First and last page the main paginator will show */
- const firstPageShow = (currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow;
- const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow * 2);
+ const firstPageShow = (currentPage - firstPage) < numPagesToShow ? firstPage : ((currentPage - numPagesToShow < 0) ? currentPage : currentPage - numPagesToShow);
+ const lastPageShow = (firstPageShow + numPagesToShow) > lastPage ? lastPage : (firstPageShow + numPagesToShow + numPagesToShow);
/* Whether to show the first and last pages in existence at the ends of the paginator */
- const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow * 2);
- const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow * 2);
+ const showFirstPage = (Math.abs(firstPage - currentPage)) > (numPagesToShow);
+ const showLastPage = (Math.abs(lastPage - currentPage)) > (numPagesToShow);
+ const prevButtonDisabled = currentPage === firstPage ? 'disabled' : '';
+
/* Previous button */
this.element.appendChild(makeEl(
- `