Skip to content

Commit

Permalink
Merge pull request #1269 from pi-hole/fix/client_sorting
Browse files Browse the repository at this point in the history
Add proper IP sorting to the groups->client table
  • Loading branch information
PromoFaux authored May 17, 2020
2 parents 0b2ae59 + a0bd88c commit 7d409ad
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions groups-clients.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
</div>
</div>

<script src="scripts/pi-hole/js/ip-address-sorting.js"></script>
<script src="scripts/pi-hole/js/groups-common.js"></script>
<script src="scripts/pi-hole/js/groups-clients.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion scripts/pi-hole/js/groups-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function initTable() {
order: [[0, "asc"]],
columns: [
{ data: "id", visible: false },
{ data: "ip" },
{ data: "ip", type: "ip-address" },
{ data: "comment" },
{ data: "groups", searchable: false },
{ data: "name", width: "80px", orderable: false }
Expand Down
28 changes: 25 additions & 3 deletions scripts/pi-hole/js/ip-address-sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
var m = a.split("."),
n = a.split(":"),
x = "",
xa = "";
xa = "",
cidr = [];
if (m.length === 4) {
// IPV4
// IPV4 (possibly with CIDR)
cidr = m[3].split("/");
if (cidr.length === 2) {
m.pop();
m = m.concat(cidr);
}

for (i = 0; i < m.length; i++) {
item = m[i];

Expand All @@ -38,7 +45,7 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
}
}
} else if (n.length > 0) {
// IPV6
// IPV6 (possibly with CIDR)
var count = 0;
for (i = 0; i < n.length; i++) {
item = n[i];
Expand Down Expand Up @@ -79,6 +86,21 @@ jQuery.extend(jQuery.fn.dataTableExt.oSort, {
x += item;
}
}

cidr = x.split("/");
x = cidr[0];
if (cidr.length === 2) {
item = cidr[1];
if (item.length === 1) {
x += "00" + item;
} else if (item.length === 2) {
x += "0" + item;
} else {
x += item;
}
}

console.log([a, n, xa, count, x]);
}

return x;
Expand Down

0 comments on commit 7d409ad

Please sign in to comment.