From 426fc7d389248df2a3c5cf135aa75f4acdef437a Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Tue, 6 Nov 2012 00:54:09 +0100 Subject: [PATCH] table javascript sorting improvement sorttable 1.2.3.4:123 and *:1234 now sort properly. --- usr/local/www/javascript/sorttable.js | 59 ++++++++++++++++++++------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/usr/local/www/javascript/sorttable.js b/usr/local/www/javascript/sorttable.js index e86ba5d5a7..ce2e68a95c 100644 --- a/usr/local/www/javascript/sorttable.js +++ b/usr/local/www/javascript/sorttable.js @@ -19,6 +19,7 @@ 2012-09-15 Allow for multiple header rows, using "sortableHeaderRowIdentifier" class for the TR that has the column headers. (used in firewall-log) 2012-09-15 Allow sorting multiple dual/mutlti rows together, using sortablemultirow="2" attribute for the table 2012-09-15 Allow sorting of IP:Port texts, changed sort compare function + 2012-11-05 Allow sorting of IP:Port and *:port texts toghether also AAA_23 AAA_123 in 'numeric order' (used in Diagnostics\Sockets column LOCAL) */ @@ -341,11 +342,39 @@ sorttable = { if (dt1 b2match) return 1; + if (a2match < b2match) return -1; + } + if (a[0] == b[0]) return 0; + if (a[0] < b[0]) return -1; return 1; }, + sort_ipaddr: function(a,b) { + aip = ip2ulong(a[0]); + bip = ip2ulong(b[0]); + if (aip && bip) + { + if (aip == bip) return 0; + if (aip < bip) return -1; + return 1; + } else { + if (aip !== false || bip !== false) + return aip === false ? -1 : 1; + else + { + return sorttable.sortWithNumber(a,b); + } + } + }, shaker_sort: function(list, comp_func) { // A stable sort function to allow multi-level sorting of data @@ -386,25 +415,25 @@ sorttable = { function ip2ulong(ip) { ip += ""; var ulip = false; - var octets = []; - ipmatch = ip.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/);// IP only - if (ipmatch) { - ipmatch+=""; - octets = ipmatch.split('.'); + var octets = []; + ipportmatch = ip.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:[0-9]{1,5}\b/);// IP:port + if (ipportmatch) { + ipportmatch += ""; + ipport = ipportmatch.split(':'); + octets = ipport[0].split('.'); for (i=0; i < 4; i++) { ulip += octets[i] * Math.pow(256, (5-i)); } + ulip += parseInt(ipport[1]); } else { - ipportmatch = ip.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:[0-9]{1,5}\b/);// IP:port - if (ipportmatch) { - ipportmatch += ""; - ipport = ipportmatch.split(':'); - octets = ipport[0].split('.'); + ipmatch = ip.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/);// IP only + if (ipmatch) { + ipmatch+=""; + octets = ipmatch.split('.'); for (i=0; i < 4; i++) { ulip += octets[i] * Math.pow(256, (5-i)); } - ulip += parseInt(ipport[1]); - } + } } return ulip; }