Skip to content

Commit 5ae19d6

Browse files
slalomsk8erlafelectrocret
authored
Pagination for access points (librenms#16391)
* Pagination for access points * Update accesspoints.inc.php fix label of pagination statistics --------- Co-authored-by: Neil Lathwood <[email protected]> Co-authored-by: Justin Lentz <[email protected]>
1 parent d415aa5 commit 5ae19d6

File tree

1 file changed

+107
-1
lines changed

1 file changed

+107
-1
lines changed

includes/html/pages/device/accesspoints.inc.php

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
<?php
2+
/*
3+
* LibreNMS
4+
*
5+
* This program is free software: you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License as published by the
7+
* Free Software Foundation, either version 3 of the License, or (at your
8+
* option) any later version. Please see LICENSE.txt at the top level of
9+
* the source code distribution for details.
10+
*
11+
* @package LibreNMS
12+
* @subpackage webui
13+
* @link https://www.librenms.org
14+
* @copyright 2024 LibreNMS
15+
* @author LibreNMS Contributors
16+
*/
217

18+
echo '<form method="post" action="" id="result_form">';
19+
echo csrf_field();
20+
if (isset($_POST['results_amount']) && $_POST['results_amount'] > 0) {
21+
$results = $_POST['results'];
22+
} else {
23+
$results = 50;
24+
}
25+
26+
echo '<div class="panel panel-default">';
27+
echo '<div class="pull-right" style="padding-top: 5px;padding-right: 5px;">';
28+
echo '<select data-toggle="popover" data-placement="left" data-content="results per page" name="results" id="results" class="form-control input-sm" onChange="updateResults(this);">';
29+
30+
$result_options = [
31+
'10',
32+
'50',
33+
'100',
34+
'250',
35+
'500',
36+
'1000',
37+
'5000',
38+
39+
];
40+
foreach ($result_options as $option) {
41+
echo "<option value='$option'";
42+
if ($results == $option) {
43+
echo ' selected';
44+
}
45+
echo ">$option</option>";
46+
}
47+
echo '</select>';
48+
echo '</div>';
49+
echo '<div class="panel-heading">';
50+
echo '<span class="tw-font-bold">Access Points</span>';
51+
echo '</div>';
52+
echo '</div>';
53+
echo '<br>';
354
echo "<div style='margin: 0px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>";
455

556
$i = '1';
@@ -9,12 +60,67 @@
960
} else {
1061
$aps = dbFetchRows("SELECT * FROM `access_points` WHERE `device_id` = ? AND `deleted` = '0' ORDER BY `name`,`radio_number` ASC", [$device['device_id']]);
1162
}
63+
64+
$count = count($aps);
65+
66+
if (isset($_POST['page_number']) && $_POST['page_number'] > 0 && $_POST['page_number'] <= $count) {
67+
$page_number = $_POST['page_number'];
68+
} else {
69+
$page_number = 1;
70+
}
71+
72+
$start = (($page_number - 1) * $results);
73+
74+
1275
echo "<div style='margin: 0px;'><table border=0 cellspacing=0 cellpadding=5 width=100%>";
76+
$index = 0;
1377
foreach ($aps as $ap) {
78+
$index++;
79+
80+
if ($index < $start) {
81+
continue;
82+
}
83+
if ($index > $start + $results) {
84+
break;
85+
}
86+
1487
include 'includes/html/print-accesspoint.inc.php';
1588
$i++;
1689
}
1790

1891
echo '</table></div>';
19-
2092
echo '</div>';
93+
94+
if ($count > $results) {
95+
echo '<div class="table-responsive">';
96+
echo '<div class="col pull-left">';
97+
echo generate_pagination($count, $results, $page_number);
98+
echo '</div>';
99+
echo '<div class="col pull-right">';
100+
$showing_start = ($page_number * $results) - $results + 1;
101+
$showing_end = $page_number * $results;
102+
if ($showing_end > $count) {
103+
$showing_end = $count;
104+
}
105+
echo "<p class=\"pagination\">Showing $showing_start to $showing_end of $count access pints</p>";
106+
echo '</div>';
107+
echo '</div>';
108+
}
109+
110+
echo '<input type="hidden" name="page_number" id="page_number" value="' . htmlspecialchars($page_number) . '">
111+
<input type="hidden" name="results_amount" id="results_amount" value="' . htmlspecialchars($results) . '">
112+
</form>';
113+
?>
114+
<script>
115+
function updateResults(results) {
116+
$('#results_amount').val(results.value);
117+
$('#page_number').val(1);
118+
$('#result_form').trigger( "submit" );
119+
}
120+
121+
function changePage(page,e) {
122+
e.preventDefault();
123+
$('#page_number').val(page);
124+
$('#result_form').trigger( "submit" );
125+
}
126+
</script>

0 commit comments

Comments
 (0)