diff --git a/public/services/order-object-by.js b/public/services/order-object-by.js index b6bf4c899..2cc1bb59f 100644 --- a/public/services/order-object-by.js +++ b/public/services/order-object-by.js @@ -3,8 +3,8 @@ * Copyright (C) 2018 Wazuh, Inc. * * Copyright (C) 2015 Fabricio Quagliariello. - * Original source code under the MIT license. - * Code available here: https://github.com/fmquaglia/ngOrderObjectBy + * Source code available under the MIT License. + * More information here: https://github.com/fmquaglia/ngOrderObjectBy * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,47 +17,47 @@ import { uiModules } from 'ui/modules' uiModules.get('app/wazuh', []) -.filter('orderObjectBy', function() { - return function (items, field, reverse) { + .filter('orderObjectBy', function() { + return function(items, field, reverse) { - function isNumeric(n) { - return !isNaN(parseFloat(n)) && isFinite(n); - } + function isNumeric(n) { + return !isNaN(parseFloat(n)) && isFinite(n); + } - var filtered = []; + var filtered = []; - angular.forEach(items, function(item, key) { - item.key = key; - filtered.push(item); + angular.forEach(items, function(item, key) { + item.key = key; + filtered.push(item); + }); + + function index(obj, i) { + return obj[i]; + } + + filtered.sort(function(a, b) { + var comparator; + var reducedA = field.split('.').reduce(index, a); + var reducedB = field.split('.').reduce(index, b); + + if (isNumeric(reducedA) && isNumeric(reducedB)) { + reducedA = Number(reducedA); + reducedB = Number(reducedB); + } + + if (reducedA === reducedB) { + comparator = 0; + } else { + comparator = reducedA > reducedB ? 1 : -1; + } + + return comparator; + }); + + if (reverse) { + filtered.reverse(); + } + + return filtered; + }; }); - - function index(obj, i) { - return obj[i]; - } - - filtered.sort(function (a, b) { - var comparator; - var reducedA = field.split('.').reduce(index, a); - var reducedB = field.split('.').reduce(index, b); - - if (isNumeric(reducedA) && isNumeric(reducedB)) { - reducedA = Number(reducedA); - reducedB = Number(reducedB); - } - - if (reducedA === reducedB) { - comparator = 0; - } else { - comparator = reducedA > reducedB ? 1 : -1; - } - - return comparator; - }); - - if (reverse) { - filtered.reverse(); - } - - return filtered; - }; -});