From 6f53d1a35a3abff6a660486801984ca8ee2ee51d Mon Sep 17 00:00:00 2001 From: Romain Date: Wed, 15 Feb 2017 23:08:18 +0100 Subject: [PATCH] feat (container): remember selection when refreshing a list view (#151) (#567) --- app/components/containers/containersController.js | 8 ++++++-- app/services/entityListService.js | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/services/entityListService.js diff --git a/app/components/containers/containersController.js b/app/components/containers/containersController.js index 59f8caa6b..93089e3da 100644 --- a/app/components/containers/containersController.js +++ b/app/components/containers/containersController.js @@ -1,6 +1,6 @@ angular.module('containers', []) -.controller('ContainersController', ['$scope', '$filter', 'Container', 'ContainerHelper', 'Info', 'Settings', 'Messages', 'Config', 'Pagination', -function ($scope, $filter, Container, ContainerHelper, Info, Settings, Messages, Config, Pagination) { +.controller('ContainersController', ['$scope', '$filter', 'Container', 'ContainerHelper', 'Info', 'Settings', 'Messages', 'Config', 'Pagination', 'EntityListService', +function ($scope, $filter, Container, ContainerHelper, Info, Settings, Messages, Config, Pagination, EntityListService) { $scope.state = {}; $scope.state.pagination_count = Pagination.getPaginationCount('containers'); $scope.state.displayAll = Settings.displayAll; @@ -29,6 +29,10 @@ function ($scope, $filter, Container, ContainerHelper, Info, Settings, Messages, var model = new ContainerViewModel(container); model.Status = $filter('containerstatus')(model.Status); + EntityListService.rememberPreviousSelection($scope.containers, model, function onSelect(model){ + $scope.selectItem(model); + }); + if (model.IP) { $scope.state.displayIP = true; } diff --git a/app/services/entityListService.js b/app/services/entityListService.js new file mode 100644 index 000000000..f3eeb86f8 --- /dev/null +++ b/app/services/entityListService.js @@ -0,0 +1,15 @@ +angular.module('portainer.services') +.factory('EntityListService', [function EntityListServiceFactory() { + 'use strict'; + return { + rememberPreviousSelection: function(oldContainerList, model, onSelectCallback) { + var oldModel = _.find(oldContainerList, function(item){ + return item.Id === model.Id; + }); + if (oldModel && oldModel.Checked) { + model.Checked = true; + onSelectCallback(model); + } + } + }; +}]);