support of sorting in route paths

This commit is contained in:
Michele Artini 2024-11-28 12:05:01 +01:00
parent 02655e504a
commit f25d89bc4a
2 changed files with 97 additions and 37 deletions

View File

@ -23,19 +23,19 @@
<tr ng-repeat="e in entries | filter: browseFilter">
<th>{{e.name}} <span ng-if="e.code != e.name"> ({{e.code}})</span></th>
<td class="text-right">
<a href="#!{{resultsBasePath}}/0/50/approved/{{e.code}}" ng-if="e.values.approved && e.values.approved > 0">{{e.values.approved}}</a>
<a href="#!{{resultsBasePath}}/approved/{{e.code}}" ng-if="e.values.approved && e.values.approved > 0">{{e.values.approved}}</a>
<span ng-if="!e.values.approved || e.values.approved == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/suggested/{{e.code}}" ng-if="e.values.suggested && e.values.suggested > 0">{{e.values.suggested}}</a>
<a href="#!{{resultsBasePath}}/suggested/{{e.code}}" ng-if="e.values.suggested && e.values.suggested > 0">{{e.values.suggested}}</a>
<span ng-if="!e.values.suggested || e.values.suggested == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/raw/{{e.code}}" ng-if="e.values.raw && e.values.raw > 0">{{e.values.raw}}</a>
<a href="#!{{resultsBasePath}}/raw/{{e.code}}" ng-if="e.values.raw && e.values.raw > 0">{{e.values.raw}}</a>
<span ng-if="!e.values.raw || e.values.raw == 0">-</span>
</td>
<td class="text-right" ng-if="mode == 1">
<a href="#!{{resultsBasePath}}/0/50/hidden/{{e.code}}" ng-if="e.values.hidden && e.values.hidden > 0">{{e.values.hidden}}</a>
<a href="#!{{resultsBasePath}}/hidden/{{e.code}}" ng-if="e.values.hidden && e.values.hidden > 0">{{e.values.hidden}}</a>
<span ng-if="!e.values.hidden || e.values.hidden == 0">-</span>
</td>
</tr>

View File

