Skip to content

Commit

Permalink
Use default ordering for tei lists (#1292)
Browse files Browse the repository at this point in the history
* feat: remove default search param order=created:desc

* fix: null checks for sortColumn
  • Loading branch information
superskip committed May 31, 2024
1 parent 817734c commit 8837e3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 4 additions & 9 deletions components/home/lists/lists-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,6 @@ trackerCapture.controller('ListsController',function(
}
$scope.showCustomWorkingListInline = false;
$scope.currentTrackedEntityList = { type: type, config: config, data: data };
if(!$scope.currentTrackedEntityList.sortColumn){
$scope.currentTrackedEntityList.sortColumn = {
id: 'created',
direction: 'desc',
}
}
}

var setCurrentTrackedEntityListData = function(serverResponse){
Expand All @@ -201,7 +195,7 @@ trackerCapture.controller('ListsController',function(



$scope.fetchTeis = function(pager, sortColumn){
$scope.fetchTeis = function(pager){
var s = 1;
if($scope.currentTrackedEntityList){
if($scope.currentTrackedEntityList.type === $scope.trackedEntityListTypes.CUSTOM){
Expand Down Expand Up @@ -395,11 +389,12 @@ trackerCapture.controller('ListsController',function(
sortedTei = sortedTei.concat(data.rows.other);
}
sortedTei = $filter('orderBy')(sortedTei, function(tei) {
var id = $scope.currentTrackedEntityList.sortColumn ? $scope.currentTrackedEntityList.sortColumn.id : 'created';
if($scope.currentTrackedEntityList.sortColumn && $scope.currentTrackedEntityList.sortColumn.valueType === 'date'){
var d = tei[$scope.currentTrackedEntityList.sortColumn.id];
var d = tei[id];
return DateUtils.getDate(d);
}
return tei[$scope.currentTrackedEntityList.sortColumn.id];
return tei[id];
}, $scope.currentTrackedEntityList.direction == 'desc');

angular.forEach(sortedTei, function(tei){
Expand Down
10 changes: 6 additions & 4 deletions scripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
}
return eventUrl;
}
var getCachedMultipleEventFiltersData = function(workingList, pager, sortColumn){
var getCachedMultipleEventFiltersData = function(workingList, pager){
var cachedData = cachedMultipleEventFiltersData[workingList.name];
if(!pager) pager = { page: 1, pageSize: 50, pageCount: Math.ceil(cachedData.rows.length/50)};
var pageEnd = (pager.pageSize*pager.page);
Expand Down Expand Up @@ -2793,13 +2793,15 @@ var trackerCaptureServices = angular.module('trackerCaptureServices', ['ngResour
existing[d[0]] = true;
return true;
});
var sortColumnIndex = data.headers.findIndex(function(h){ return h.name === sortColumn.id});
if(sortColumnIndex) data.rows = orderByKeyFilter(data.rows, sortColumnIndex, sortColumn.direction);
if (sortColumn) {
var sortColumnIndex = data.headers.findIndex(function(h){ return h.name === sortColumn.id});
if(sortColumnIndex) data.rows = orderByKeyFilter(data.rows, sortColumnIndex, sortColumn.direction);
}
//order list
cachedMultipleEventFiltersData[workingList.name] = data;
workingList.cachedSorting = searchParams.sortUrl;
workingList.cachedOrgUnit = searchParams.orgUnitId;
var data = getCachedMultipleEventFiltersData(workingList, pager, sortColumn);
var data = getCachedMultipleEventFiltersData(workingList, pager);
def.resolve(data);
});
}
Expand Down

0 comments on commit 8837e3f

Please sign in to comment.