From 0f4b6dd80c7e2d4468025486e7b0dc58505125d4 Mon Sep 17 00:00:00 2001 From: thuva4 Date: Sat, 10 Mar 2018 00:10:46 +0530 Subject: Add sorting service to module Show the results in sorted order Provide options to sort the results by fields in pods and project page Change-Id: I9b73fbe98146d4bdf9edbb4a3ef3b3e0717500a7 qSigned-off-by: thuva4 --- .../ui/components/pods/podsController.js | 29 +++------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'testapi/opnfv_testapi/ui/components/pods/podsController.js') diff --git a/testapi/opnfv_testapi/ui/components/pods/podsController.js b/testapi/opnfv_testapi/ui/components/pods/podsController.js index 95e970d..f405ecb 100644 --- a/testapi/opnfv_testapi/ui/components/pods/podsController.js +++ b/testapi/opnfv_testapi/ui/components/pods/podsController.js @@ -21,7 +21,7 @@ PodsController.$inject = [ '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl','raiseAlert', - 'confirmModal', 'keepState' + 'confirmModal', 'keepState', 'sortService' ]; /** @@ -30,7 +30,7 @@ * through pods declared in TestAPI. */ function PodsController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl, - raiseAlert, confirmModal, keepState) { + raiseAlert, confirmModal, keepState, sortService) { var ctrl = this; ctrl.url = testapiApiUrl + '/pods'; ctrl.checkBox = [] @@ -50,29 +50,8 @@ ctrl.sortBy = sortBy function sortBy(field){ - if(ctrl.sorting[field]){ - ctrl.data.pods.sort(function(a,b) { - if (a[field].toLowerCase() > b[field].toLowerCase()) { - return -1; - } - if (a[field].toLowerCase() < b[field].toLowerCase()) { - return 1; - } - return 0; - }); - ctrl.sorting[field] = false - }else{ - ctrl.data.pods.sort(function(a,b) { - if (a[field].toLowerCase() < b[field].toLowerCase()) { - return -1; - } - if (a[field].toLowerCase() > b[field].toLowerCase()) { - return 1; - } - return 0; - }); - ctrl.sorting[field] = true - } + ctrl.data.pods = sortService.sortFunction(ctrl.data.pods, field , ctrl.sorting[field] ) + ctrl.sorting[field]=!ctrl.sorting[field] } /** -- cgit 1.2.3-korg