1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Merge pull request #2338 from mabashian/instance-modal-search

Updates to instance list and instance modal search
This commit is contained in:
Michael Abashian 2018-06-28 09:15:34 -04:00 committed by GitHub
commit e8748fa147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 39 deletions

View File

@ -1,8 +1,11 @@
function InstanceModalController ($scope, $state, models, strings, ProcessErrors, Wait) { function InstanceModalController ($scope, $state, models, strings, ProcessErrors, Wait) {
const { instance, instanceGroup } = models; const { instance, instanceGroup } = models;
const vm = this || {}; const vm = this || {};
let relatedInstanceIds = [];
vm.setInstances = () => { vm.setInstances = () => {
vm.relatedInstances = [];
vm.selectedRows = [];
vm.instances = instance.get('results').map(instance => { vm.instances = instance.get('results').map(instance => {
instance.isSelected = false; instance.isSelected = false;
return instance; return instance;
@ -12,9 +15,10 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors
vm.setRelatedInstances = () => { vm.setRelatedInstances = () => {
vm.instanceGroupName = instanceGroup.get('name'); vm.instanceGroupName = instanceGroup.get('name');
vm.relatedInstances = instanceGroup.get('related.instances.results'); vm.relatedInstances = instanceGroup.get('related.instances.results');
vm.relatedInstanceIds = vm.relatedInstances.map(instance => instance.id); vm.selectedRows = _.cloneDeep(vm.relatedInstances);
relatedInstanceIds = vm.relatedInstances.map(instance => instance.id);
vm.instances = instance.get('results').map(instance => { vm.instances = instance.get('results').map(instance => {
instance.isSelected = vm.relatedInstanceIds.includes(instance.id); instance.isSelected = relatedInstanceIds.includes(instance.id);
return instance; return instance;
}); });
}; };
@ -26,24 +30,38 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors
vm.panelTitle = strings.get('instance.PANEL_TITLE'); vm.panelTitle = strings.get('instance.PANEL_TITLE');
vm.instanceGroupId = instanceGroup.get('id'); vm.instanceGroupId = instanceGroup.get('id');
vm.dataset = instance.get();
vm.querySet = { order_by: 'hostname', page_size: '5' };
vm.list = {
name: 'instances',
iterator: 'instance',
basePath: `/api/v2/instances/`
};
if (vm.instanceGroupId === undefined) { if (vm.instanceGroupId === undefined) {
vm.setInstances(); vm.setInstances();
} else { } else {
vm.setRelatedInstances(); vm.setRelatedInstances();
} }
}
$scope.$watch('vm.instances', function() { $scope.$watch('vm.instances', function() {
vm.selectedRows = _.filter(vm.instances, 'isSelected'); angular.forEach(vm.instances, function(instance) {
vm.deselectedRows = _.filter(vm.instances, 'isSelected', false); instance.isSelected = _.filter(vm.selectedRows, 'id', instance.id).length > 0;
}, true); });
});
}
vm.submit = () => { vm.submit = () => {
Wait('start'); Wait('start');
const associate = vm.selectedRows const selectedRowIds = vm.selectedRows.map(instance => instance.id);
.map(instance => ({id: instance.id}));
const disassociate = vm.deselectedRows const associate = selectedRowIds.filter(instanceId => {
.map(instance => ({id: instance.id, disassociate: true})); return !relatedInstanceIds.includes(instanceId);
}).map(id => ({id}));
const disassociate = relatedInstanceIds.filter(instanceId => {
return !selectedRowIds.includes(instanceId);
}).map(id => ({id, disassociate: true}));
const all = associate.concat(disassociate); const all = associate.concat(disassociate);
const defers = all.map((data) => { const defers = all.map((data) => {
@ -74,6 +92,24 @@ function InstanceModalController ($scope, $state, models, strings, ProcessErrors
vm.dismiss = () => { vm.dismiss = () => {
$state.go('instanceGroups.instances'); $state.go('instanceGroups.instances');
}; };
vm.toggleRow = (row) => {
if (row.isSelected) {
let matchingIndex;
angular.forEach(vm.selectedRows, function(value, index) {
if(row.id === vm.selectedRows[index].id) {
matchingIndex = index;
}
});
vm.selectedRows.splice(matchingIndex, 1);
row.isSelected = false;
} else {
row.isSelected = true;
vm.selectedRows.push(row);
}
};
} }
InstanceModalController.$inject = [ InstanceModalController.$inject = [

View File

@ -17,12 +17,13 @@
<smart-search <smart-search
class="at-List-search" class="at-List-search"
django-model="instances" django-model="instances"
base-path="instances" base-path="{{vm.list.basePath}}"
iterator="instance" iterator="instance"
list="list" list="vm.list"
dataset="vm.instances" collection="vm.instances"
collection="collection" dataset="vm.dataset"
search-tags="searchTags"> search-tags="vm.searchTags"
query-set="vm.querySet">
</smart-search> </smart-search>
</div> </div>
<at-list results='vm.instances'> <at-list results='vm.instances'>
@ -32,10 +33,10 @@
<input type="checkbox" <input type="checkbox"
class="at-Row-checkbox" class="at-Row-checkbox"
ng-class="{ 'at-Input--rejected': state.rejected }" ng-class="{ 'at-Input--rejected': state.rejected }"
ng-model="instance.isSelected"
ng-checked="instance.isSelected" ng-checked="instance.isSelected"
ng-attr-tabindex="{{ tab || undefined }}" ng-attr-tabindex="{{ tab || undefined }}"
ng-disabled="state._disabled" /> ng-disabled="state._disabled"
ng-click="vm.toggleRow(instance)" />
<div class="at-Row-items" style="flex: 1"> <div class="at-Row-items" style="flex: 1">
<at-row-item <at-row-item

View File

@ -14,12 +14,12 @@
<smart-search <smart-search
class="at-List-search" class="at-List-search"
django-model="instances" django-model="instances"
base-path="{{list.basePath}}" base-path="{{vm.list.basePath}}"
iterator="instance" iterator="instance"
list="list" list="vm.list"
dataset="instance_dataset" collection="vm.instances"
collection="collection" dataset="vm.dataset"
search-tags="searchTags"> search-tags="vm.searchTags">
</smart-search> </smart-search>
<div class="at-List-toolbarAction"> <div class="at-List-toolbarAction">

View File

@ -15,26 +15,13 @@ function InstancesController ($scope, $state, $http, models, strings, Dataset, P
init(); init();
function init() { function init() {
$scope.list = { vm.list = {
name: 'instances', name: 'instances',
iterator: 'instance', iterator: 'instance',
basePath: `/api/v2/instance_groups/${vm.instance_group_id}/instances/` basePath: `/api/v2/instance_groups/${vm.instance_group_id}/instances/`
}; };
$scope.collection = { vm.dataset = Dataset.data;
iterator: 'instance',
basePath: `/api/v2/instance_groups/${vm.instance_group_id}/instances/`
};
$scope[`${$scope.list.iterator}_dataset`] = Dataset.data;
$scope[$scope.list.name] = $scope[`${$scope.list.iterator}_dataset`].results;
$scope.instances = vm.instances;
$scope.$on('updateDataset', function(e, dataset) {
$scope[`${$scope.list.iterator}_dataset`] = dataset;
$scope[$scope.list.name] = dataset.results;
vm.instances = dataset.results;
});
} }
vm.tab = { vm.tab = {