Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes api list wrong sorting #261

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion public/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
}
}

const sortByTimestamp = (a,b) => {
const intA = parseInt(a._id);
const intB = parseInt(b._id);
return intA > intB ? -1 : intA < intB ? 1 : 0;
};

// Set default API
$scope.setDefault = (item) => {
let index = $scope.apiEntries.indexOf(item);
Expand Down Expand Up @@ -144,8 +150,9 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
try {
const data = await genericReq.request('GET', '/api/wazuh-api/apiEntries');
for(const entry of data.data) $scope.showEditForm[entry._id] = false;

$scope.apiEntries = data.data.length > 0 ? data.data : [];
$scope.apiEntries = $scope.apiEntries.sort(sortByTimestamp);
if (appState.getCurrentAPI() !== undefined && appState.getCurrentAPI() !== null)
$scope.currentDefault = JSON.parse(appState.getCurrentAPI()).id;
if(!$scope.$$phase) $scope.$digest();
Expand Down Expand Up @@ -247,6 +254,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
};

$scope.apiEntries.push(newEntry);
$scope.apiEntries = $scope.apiEntries.sort(sortByTimestamp);

errorHandler.info('Wazuh API successfully added','Settings');
$scope.addManagerContainer = false;
Expand Down Expand Up @@ -328,6 +336,7 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
$scope.apiEntries[index]._source.api_port = tmpData.port;
$scope.apiEntries[index]._source.api_user = tmpData.user;

$scope.apiEntries = $scope.apiEntries.sort(sortByTimestamp);
$scope.showEditForm[$scope.apiEntries[index]._id] = false;

errorHandler.info('Connection success','Settings');
Expand Down