From 9cfeadc94475d9c45249495260749d4580fca3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Tue, 29 Oct 2024 14:38:00 +0100 Subject: [PATCH] Sort groups alphabetically on the new account and report pages --- .../components/utility/UtilityService.js | 18 +++++++++++++++++- .../resources/catalog/js/LoginController.js | 6 +++++- .../catalog/js/admin/ReportController.js | 15 +++++++++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/utility/UtilityService.js b/web-ui/src/main/resources/catalog/components/utility/UtilityService.js index 65dcf00babd..32d478f43af 100644 --- a/web-ui/src/main/resources/catalog/components/utility/UtilityService.js +++ b/web-ui/src/main/resources/catalog/components/utility/UtilityService.js @@ -436,6 +436,21 @@ return defer.promise; }; + /** + * Sort an array of elements with translations labels, using the provided language. + * + */ + var sortByTranslation = function (values, sortByLanguage, defaultProperty) { + return Object.values( + values.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, @@ -452,7 +467,8 @@ randomUuid: randomUuid, displayPermalink: displayPermalink, openModal: openModal, - goBack: goBack + goBack: goBack, + sortByTranslation: sortByTranslation }; } ]); diff --git a/web-ui/src/main/resources/catalog/js/LoginController.js b/web-ui/src/main/resources/catalog/js/LoginController.js index 42097136212..15a0a862c6e 100644 --- a/web-ui/src/main/resources/catalog/js/LoginController.js +++ b/web-ui/src/main/resources/catalog/js/LoginController.js @@ -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) {} ); diff --git a/web-ui/src/main/resources/catalog/js/admin/ReportController.js b/web-ui/src/main/resources/catalog/js/admin/ReportController.js index 0178ae06155..13a88062239 100644 --- a/web-ui/src/main/resources/catalog/js/admin/ReportController.js +++ b/web-ui/src/main/resources/catalog/js/admin/ReportController.js @@ -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", @@ -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 @@ -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