diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2012-11-06 00:54:09 +0100 |
---|---|---|
committer | PiBa-NL <pba_2k3@yahoo.com> | 2012-11-06 00:54:09 +0100 |
commit | 426fc7d389248df2a3c5cf135aa75f4acdef437a (patch) | |
tree | 8feb382fdc06255b7f80d2dfb2c832bc4925ac1b /usr/local/www | |
parent | 2ab2d8fbf03333aa1a4cbab6899e016b8f4ec237 (diff) | |
download | pfsense-426fc7d389248df2a3c5cf135aa75f4acdef437a.zip pfsense-426fc7d389248df2a3c5cf135aa75f4acdef437a.tar.gz |
table javascript sorting improvement sorttable 1.2.3.4:123 and *:1234 now sort properly.
Diffstat (limited to 'usr/local/www')
-rw-r--r-- | usr/local/www/javascript/sorttable.js | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/usr/local/www/javascript/sorttable.js b/usr/local/www/javascript/sorttable.js index e86ba5d..ce2e68a 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<dt2) return -1; return 1; }, - sort_ipaddr: function(a,b) { - if (ip2ulong(a[0]) == ip2ulong(b[0])) return 0; - if (ip2ulong(a[0]) < ip2ulong(b[0])) return -1; + sortWithNumber: function(a,b) { + amatch = a[0].match(/.*?(?=[0-9])/); + bmatch = b[0].match(/.*?(?=[0-9])/); + if (amatch && bmatch && amatch[0] == bmatch[0]) + { + anumber = a[0].substring(amatch.length+1); + bnumber = b[0].substring(bmatch.length+1); + a2match = parseInt(anumber.match(/[0-9]*/)); + b2match = parseInt(bnumber.match(/[0-9]*/)); + if (a2match > 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; } |