Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/96#discussion_r230342561
--- Diff:
ui-modules/blueprint-composer/app/components/catalog-selector/catalog-selector.directive.js
---
@@ -247,11 +266,23 @@ function controller($scope, $element, $timeout, $q,
$uibModal, $log, $templateCa
paletteDragAndDropService.dragEnd();
tryMarkUsed(item);
};
+
$scope.sortBy = function (order) {
- let newOrder = [].concat($scope.state.currentOrder);
- newOrder = newOrder.filter( (o) => o !== order.field );
- $scope.state.currentOrder = [order.field].concat(newOrder);
+ let newFirst = {};
+ if (order) {
+ newFirst[order.id] = order;
+ }
+ $scope.state.currentOrder = Object.assign(newFirst,
$scope.state.currentOrder, newFirst);
+ $scope.state.currentOrderFields = [];
+ $scope.state.currentOrderValues = [];
+ Object.values($scope.state.currentOrder).forEach( it => {
+ $scope.state.currentOrderValues.push(it);
+ $scope.state.currentOrderFields.push(it.field);
+ });
--- End diff --
Instead of creating multiple objects and arrays, you can have only one
array containing sort object that you update with `Array.splice()` and
`Array.unshift()`. This array can then be use to generate the multi sort filter
+ the display on the template.
That would be more efficient that what we currently have
---