@ -212,7 +212,7 @@ orgsModule.directive('orgDetails', function($http, $location, $route) {
}
});
orgsModule.directive('orgResultsPage', function($http, $location, $route) {
orgsModule.directive('orgResultsPage', function($http, $location, $route, $routeParams) {
return {
restrict: 'E',
scope: {
@ -250,9 +250,13 @@ orgsModule.directive('orgResultsPage', function($http, $location, $route) {
for (var i = 0; i < scope.orgs.totalPages; i++) input.push(i);
return input;
}
scope.gotoPage = function(page, pageSize) {
var url = scope.pageFunction().replace(/__PAGE__/, page).replace(/__SIZE__/, pageSize);
scope.gotoPageAndSort = function(page, pageSize, orderBy, orderType) {
var url = scope.pageFunction()
.replace(/__PAGE__/, page)
.replace(/__SIZE__/, pageSize)
.replace(/__ORDER_BY__/, orderBy)
.replace(/__ORDER_TYPE__/, orderType);
if (scope.mode == 'select-modal' || scope.mode == 'multi-select-modal') {
scope.orgs = {};
@ -263,6 +267,11 @@ orgsModule.directive('orgResultsPage', function($http, $location, $route) {
$location.url(url);
}
}
scope.gotoPage = function(page, pageSize) {
scope.gotoPageAndSort(page, pageSize, $routeParams.orderBy, $routeParams.orderType);
}
}
}
@ -402,25 +411,24 @@ orgsModule.directive('orgJournal', function($http) {
}
});
orgsModule.config(function($routeProvider) {
$routeProvider
.when('/search', { templateUrl: 'resources/html/pages/search/search.html', controller: 'searchCtrl' })
.when('/searchResults/:page/:size/:text*', { templateUrl: 'resources/html/pages/search/searchResults.html', controller: 'searchResultsCtrl' })
.when('/countries/:mode', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'countriesCtrl' })
.when('/byCountry/:page/:size/:status/:code*', { templateUrl: 'resources/html/pages/search/resultsByCountry.html', controller: 'byCountryCtrl' })
.when('/types/:mode', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'typesCtrl' })
.when('/byType/:page/:size/:status/:type*', { templateUrl: 'resources/html/pages/search/resultsByType.html', controller: 'byTypeCtrl' })
.when('/edit/:msg/:id*', { templateUrl: 'resources/html/pages/edit/edit.html', controller: 'showEditCtrl' })
.when('/new', { templateUrl: 'resources/html/pages/advanced/new.html', controller: 'newOrgCtrl' })
.when('/pendings/:country', { templateUrl: 'resources/html/pages/advanced/pendingOrgs.html', controller: 'pendingOrgsCtrl' })
.when('/duplicates/:country', { templateUrl: 'resources/html/pages/advanced/duplicates.html', controller: 'duplicatesCtrl' })
.when('/conflicts/:country', { templateUrl: 'resources/html/pages/advanced/conflicts.html', controller: 'conflictsCtrl' })
.when('/users', { templateUrl: 'resources/html/pages/admin/users.html', controller: 'usersCtrl' })
.when('/sysconf', { templateUrl: 'resources/html/pages/admin/sysConf.html', controller: 'sysConfCtrl' })
.when('/utils', { templateUrl: 'resources/html/pages/admin/utils.html', controller: 'utilsCtrl' })
.when('/lastImport', { templateUrl: 'resources/html/pages/admin/lastImport.html', controller: 'lastImportCtrl' })
.when('/persistentOrgs', { templateUrl: 'resources/html/pages/admin/persistentOrgs.html', controller: 'persistentOrgsCtrl' })
.when('/search', { templateUrl: 'resources/html/pages/search/search.html', controller: 'searchCtrl' })
.when('/page/:page/:size/sortBy/:orderBy/:orderType/search/:text*', { templateUrl: 'resources/html/pages/search/searchResults.html', controller: 'searchResultsCtrl' })
.when('/countries/:mode', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'countriesCtrl' })
.when('/page/:page/:size/sortBy/:orderBy/:orderType/byCountry/:status/:code*', { templateUrl: 'resources/html/pages/search/resultsByCountry.html', controller: 'byCountryCtrl' })
.when('/types/:mode', { templateUrl: 'resources/html/pages/search/browse.html', controller: 'typesCtrl' })
.when('/page/:page/:size/sortBy/:orderBy/:orderType/byType/:status/:type*', { templateUrl: 'resources/html/pages/search/resultsByType.html', controller: 'byTypeCtrl' })
.when('/edit/:msg/:id*', { templateUrl: 'resources/html/pages/edit/edit.html', controller: 'showEditCtrl' })
.when('/new', { templateUrl: 'resources/html/pages/advanced/new.html', controller: 'newOrgCtrl' })
.when('/pendings/:country', { templateUrl: 'resources/html/pages/advanced/pendingOrgs.html', controller: 'pendingOrgsCtrl' })
.when('/duplicates/:country', { templateUrl: 'resources/html/pages/advanced/duplicates.html', controller: 'duplicatesCtrl' })
.when('/conflicts/:country', { templateUrl: 'resources/html/pages/advanced/conflicts.html', controller: 'conflictsCtrl' })
.when('/users', { templateUrl: 'resources/html/pages/admin/users.html', controller: 'usersCtrl' })
.when('/sysconf', { templateUrl: 'resources/html/pages/admin/sysConf.html', controller: 'sysConfCtrl' })
.when('/utils', { templateUrl: 'resources/html/pages/admin/utils.html', controller: 'utilsCtrl' })
.when('/lastImport', { templateUrl: 'resources/html/pages/admin/lastImport.html', controller: 'lastImportCtrl' })
.when('/persistentOrgs', { templateUrl: 'resources/html/pages/admin/persistentOrgs.html', controller: 'persistentOrgsCtrl' })
.otherwise({ redirectTo: '/search' });
});
@ -462,9 +470,9 @@ orgsModule.controller('searchCtrl', function ($scope, $location) {
$scope.searchText = '';
$scope.search = function() {
if ($scope.searchText) {
$location.url('/searchResults/0/50/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
$location.url('/page/0/50/sortBy/name/asc/search/' + encodeURIComponent(encodeURIComponent($scope.searchText)));
} else {
$location.url('/searchResults/0/50/_');
$location.url('/page/0/50/sortBy/name/asc/search/_');
}
}
});
@ -476,13 +484,27 @@ orgsModule.controller('searchResultsCtrl', function ($scope, $http, $routeParams
}
$scope.orgs = {};
call_http_get($http, 'api/organizations/search/' + $routeParams.page + '/' + $routeParams.size + '?q=' + $scope.searchText, function(res) { $scope.orgs = res.data; });
var url = 'api/organizations/search/'
+ $routeParams.page
+ '/'
+ $routeParams.size
+ '?q='
+ $scope.searchText
+ '&orderBy='
+ encodeURIComponent($routeParams.orderBy);
if ($routeParams.orderType == 'desc') {
url += "&reverse=true";
}
call_http_get($http, url, function(res) { $scope.orgs = res.data; });
$scope.pageSearch = function() {
if ($scope.searchText) {
return '/searchResults/__PAGE__/__SIZE__/' + encodeURIComponent($scope.searchText);
return '/page/__PAGE__/__SIZE__/sortBy/__ORDER_BY__/__ORDER_TYPE__/search/' + encodeURIComponent($scope.searchText);
} else {
return '/searchResults/__PAGE__/__SIZE__/_';
return '/page/__PAGE__/__SIZE__/sortBy/__ORDER_BY__/__ORDER_TYPE__/search/_';
}
}
@ -492,7 +514,7 @@ orgsModule.controller('countriesCtrl', function ($scope, $http, $routeParams) {
$scope.title = 'Countries';
$scope.field = 'Country';
$scope.resultsBasePath = '/byCountry'
$scope.resultsBasePath = '/page/0/50/sortBy/name/asc/byCountry';
$scope.entries = [];
$scope.mode = $routeParams.mode;
@ -504,18 +526,37 @@ orgsModule.controller('byCountryCtrl', function ($scope, $http, $routeParams, $l
$scope.fieldValue = decodeURIComponent($routeParams.code);
$scope.orgs = {};
call_http_get($http, 'api/organizations/byCountry/' + $routeParams.status + '/' + $routeParams.code + '/' + $routeParams.page + '/' + $routeParams.size, function(res) { $scope.orgs = res.data; });
var url = 'api/organizations/byCountry/'
+ $routeParams.status
+ '/'
+ $routeParams.code
+ '/'
+ $routeParams.page
+ '/'
+ $routeParams.size
+ '?orderBy='
+ encodeURIComponent($routeParams.orderBy)
if ($routeParams.orderType == 'desc') {
url += "&reverse=true";
}
call_http_get($http, url, function(res) { $scope.orgs = res.data; });
$scope.pageByCountry = function() {
return '/byCountry/__PAGE__/__SIZE__/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue);
return '/page/__PAGE__/__SIZE__/sortBy/__ORDER_BY__/__ORDER_TYPE__/byCountry/'
+ $routeParams.status
+ '/'
+ encodeURIComponent($scope.fieldValue);
}
});
orgsModule.controller('typesCtrl', function ($scope, $http, $routeParams) {
$scope.title = 'Organization types';
$scope.field = 'Organization type';
$scope.resultsBasePath = '/byType'
$scope.resultsBasePath = '/page/0/50/sortBy/name/asc/byType';
$scope.entries = [];
$scope.mode = $routeParams.mode;
@ -528,10 +569,29 @@ orgsModule.controller('byTypeCtrl', function ($scope, $http, $routeParams, $loca
$scope.orgs = {};
call_http_get($http, 'api/organizations/byType/' + $routeParams.status + '/' + $routeParams.type + '/' + $routeParams.page + '/' + $routeParams.size, function(res) { $scope.orgs = res.data; });
var url = 'api/organizations/byType/'
+ $routeParams.status
+ '/'
+ $routeParams.type
+ '/'
+ $routeParams.page
+ '/'
+ $routeParams.size
+ '?orderBy='
+ encodeURIComponent($routeParams.orderBy)
if ($routeParams.orderType == 'desc') {
url += "&reverse=true";
}
call_http_get($http, url, function(res) { $scope.orgs = res.data; });
$scope.pageByType = function() {
return '/byType/__PAGE__/__SIZE__/' + $routeParams.status + '/' + encodeURIComponent($scope.fieldValue);
return '/page/__PAGE__/__SIZE__/sortBy/__ORDER_BY__/__ORDER_TYPE__/byType/'
+ $routeParams.status
+ '/'
+ encodeURIComponent($scope.fieldValue);
}
});