From 77334af55a9c915595d7e820c352f7c4b90be474 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Mon, 30 Jul 2018 09:45:15 -0400 Subject: [PATCH] Fix instance modal pagination and search --- .../instances/instance-modal.controller.js | 34 +++++++------------ .../instances/instance-modal.partial.html | 11 ++++-- .../instances/instances-list.partial.html | 2 +- .../instances/instances.controller.js | 5 +-- awx/ui/client/src/instance-groups/main.js | 21 ++++++++++-- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/awx/ui/client/src/instance-groups/instances/instance-modal.controller.js b/awx/ui/client/src/instance-groups/instances/instance-modal.controller.js index 93400a8ad8..b1fddd782e 100644 --- a/awx/ui/client/src/instance-groups/instances/instance-modal.controller.js +++ b/awx/ui/client/src/instance-groups/instances/instance-modal.controller.js @@ -1,27 +1,17 @@ -function InstanceModalController ($scope, $state, models, strings, ProcessErrors, Wait) { - const { instance, instanceGroup } = models; +function InstanceModalController ($scope, $state, Dataset, models, strings, ProcessErrors, Wait) { + const { instanceGroup } = models; const vm = this || {}; let relatedInstanceIds = []; - vm.setInstances = () => { - vm.relatedInstances = []; - vm.selectedRows = []; - vm.instances = instance.get('results').map(instance => { - instance.isSelected = false; - return instance; - }); - }; - - vm.setRelatedInstances = () => { - vm.instanceGroupName = instanceGroup.get('name'); + function setRelatedInstances () { vm.relatedInstances = instanceGroup.get('related.instances.results'); vm.selectedRows = _.cloneDeep(vm.relatedInstances); relatedInstanceIds = vm.relatedInstances.map(instance => instance.id); - vm.instances = instance.get('results').map(instance => { + vm.instances = vm.instances.map(instance => { instance.isSelected = relatedInstanceIds.includes(instance.id); return instance; }); - }; + } init(); @@ -29,9 +19,9 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors vm.strings = strings; vm.panelTitle = strings.get('instance.PANEL_TITLE'); vm.instanceGroupId = instanceGroup.get('id'); + vm.instanceGroupName = instanceGroup.get('name'); - vm.dataset = instance.get(); - vm.querySet = { order_by: 'hostname', page_size: '5' }; + vm.querySet = $state.params.instance_search; vm.list = { name: 'instances', @@ -39,11 +29,10 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors basePath: `/api/v2/instances/` }; - if (vm.instanceGroupId === undefined) { - vm.setInstances(); - } else { - vm.setRelatedInstances(); - } + vm.instances = Dataset.data.results; + vm.instance_dataset = Dataset.data; + + setRelatedInstances(); $scope.$watch('vm.instances', function() { angular.forEach(vm.instances, function(instance) { @@ -115,6 +104,7 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors InstanceModalController.$inject = [ '$scope', '$state', + 'Dataset', 'resolvedModels', 'InstanceGroupsStrings', 'ProcessErrors', diff --git a/awx/ui/client/src/instance-groups/instances/instance-modal.partial.html b/awx/ui/client/src/instance-groups/instances/instance-modal.partial.html index bc0c2ec263..12179cfa28 100644 --- a/awx/ui/client/src/instance-groups/instances/instance-modal.partial.html +++ b/awx/ui/client/src/instance-groups/instances/instance-modal.partial.html @@ -21,8 +21,9 @@ iterator="instance" list="vm.list" collection="vm.instances" - dataset="vm.dataset" + dataset="vm.instance_dataset" search-tags="vm.searchTags" + default-params="vm.querySet" query-set="vm.querySet" search-bar-full-width="true"> @@ -46,8 +47,14 @@ - + +