mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 10:18:57 +00:00
Update order-object-by.js
This commit is contained in:
parent
c09d678ecf
commit
fac3b55e29
@ -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;
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user