From ba54a3aa18859272b02507f29d92a69512b1c12a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 31 Mar 2022 18:06:06 +0000 Subject: [PATCH] GUACAMOLE-462: Request correct sort order from REST API when searching history. --- .../guacSettingsConnectionHistory.js | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/settings/directives/guacSettingsConnectionHistory.js b/guacamole/src/main/frontend/src/app/settings/directives/guacSettingsConnectionHistory.js index 58ffca938..f52fc0f9d 100644 --- a/guacamole/src/main/frontend/src/app/settings/directives/guacSettingsConnectionHistory.js +++ b/guacamole/src/main/frontend/src/app/settings/directives/guacSettingsConnectionHistory.js @@ -89,6 +89,37 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function 'entry.remoteHost' ]); + /** + * The names of sortable properties supported by the REST API that + * correspond to the properties that may be stored within + * $scope.order. + * + * @type {!Object.} + */ + const apiSortProperties = { + 'entry.startDate' : 'startDate', + '-entry.startDate' : '-startDate' + }; + + /** + * Converts the given sort predicate to a correponding array of + * sortable properties supported by the REST API. Any properties + * within the predicate that are not supported will be dropped. + * + * @param {!string[]} predicate + * The sort predicate to convert, as exposed by the predicate + * property of SortOrder. + * + * @returns {!string[]} + * A corresponding array of sortable properties, omitting any + * properties not supported by the REST API. + */ + var toAPISortPredicate = function toAPISortPredicate(predicate) { + return predicate + .map((name) => apiSortProperties[name]) + .filter((name) => !!name); + }; + // Get session date format $translate('SETTINGS_CONNECTION_HISTORY.FORMAT_DATE') .then(function dateFormatReceived(retrievedDateFormat) { @@ -166,9 +197,7 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function historyService.getConnectionHistory( $scope.dataSource, requiredContents, - $scope.order.predicate.filter(function isSupportedPredicate(predicate) { - return predicate === 'startDate' || predicate === '-startDate'; - }) + toAPISortPredicate($scope.order.predicate) ) .then(function historyRetrieved(historyEntries) {