This is an automated email from the ASF dual-hosted git repository.
richard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git
The following commit(s) were added to refs/heads/master by this push:
new 91fe3ee persist sort-by information
new daf8992 Merge pull request #175 from frogfather/persist-sort-order
91fe3ee is described below
commit 91fe3ee50b907015c4e069df9b0423b9c1069c59
Author: frogfather <[email protected]>
AuthorDate: Mon Jun 8 11:30:06 2020 +0100
persist sort-by information
---
.../catalog/app/views/catalog/catalog.state.js | 29 +++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/ui-modules/catalog/app/views/catalog/catalog.state.js
b/ui-modules/catalog/app/views/catalog/catalog.state.js
index 0a8713e..f7a6072 100644
--- a/ui-modules/catalog/app/views/catalog/catalog.state.js
+++ b/ui-modules/catalog/app/views/catalog/catalog.state.js
@@ -78,17 +78,26 @@ export function catalogController($scope, $rootScope,
catalogApi, brUtilsGeneral
label: 'Bundle'
}];
+ const savedOrderByKey = 'catalog-order-by';
+
+ const savedOrderBy = localStorage && localStorage.getItem(savedOrderByKey)
!== null ?
+ JSON.parse(localStorage.getItem(savedOrderByKey))
+ : {
+ orderBy: 'bundles',
+ sortBy: 0
+ }
+
$scope.pagination = {
page: 1,
itemsPerPage: 20
};
$scope.config = {
- orderBy: orderBysBundles
+ orderBy: savedOrderBy.orderBy === 'bundles' ? orderBysBundles :
orderBysTypes
};
$scope.state = {
- view: 'bundles',
+ view: savedOrderBy.orderBy,
versions: [],
- orderBy: $scope.config.orderBy[0],
+ orderBy: $scope.config.orderBy.length > savedOrderBy.sortBy ?
$scope.config.orderBy[savedOrderBy.sortBy] : 0,
search: {}
};
@@ -96,6 +105,20 @@ export function catalogController($scope, $rootScope,
catalogApi, brUtilsGeneral
if (newView && oldView && !angular.equals(newView, oldView)) {
$scope.config.orderBy = newView === 'types' ? orderBysTypes :
orderBysBundles;
$scope.state.orderBy = $scope.config.orderBy[0]
+ savedOrderBy.orderBy = newView;
+ savedOrderBy.sortBy = 0;
+ if (localStorage) {
+ localStorage.setItem(savedOrderByKey,
JSON.stringify(savedOrderBy));
+ }
+ }
+ });
+
+ $scope.$watch('state.orderBy', (newOrderBy, oldOrderBy) => {
+ if(newOrderBy && oldOrderBy && !angular.equals(newOrderBy,
oldOrderBy)) {
+ savedOrderBy.sortBy = $scope.config.orderBy.indexOf(newOrderBy);
+ if (localStorage) {
+ localStorage.setItem(savedOrderByKey,
JSON.stringify(savedOrderBy));
+ }
}
});