From 8dd9da2cd31240dc3c02f08b72380eb2c1c28a75 Mon Sep 17 00:00:00 2001 From: juanmont Date: Sun, 30 Oct 2016 12:01:04 +0100 Subject: [PATCH 1/2] B #4799 Sunstone sort by IP --- src/sunstone/public/app/app.js | 115 ++++++++++++++++++ .../public/app/tabs/vms-tab/datatable.js | 1 + 2 files changed, 116 insertions(+) diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index 7c4e5733db..b822249c45 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -176,8 +176,17 @@ define(function(require) { }); } + function _checkIP( sData ) + { + if (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(sData)) { + return 'ip-address'; + } + return null; + } + function _setupDataTableSearch() { $.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) { + console.log("hola"); var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i ); var multipliers = { B: 1, @@ -188,6 +197,7 @@ define(function(require) { PB: 1125899906842624 }; + if (matches) { var multiplier = multipliers[matches[2]]; return parseFloat( matches[1] ) * multiplier; @@ -195,5 +205,110 @@ define(function(require) { return -1; } } + + //source https://cdn.datatables.net/plug-ins/1.10.12/type-detection/ip-address.js (modified) + jQuery.fn.dataTableExt.aTypes.unshift( + function ( sData ) + { + if (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(sData)) { + return 'ip-address'; + } + return 'ip-address'; + } + ); + + //source https://datatables.net/plug-ins/sorting/ip-address (modified) + jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "ip-address-pre": function ( a ) { + var ip = a.split("
"); + var i, item; + if(ip.length == 1){ + var m = a.split("."), + n = a.split(":"); + } + else if(ip.length > 1){ + var m = ip[0].split("."), + n = ip[0].split(":"); + } + var x = "", + xa = ""; + + if (m.length == 4) { + // IPV4 + for(i = 0; i < m.length; i++) { + item = m[i]; + + if(item.length == 1) { + x += "00" + item; + } + else if(item.length == 2) { + x += "0" + item; + } + else { + x += item; + } + } + } + else if (n.length > 0) { + // IPV6 + var count = 0; + for(i = 0; i < n.length; i++) { + item = n[i]; + + if (i > 0) { + xa += ":"; + } + + if(item.length === 0) { + count += 0; + } + else if(item.length == 1) { + xa += "000" + item; + count += 4; + } + else if(item.length == 2) { + xa += "00" + item; + count += 4; + } + else if(item.length == 3) { + xa += "0" + item; + count += 4; + } + else { + xa += item; + count += 4; + } + } + + // Padding the :: + n = xa.split(":"); + var paddDone = 0; + + for (i = 0; i < n.length; i++) { + item = n[i]; + + if (item.length === 0 && paddDone === 0) { + for (var padding = 0 ; padding < (32-count) ; padding++) { + x += "0"; + paddDone = 1; + } + } + else { + x += item; + } + } + } + + return x; + }, + + "ip-address-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "ip-address-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +}); } }); diff --git a/src/sunstone/public/app/tabs/vms-tab/datatable.js b/src/sunstone/public/app/tabs/vms-tab/datatable.js index 9c9d336c54..63b84b9e3b 100644 --- a/src/sunstone/public/app/tabs/vms-tab/datatable.js +++ b/src/sunstone/public/app/tabs/vms-tab/datatable.js @@ -59,6 +59,7 @@ define(function(require) { "bSortClasses" : false, "bDeferRender": true, "aoColumnDefs": [ + {"sType": "ip-address", "aTargets": [0]}, {"bSortable": false, "aTargets": ["check", 6, 7, 11]}, {"sWidth": "35px", "aTargets": [0]}, {"bVisible": true, "aTargets": SunstoneConfig.tabTableColumns(TAB_NAME)}, From e9fa4cb3c5de35749d07918f70eaa72371e4b348 Mon Sep 17 00:00:00 2001 From: juanmont Date: Wed, 9 Nov 2016 19:45:04 +0100 Subject: [PATCH 2/2] removed console.log --- src/sunstone/public/app/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sunstone/public/app/app.js b/src/sunstone/public/app/app.js index b822249c45..339811253a 100644 --- a/src/sunstone/public/app/app.js +++ b/src/sunstone/public/app/app.js @@ -186,7 +186,6 @@ define(function(require) { function _setupDataTableSearch() { $.fn.dataTable.ext.type.order['file-size-pre'] = function ( data ) { - console.log("hola"); var matches = data.match( /^(\d+(?:\.\d+)?)\s*([a-z]+)/i ); var multipliers = { B: 1,