Skip to content

Commit

Permalink
Sort groups alphabetically on the new account and report pages (#8509)
Browse files Browse the repository at this point in the history
Co-authored-by: Jose García <[email protected]>
  • Loading branch information
geonetworkbuild and josegar74 authored Nov 22, 2024
1 parent 5ac3f96 commit 18c2c5e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@
return defer.promise;
};

/**
* Sort an array of elements with translations labels, using the provided language.
*
*/
var sortByTranslation = function (values, sortByLanguage, defaultProperty) {
return Object.values(
// Don't mutate the original array
values.concat().sort(function (a, b) {
var aValue = a.label[sortByLanguage] || a[defaultProperty];
var bValue = b.label[sortByLanguage] || b[defaultProperty];

return aValue.localeCompare(bValue);
})
);
};

return {
scrollTo: scrollTo,
isInView: isInView,
Expand All @@ -452,7 +468,8 @@
randomUuid: randomUuid,
displayPermalink: displayPermalink,
openModal: openModal,
goBack: goBack
goBack: goBack,
sortByTranslation: sortByTranslation
};
}
]);
Expand Down
6 changes: 5 additions & 1 deletion web-ui/src/main/resources/catalog/js/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@
$scope.retrieveGroups = function () {
$http.get("../api/groups").then(
function (response) {
$scope.groups = response.data;
$scope.groups = gnUtilityService.sortByTranslation(
response.data,
$scope.lang,
"name"
);
},
function (response) {}
);
Expand Down
15 changes: 13 additions & 2 deletions web-ui/src/main/resources/catalog/js/admin/ReportController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"$http",
"$rootScope",
"$translate",
function ($scope, $routeParams, $http, $rootScope, $translate) {
"gnUtilityService",
function ($scope, $routeParams, $http, $rootScope, $translate, gnUtilityService) {
$scope.pageMenu = {
folder: "report/",
defaultTab: "report-updated-metadata",
Expand Down Expand Up @@ -150,7 +151,11 @@
if ($scope.user.profile === "Administrator") {
$http.get("../api/groups").then(
function (response) {
$scope.groups = response.data;
$scope.groups = gnUtilityService.sortByTranslation(
response.data,
$scope.lang,
"name"
);
},
function (response) {
// TODO
Expand All @@ -166,6 +171,12 @@
$scope.groups = _.uniqBy(groups, function (e) {
return e.id;
});

$scope.groups = gnUtilityService.sortByTranslation(
$scope.groups,
$scope.lang,
"name"
);
},
function (response) {
// TODO
Expand Down

0 comments on commit 18c2c5e

Please sign in to comment.