mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 10:30:03 -03:30
Merge pull request #1815 from marshmalien/fix/1474-instance-policy-list-search
Hookup instance policy list smart search and add Dataset resolve
This commit is contained in:
commit
64e3323ff5
@ -4,24 +4,29 @@ function InstanceListPolicyLink (scope, el, attrs, controllers) {
|
||||
const instancePolicyController = controllers[0];
|
||||
const formController = controllers[1];
|
||||
const models = scope.$resolve.resolvedModels;
|
||||
const Dataset = scope.$resolve.Dataset;
|
||||
|
||||
instancePolicyController.init(formController, models);
|
||||
instancePolicyController.init(formController, models, Dataset);
|
||||
}
|
||||
|
||||
|
||||
function InstanceListPolicyController ($scope, $state, strings) {
|
||||
const vm = this || {};
|
||||
let form;
|
||||
let instance;
|
||||
let instanceGroup;
|
||||
vm.strings = strings;
|
||||
|
||||
vm.init = (_form_, _models_) => {
|
||||
vm.init = (_form_, _models_, Dataset) => {
|
||||
form = _form_;
|
||||
({ instance, instanceGroup} = _models_);
|
||||
({ instanceGroup } = _models_);
|
||||
|
||||
vm.strings = strings;
|
||||
vm.instanceGroupId = instanceGroup.get('id');
|
||||
vm.defaultParams = { page_size: '10', order_by: 'hostname' };
|
||||
|
||||
$scope.list = {
|
||||
name: 'instances',
|
||||
iterator: 'instance'
|
||||
};
|
||||
$scope.instance_dataset = Dataset.data;
|
||||
$scope.instances = Dataset.data.results;
|
||||
|
||||
if (vm.instanceGroupId === undefined) {
|
||||
vm.setInstances();
|
||||
@ -31,25 +36,24 @@ function InstanceListPolicyController ($scope, $state, strings) {
|
||||
};
|
||||
|
||||
vm.setInstances = () => {
|
||||
vm.instances = instance.get('results').map(instance => {
|
||||
$scope.instances = $scope.instances.map(instance => {
|
||||
instance.isSelected = false;
|
||||
return instance;
|
||||
});
|
||||
};
|
||||
|
||||
vm.setRelatedInstances = () => {
|
||||
vm.instanceGroupName = instanceGroup.get('name');
|
||||
vm.relatedInstances = instanceGroup.get('policy_instance_list');
|
||||
|
||||
vm.instances = instance.get('results').map(instance => {
|
||||
$scope.instances = $scope.instances.map(instance => {
|
||||
instance.isSelected = vm.relatedInstances.includes(instance.hostname);
|
||||
return instance;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$watch('vm.instances', function() {
|
||||
vm.selectedRows = _.filter(vm.instances, 'isSelected');
|
||||
vm.deselectedRows = _.filter(vm.instances, 'isSelected', false);
|
||||
$scope.$watch('instances', function() {
|
||||
vm.selectedRows = _.filter($scope.instances, 'isSelected');
|
||||
vm.deselectedRows = _.filter($scope.instances, 'isSelected', false);
|
||||
}, true);
|
||||
|
||||
vm.submit = () => {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<at-panel-heading>
|
||||
{{:: vm.strings.get('instance.PANEL_TITLE') }}
|
||||
</at-panel-heading>
|
||||
<multi-select-preview selected-rows='vm.selectedRows' available-rows='vm.instances'></multi-select-preview>
|
||||
<multi-select-preview selected-rows='vm.selectedRows' available-rows='instances'></multi-select-preview>
|
||||
<at-panel-body>
|
||||
<div class="at-List-toolbar">
|
||||
<smart-search
|
||||
@ -11,15 +11,15 @@
|
||||
django-model="instances"
|
||||
base-path="instances"
|
||||
iterator="instance"
|
||||
default-params="vm.defaultParams"
|
||||
list="list"
|
||||
dataset="vm.instances"
|
||||
dataset="instance_dataset"
|
||||
collection="collection"
|
||||
search-tags="searchTags">
|
||||
search-tags="searchTags"
|
||||
query-set="querySet">
|
||||
</smart-search>
|
||||
</div>
|
||||
<at-list results='vm.instances'>
|
||||
<at-row ng-repeat="instance in vm.instances"
|
||||
<at-list results='instances'>
|
||||
<at-row ng-repeat="instance in instances"
|
||||
ng-class="{'at-Row--active': (instance.id === vm.activeId)}">
|
||||
|
||||
<input type="checkbox"
|
||||
|
||||
@ -35,15 +35,12 @@ function InstanceGroupsResolve ($q, $stateParams, InstanceGroup, Instance) {
|
||||
|
||||
if (!instanceGroupId && !instanceId) {
|
||||
promises.instanceGroup = new InstanceGroup(['get', 'options']);
|
||||
promises.instance = new Instance(['get', 'options']);
|
||||
|
||||
return $q.all(promises);
|
||||
}
|
||||
|
||||
if (instanceGroupId && instanceId) {
|
||||
promises.instance = new Instance(['get', 'options'], [instanceId, instanceId])
|
||||
.then((instance) => instance.extend('get', 'jobs', {params: {page_size: "10", order_by: "-finished"}}));
|
||||
|
||||
return $q.all(promises);
|
||||
}
|
||||
|
||||
@ -111,6 +108,14 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
ncyBreadcrumb: {
|
||||
label: strings.get('state.ADD_BREADCRUMB_LABEL')
|
||||
},
|
||||
params: {
|
||||
instance_search: {
|
||||
value: {
|
||||
order_by: 'hostname',
|
||||
page_size: '10'
|
||||
}
|
||||
}
|
||||
},
|
||||
views: {
|
||||
'add@instanceGroups': {
|
||||
templateUrl: AddEditTemplate,
|
||||
@ -119,7 +124,17 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
resolvedModels: InstanceGroupsResolve
|
||||
resolvedModels: InstanceGroupsResolve,
|
||||
Dataset: [
|
||||
'$stateParams',
|
||||
'GetBasePath',
|
||||
'QuerySet',
|
||||
($stateParams, GetBasePath, qs) => {
|
||||
const searchParams = $stateParams.instance_search;
|
||||
const searchPath = GetBasePath('instances');
|
||||
return qs.search(searchPath, searchParams);
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
@ -146,8 +161,7 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
"modal": {
|
||||
template: '<instance-list-policy></instance-list-policy>',
|
||||
}
|
||||
},
|
||||
resolvedModels: InstanceGroupsResolve
|
||||
}
|
||||
});
|
||||
|
||||
$stateExtender.addState({
|
||||
@ -156,6 +170,14 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
ncyBreadcrumb: {
|
||||
label: strings.get('state.EDIT_BREADCRUMB_LABEL')
|
||||
},
|
||||
params: {
|
||||
instance_search: {
|
||||
value: {
|
||||
order_by: 'hostname',
|
||||
page_size: '10'
|
||||
}
|
||||
}
|
||||
},
|
||||
views: {
|
||||
'edit@instanceGroups': {
|
||||
templateUrl: AddEditTemplate,
|
||||
@ -164,7 +186,17 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
resolvedModels: InstanceGroupsResolve
|
||||
resolvedModels: InstanceGroupsResolve,
|
||||
Dataset: [
|
||||
'$stateParams',
|
||||
'GetBasePath',
|
||||
'QuerySet',
|
||||
($stateParams, GetBasePath, qs) => {
|
||||
const searchParams = $stateParams.instance_search;
|
||||
const searchPath = GetBasePath('instances');
|
||||
return qs.search(searchPath, searchParams);
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
@ -192,8 +224,7 @@ function InstanceGroupsRun ($stateExtender, strings, ComponentsStrings) {
|
||||
"modal": {
|
||||
template: '<instance-list-policy></instance-list-policy>',
|
||||
}
|
||||
},
|
||||
resolvedModels: InstanceGroupsResolve
|
||||
}
|
||||
});
|
||||
|
||||
$stateExtender.addState({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user