
From: Samuel Guimarães <sguimaraes943@gmail.com> Signed-off-by: Samuel Guimarães <sguimaraes943@gmail.com> --- configure.ac | 2 + ui/libs/datatables/js/Makefile.am | 2 + ui/libs/datatables/js/plugins/Makefile.am | 19 ++++ ui/libs/datatables/js/plugins/ip-address/LICENSE | 20 ++++ .../datatables/js/plugins/ip-address/Makefile.am | 21 +++++ .../datatables/js/plugins/ip-address/ip-address.js | 103 +++++++++++++++++++++ ui/pages/wok-ui.html.tmpl | 1 + 7 files changed, 168 insertions(+) create mode 100644 ui/libs/datatables/js/plugins/Makefile.am create mode 100644 ui/libs/datatables/js/plugins/ip-address/LICENSE create mode 100644 ui/libs/datatables/js/plugins/ip-address/Makefile.am create mode 100644 ui/libs/datatables/js/plugins/ip-address/ip-address.js diff --git a/configure.ac b/configure.ac index c7a2787..ff41c84 100644 --- a/configure.ac +++ b/configure.ac @@ -145,6 +145,8 @@ AC_CONFIG_FILES([ ui/libs/moment/Makefile ui/libs/datatables/Makefile ui/libs/datatables/js/Makefile + ui/libs/datatables/js/plugins/Makefile + ui/libs/datatables/js/plugins/ip-address/Makefile ui/libs/datatables/css/Makefile ui/libs/typeahead/Makefile ui/pages/Makefile diff --git a/ui/libs/datatables/js/Makefile.am b/ui/libs/datatables/js/Makefile.am index d50991c..2222ab0 100644 --- a/ui/libs/datatables/js/Makefile.am +++ b/ui/libs/datatables/js/Makefile.am @@ -16,6 +16,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +SUBDIRS = plugins + datatablesjsdir = $(datadir)/wok/ui/libs/datatables/js dist_datatablesjs_DATA = $(wildcard *.js) $(NULL) diff --git a/ui/libs/datatables/js/plugins/Makefile.am b/ui/libs/datatables/js/plugins/Makefile.am new file mode 100644 index 0000000..05cb35f --- /dev/null +++ b/ui/libs/datatables/js/plugins/Makefile.am @@ -0,0 +1,19 @@ +# +# Project Wok +# +# Copyright IBM Corp, 2016 +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SUBDIRS = ip-address diff --git a/ui/libs/datatables/js/plugins/ip-address/LICENSE b/ui/libs/datatables/js/plugins/ip-address/LICENSE new file mode 100644 index 0000000..9ade2f1 --- /dev/null +++ b/ui/libs/datatables/js/plugins/ip-address/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010-2015 SpryMedia Limited +http://datatables.net + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ui/libs/datatables/js/plugins/ip-address/Makefile.am b/ui/libs/datatables/js/plugins/ip-address/Makefile.am new file mode 100644 index 0000000..f823bae --- /dev/null +++ b/ui/libs/datatables/js/plugins/ip-address/Makefile.am @@ -0,0 +1,21 @@ +# +# Project Wok +# +# Copyright IBM Corp, 2016 +# +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +datatablesipaddressjsdir = $(datadir)/wok/ui/libs/datatables/js/plugins/ip-address/ip-address.js + +dist_datatablesipaddressjs_DATA = $(wildcard *.js) $(NULL) diff --git a/ui/libs/datatables/js/plugins/ip-address/ip-address.js b/ui/libs/datatables/js/plugins/ip-address/ip-address.js new file mode 100644 index 0000000..28ff323 --- /dev/null +++ b/ui/libs/datatables/js/plugins/ip-address/ip-address.js @@ -0,0 +1,103 @@ +/** + * Sorts a column containing IP addresses (IPv4 and IPv6) in typical dot + * notation / colon. This can be most useful when using DataTables for a + * networking application, and reporting information containing IP address. + * + * @name IP addresses + * @summary Sort IP addresses numerically + * @author Dominique Fournier + * @author Brad Wasson + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'ip-address', targets: 0 } + * ] + * } ); + */ + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "ip-address-pre": function ( a ) { + var i, item; + var m = a.split("."), + n = a.split(":"), + 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)); + } +}); \ No newline at end of file diff --git a/ui/pages/wok-ui.html.tmpl b/ui/pages/wok-ui.html.tmpl index e238a34..e49b602 100644 --- a/ui/pages/wok-ui.html.tmpl +++ b/ui/pages/wok-ui.html.tmpl @@ -87,6 +87,7 @@ <script src="$href('libs/lodash/lodash.js')"></script> <script src="$href('libs/moment/moment-with-locales.min.js')"></script> <script src="$href('libs/datatables/js/datatables.min.js')"></script> + <script src="$href('libs/datatables/js/plugins/ip-address/ip-address.js')"></script> <script src="$href('base64/jquery.base64.js')"></script> <script src="$href('js/wok.min.js')"></script> <!-- This is used for detecting if the UI needs to be built --> -- 2.5.5