From 59b8ba2a1ca8064b38bd8e7a887348f27ba726c2 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Tue, 11 Apr 2017 13:21:44 -0400 Subject: [PATCH] Fixed copy/move groups/hosts pagination bug --- .../copy-move/copy-move-groups.controller.js | 8 ++-- .../copy-move/copy-move-hosts.controller.js | 8 ++-- .../copy-move/copy-move-list.controller.js | 44 +++++++++++++++++++ .../manage/copy-move/copy-move.route.js | 7 ++- 4 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 awx/ui/client/src/inventories/manage/copy-move/copy-move-list.controller.js diff --git a/awx/ui/client/src/inventories/manage/copy-move/copy-move-groups.controller.js b/awx/ui/client/src/inventories/manage/copy-move/copy-move-groups.controller.js index 9153dad34d..487211fa06 100644 --- a/awx/ui/client/src/inventories/manage/copy-move/copy-move-groups.controller.js +++ b/awx/ui/client/src/inventories/manage/copy-move/copy-move-groups.controller.js @@ -11,11 +11,9 @@ $scope.item = group; $scope.submitMode = $stateParams.groups === undefined ? 'move' : 'copy'; - $scope.toggle_row = function(id){ - // toggle off anything else currently selected - _.forEach($scope.groups, (item) => {return item.id === id ? item.checked = 1 : item.checked = null;}); - // yoink the currently selected thing - $scope.selected = _.find($scope.groups, (item) => {return item.id === id;}); + + $scope.updateSelected = function(selectedGroup) { + $scope.selected = angular.copy(selectedGroup); }; $scope.formCancel = function(){ $state.go('^'); diff --git a/awx/ui/client/src/inventories/manage/copy-move/copy-move-hosts.controller.js b/awx/ui/client/src/inventories/manage/copy-move/copy-move-hosts.controller.js index 5c95523036..098ef23540 100644 --- a/awx/ui/client/src/inventories/manage/copy-move/copy-move-hosts.controller.js +++ b/awx/ui/client/src/inventories/manage/copy-move/copy-move-hosts.controller.js @@ -11,11 +11,9 @@ $scope.item = host; $scope.submitMode = 'copy'; - $scope.toggle_row = function(id){ - // toggle off anything else currently selected - _.forEach($scope.groups, (item) => {return item.id === id ? item.checked = 1 : item.checked = null;}); - // yoink the currently selected thing - $scope.selected = _.find($scope.groups, (item) => {return item.id === id;}); + + $scope.updateSelected = function(selectedGroup) { + $scope.selected = angular.copy(selectedGroup); }; $scope.formCancel = function(){ $state.go('^'); diff --git a/awx/ui/client/src/inventories/manage/copy-move/copy-move-list.controller.js b/awx/ui/client/src/inventories/manage/copy-move/copy-move-list.controller.js new file mode 100644 index 0000000000..e672eae640 --- /dev/null +++ b/awx/ui/client/src/inventories/manage/copy-move/copy-move-list.controller.js @@ -0,0 +1,44 @@ +/************************************************* + * Copyright (c) 2016 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + + export default + ['$scope', 'CopyMoveGroupList', 'Dataset', + function($scope, list, Dataset){ + init(); + + function init() { + $scope.list = list; + $scope[`${list.iterator}_dataset`] = Dataset.data; + $scope[list.name] = $scope[`${list.iterator}_dataset`].results; + + $scope.$watch('groups', function(){ + if($scope.selectedGroup){ + $scope.groups.forEach(function(row, i) { + if(row.id === $scope.selectedGroup.id) { + $scope.groups[i].checked = 1; + } + else { + $scope.groups[i].checked = 0; + } + }); + } + }); + } + + $scope.toggle_row = function(id) { + // toggle off anything else currently selected + _.forEach($scope.groups, (item) => { + if(item.id === id) { + item.checked = 1; + $scope.selectedGroup = item; + $scope.updateSelected(item); + } + else { + item.checked = null; + } + }); + }; + }]; diff --git a/awx/ui/client/src/inventories/manage/copy-move/copy-move.route.js b/awx/ui/client/src/inventories/manage/copy-move/copy-move.route.js index deff0cf0ef..82fd77fee2 100644 --- a/awx/ui/client/src/inventories/manage/copy-move/copy-move.route.js +++ b/awx/ui/client/src/inventories/manage/copy-move/copy-move.route.js @@ -8,6 +8,7 @@ import { N_ } from '../../../i18n'; import CopyMoveGroupsController from './copy-move-groups.controller'; import CopyMoveHostsController from './copy-move-hosts.controller'; +import CopyMoveListController from './copy-move-list.controller'; var copyMoveGroupRoute = { name: 'inventoryManage.copyMoveGroup', @@ -53,7 +54,8 @@ var copyMoveGroupRoute = { input_type: 'radio' }); return html; - } + }, + controller: CopyMoveListController } } }; @@ -90,7 +92,8 @@ var copyMoveHostRoute = { input_type: 'radio' }); return html; - } + }, + controller: CopyMoveListController } } };