diff --git a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js index 818e1890d2..7b995e7f6a 100644 --- a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js +++ b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js @@ -31,195 +31,32 @@ export default ['$state', '$stateParams', '$scope', 'GroupForm', field_id: 'group_variables', variable: 'variables', }); - initSources(); } - $scope.lookupCredential = function(){ - let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; - $state.go('.credential', { - credential_search: { - kind: kind, - page_size: '5', - page: '1' - } - }); - }; - $scope.formCancel = function() { $state.go('^'); }; $scope.formSave = function() { - var params, source, json_data; + var json_data; json_data = ToJSON($scope.parseType, $scope.variables, true); - // group fields + var group = { variables: json_data, name: $scope.name, description: $scope.description, inventory: inventoryData.id }; - if ($scope.source) { - // inventory_source fields - params = { - instance_filters: $scope.instance_filters, - source_vars: $scope[$scope.source.value + '_variables'] === '---' || $scope[$scope.source.value + '_variables'] === '{}' ? null : $scope[$scope.source.value + '_variables'], - source_script: $scope.inventory_script, - source: $scope.source.value, - credential: $scope.credential, - overwrite: $scope.overwrite, - overwrite_vars: $scope.overwrite_vars, - update_on_launch: $scope.update_on_launch, - update_cache_timeout: $scope.update_cache_timeout || 0, - // comma-delimited strings - group_by: _.map($scope.group_by, 'value').join(','), - source_regions: _.map($scope.source_regions, 'value').join(',') - }; - source = $scope.source.value; - } else { - source = null; - } - switch (source) { - // no inventory source set, just create a new group - // '' is the value supplied for Manual source type - case null || '': - GroupManageService.post(group).then(res => { - // associate - if ($stateParams.group) { - return GroupManageService.associateGroup(res.data, _.last($stateParams.group)) - .then(() => $state.go('^', null, { reload: true })); - } else { - $state.go('^', null, { reload: true }); - } - }); - break; - // create a new group and create/associate an inventory source - // equal to case 'rax' || 'ec2' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack' || 'custom' - default: - GroupManageService.post(group) - // associate to group - .then(res => { - if ($stateParams.group) { - GroupManageService.associateGroup(res.data, _.last($stateParams.group)); - return res; - } else { - return res; } - // pass the original POST response and not the association response - }) - .then(res => GroupManageService.putInventorySource( - // put the received group ID into inventory source payload - // and pass the related endpoint - _.assign(params, { group: res.data.id }), res.data.related.inventory_source)) - .then(res => $state.go('inventoryManage.editGroup', { group_id: res.data.group }, { reload: true })); - break; - } + + GroupManageService.post(group).then(res => { + if ($stateParams.group) { + return GroupManageService.associateGroup(res.data, _.last($stateParams.group)) + .then(() => $state.go('^', null, { reload: true })); + } else { + $state.go('inventoryManage.editGroup', { group_id: res.data.group }, { reload: true }); + } + }); + }; - $scope.sourceChange = function(source) { - source = source.value; - if (source === 'custom'){ - $scope.credentialBasePath = GetBasePath('inventory_script'); - } - // equal to case 'ec2' || 'rax' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack' - else{ - $scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?kind=aws' : GetBasePath('credentials') + (source === '' ? '' : '?kind=' + (source)); - } - if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack') { - ParseTypeChange({ - scope: $scope, - field_id: source + '_variables', - variable: source + '_variables', - parse_variable: 'envParseType' - }); - } - - // reset fields - $scope.group_by_choices = source === 'ec2' ? $scope.ec2_group_by : null; - // azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint - $scope.source_region_choices = source === 'azure_rm' ? $scope.azure_regions : $scope[source + '_regions']; - $scope.cloudCredentialRequired = source !== '' && source !== 'custom' && source !== 'ec2' ? true : false; - $scope.group_by = null; - $scope.source_regions = null; - $scope.credential = null; - $scope.credential_name = null; - initRegionSelect(); - }; - // region / source options callback - $scope.$on('choicesReadyGroup', function() { - initRegionSelect(); - }); - - $scope.$on('sourceTypeOptionsReady', function() { - initSourceSelect(); - }); - - function initRegionSelect(){ - CreateSelect2({ - element: '#group_source_regions', - multiple: true - }); - CreateSelect2({ - element: '#group_group_by', - multiple: true - }); - } - function initSourceSelect(){ - CreateSelect2({ - element: '#group_source', - multiple: false - }); - } - - function initSources(){ - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'rax_regions', - choice_name: 'rax_region_choices', - callback: 'choicesReadyGroup' - }); - - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'ec2_regions', - choice_name: 'ec2_region_choices', - callback: 'choicesReadyGroup' - }); - - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'gce_regions', - choice_name: 'gce_region_choices', - callback: 'choicesReadyGroup' - }); - - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'azure_regions', - choice_name: 'azure_region_choices', - callback: 'choicesReadyGroup' - }); - - // Load options for group_by - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'group_by', - variable: 'ec2_group_by', - choice_name: 'ec2_group_by_choices', - callback: 'choicesReadyGroup' - }); - GetSourceTypeOptions({ - scope: $scope, - variable: 'source_type_options', - //callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref - }); - } } ]; diff --git a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js index 1355d5d33f..27f444d69a 100644 --- a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js +++ b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js @@ -5,9 +5,9 @@ *************************************************/ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbacUiControlService', 'ToJSON', - 'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'groupData', 'inventorySourceData', + 'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'groupData', function($state, $stateParams, $scope, ParseVariableString, rbacUiControlService, ToJSON, - ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, groupData, inventorySourceData) { + ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, groupData) { init(); @@ -16,17 +16,8 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbac .then(function(canAdd) { $scope.canAdd = canAdd; }); - // instantiate expected $scope values from inventorySourceData & groupData - _.assign($scope, { credential: inventorySourceData.credential }, { overwrite: inventorySourceData.overwrite }, { overwrite_vars: inventorySourceData.overwrite_vars }, { update_on_launch: inventorySourceData.update_on_launch }, { update_cache_timeout: inventorySourceData.update_cache_timeout }, { instance_filters: inventorySourceData.instance_filters }, { inventory_script: inventorySourceData.source_script }); - if (inventorySourceData.credential) { - $scope.credential_name = inventorySourceData.summary_fields.credential.name; - } - $scope = angular.extend($scope, groupData); - // display custom inventory_script name - if (inventorySourceData.source === 'custom') { - $scope.inventory_script_name = inventorySourceData.summary_fields.source_script.name; - } + $scope = angular.extend($scope, groupData); $scope.$watch('summary_fields.user_capabilities.edit', function(val) { $scope.canAdd = val; @@ -43,36 +34,14 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbac variable: 'variables', }); - initSources(); } - var initRegionSelect = function() { - CreateSelect2({ - element: '#group_source_regions', - multiple: true - }); - CreateSelect2({ - element: '#group_group_by', - multiple: true - }); - }; - - $scope.lookupCredential = function(){ - let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value; - $state.go('.credential', { - credential_search: { - kind: kind, - page_size: '5', - page: '1' - } - }); - }; - $scope.formCancel = function() { $state.go('^'); }; + $scope.formSave = function() { - var params, source, json_data; + var json_data; json_data = ToJSON($scope.parseType, $scope.variables, true); // group fields var group = { @@ -82,166 +51,8 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbac inventory: $scope.inventory, id: groupData.id }; - if ($scope.source) { - // inventory_source fields - params = { - group: groupData.id, - source: $scope.source.value, - credential: $scope.credential, - overwrite: $scope.overwrite, - overwrite_vars: $scope.overwrite_vars, - source_script: $scope.inventory_script, - update_on_launch: $scope.update_on_launch, - update_cache_timeout: $scope.update_cache_timeout || 0, - // comma-delimited strings - group_by: _.map($scope.group_by, 'value').join(','), - source_regions: _.map($scope.source_regions, 'value').join(','), - instance_filters: $scope.instance_filters, - source_vars: $scope[$scope.source.value + '_variables'] === '---' || $scope[$scope.source.value + '_variables'] === '{}' ? null : $scope[$scope.source.value + '_variables'] - }; - source = $scope.source.value; - } else { - source = null; - } - switch (source) { - // no inventory source set, just create a new group - // '' is the value supplied for Manual source type - case null || '': - GroupManageService.put(group).then(() => $state.go($state.current, null, { reload: true })); - break; - // create a new group and create/associate an inventory source - // equal to case 'rax' || 'ec2' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack' || 'custom' - default: - GroupManageService.put(group) - .then(() => GroupManageService.putInventorySource(params, groupData.related.inventory_source)) - .then(() => $state.go($state.current, null, { reload: true })); - break; - } + GroupManageService.put(group).then(() => $state.go($state.current, null, { reload: true })); }; - $scope.sourceChange = function(source) { - $scope.source = source; - if (source.value === 'ec2' || source.value === 'custom' || - source.value === 'vmware' || source.value === 'openstack') { - $scope[source.value + '_variables'] = $scope[source.value + '_variables'] === (null || undefined) ? '---' : $scope[source.value + '_variables']; - ParseTypeChange({ - scope: $scope, - field_id: source.value + '_variables', - variable: source.value + '_variables', - parse_variable: 'envParseType', - }); - } - // reset fields - // azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint - $scope.source_region_choices = source.value === 'azure_rm' ? $scope.azure_regions : $scope[source.value + '_regions']; - $scope.cloudCredentialRequired = source.value !== '' && source.value !== 'custom' && source.value !== 'ec2' ? true : false; - $scope.group_by = null; - $scope.source_regions = null; - $scope.credential = null; - $scope.credential_name = null; - initRegionSelect(); - }; - - function initSourceSelect() { - $scope.source = _.find($scope.source_type_options, { value: inventorySourceData.source }); - CreateSelect2({ - element: '#group_source', - multiple: false - }); - // After the source is set, conditional fields will be visible - // CodeMirror is buggy if you instantiate it in a not-visible element - // So we initialize it here instead of the init() routine - if (inventorySourceData.source === 'ec2' || inventorySourceData.source === 'openstack' || - inventorySourceData.source === 'custom' || inventorySourceData.source === 'vmware') { - $scope[inventorySourceData.source + '_variables'] = inventorySourceData.source_vars === null || inventorySourceData.source_vars === '' ? '---' : ParseVariableString(inventorySourceData.source_vars); - ParseTypeChange({ - scope: $scope, - field_id: inventorySourceData.source + '_variables', - variable: inventorySourceData.source + '_variables', - parse_variable: 'envParseType', - }); - } - } - - function initRegionData() { - var source = $scope.source.value === 'azure_rm' ? 'azure' : $scope.source.value; - var regions = inventorySourceData.source_regions.split(','); - // azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint - $scope.source_region_choices = $scope[source + '_regions']; - - // the API stores azure regions as all-lowercase strings - but the azure regions received from OPTIONS are Snake_Cased - if (source === 'azure') { - $scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value.toLowerCase() === region)); - } - // all other regions are 1-1 - else { - $scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value === region)); - } - $scope.group_by_choices = source === 'ec2' ? $scope.ec2_group_by : null; - if (source === 'ec2') { - var group_by = inventorySourceData.group_by.split(','); - $scope.group_by = _.map(group_by, (item) => _.find($scope.ec2_group_by, { value: item })); - } - initRegionSelect(); - } - - function initSources() { - GetSourceTypeOptions({ - scope: $scope, - variable: 'source_type_options', - //callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref - }); - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'rax_regions', - choice_name: 'rax_region_choices', - callback: 'choicesReadyGroup' - }); - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'ec2_regions', - choice_name: 'ec2_region_choices', - callback: 'choicesReadyGroup' - }); - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'gce_regions', - choice_name: 'gce_region_choices', - callback: 'choicesReadyGroup' - }); - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'source_regions', - variable: 'azure_regions', - choice_name: 'azure_region_choices', - callback: 'choicesReadyGroup' - }); - GetChoices({ - scope: $scope, - url: GetBasePath('inventory_sources'), - field: 'group_by', - variable: 'ec2_group_by', - choice_name: 'ec2_group_by_choices', - callback: 'choicesReadyGroup' - }); - } - - // region / source options callback - $scope.$on('choicesReadyGroup', function() { - if (angular.isObject($scope.source)) { - initRegionData(); - } - }); - - $scope.$on('sourceTypeOptionsReady', function() { - initSourceSelect(); - }); } ]; diff --git a/awx/ui/client/src/inventories/groups/groups.form.js b/awx/ui/client/src/inventories/groups/groups.form.js index bdf9df2353..5199e7bb34 100644 --- a/awx/ui/client/src/inventories/groups/groups.form.js +++ b/awx/ui/client/src/inventories/groups/groups.form.js @@ -11,329 +11,69 @@ */ export default { + addTitle: 'CREATE GROUP', + editTitle: '{{ name }}', + showTitle: true, + name: 'group', + basePath: 'groups', + parent: 'inventories.edit.groups', + // the parent node this generated state definition tree expects to attach to + stateTree: 'inventories', + // form generator inspects the current state name to determine whether or not to set an active (.is-selected) class on a form tab + // this setting is optional on most forms, except where the form's edit state name is not parentStateName.edit + activeEditState: 'inventories.edit.groups.editGroup', + detailsClick: "$state.go('inventories.edit.groups.editGroup')", + well: false, + fields: { + name: { + label: 'Name', + type: 'text', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + required: true, + tab: 'properties' + }, + description: { + label: 'Description', + type: 'text', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + tab: 'properties' + }, + variables: { + label: 'Variables', + type: 'textarea', + class: 'Form-textAreaLabel Form-formGroup--fullWidth', + rows: 6, + 'default': '---', + dataTitle: 'Group Variables', + dataPlacement: 'right', + parseTypeName: 'parseType', + awPopOver: "
Variables defined here apply to all child groups and hosts.
" + + "Enter variables using either JSON or YAML syntax. Use the " + + "radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body', + tab: 'properties' + } + }, - - addTitle: 'CREATE GROUP', - editTitle: '{{ name }}', - showTitle: true, - name: 'group', - basePath: 'groups', - parent: 'inventories.edit.groups', - // the parent node this generated state definition tree expects to attach to - stateTree: 'inventories', - // form generator inspects the current state name to determine whether or not to set an active (.is-selected) class on a form tab - // this setting is optional on most forms, except where the form's edit state name is not parentStateName.edit - activeEditState: 'inventories.edit.groups.editGroup', - detailsClick: "$state.go('inventories.edit.groups.editGroup')", - well: false, - fields: { - name: { - label: 'Name', - type: 'text', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - required: true, - tab: 'properties' - }, - description: { - label: 'Description', - type: 'text', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - tab: 'properties' - }, - variables: { - label: 'Variables', - type: 'textarea', - class: 'Form-textAreaLabel Form-formGroup--fullWidth', - rows: 6, - 'default': '---', - dataTitle: 'Group Variables', - dataPlacement: 'right', - parseTypeName: 'parseType', - awPopOver: "Variables defined here apply to all child groups and hosts.
" + - "Enter variables using either JSON or YAML syntax. Use the " + - "radio button to toggle between the two.
" + - "JSON:{\n" + - "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + - '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + - 'View YAML examples at docs.ansible.com
', - dataContainer: 'body', - tab: 'properties' - }, - source: { - label: 'Source', - type: 'select', - ngOptions: 'source.label for source in source_type_options track by source.value', - ngChange: 'sourceChange(source)', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - ngModel: 'source' - }, - credential: { - // initializes a default value for this search param - // search params with default values set will not generate user-interactable search tags - search: { - kind: null - }, - label: 'Cloud Credential', - type: 'lookup', - list: 'CredentialList', - basePath: 'credentials', - ngShow: "source && source.value !== '' && source.value !== 'custom'", - sourceModel: 'credential', - sourceField: 'name', - ngClick: 'lookupCredential()', - awRequiredWhen: { - reqExpression: "cloudCredentialRequired", - init: "false" - }, - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - watchBasePath: "credentialBasePath" - }, - source_regions: { - label: 'Regions', - type: 'select', - ngOptions: 'source.label for source in source_region_choices track by source.value', - multiSelect: true, - ngShow: "source && (source.value == 'rax' || source.value == 'ec2' || source.value == 'gce' || source.value == 'azure' || source.value == 'azure_rm')", - - - dataTitle: 'Source Regions', - dataPlacement: 'right', - awPopOver: "Click on the regions field to see a list of regions for your cloud provider. You can select multiple regions, " + - "or choose All to include all regions. Tower will only be updated with Hosts associated with the selected regions." + - "
", - dataContainer: 'body', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, - instance_filters: { - label: 'Instance Filters', - type: 'text', - ngShow: "source && source.value == 'ec2'", - dataTitle: 'Instance Filters', - dataPlacement: 'right', - awPopOver: "Provide a comma-separated list of filter expressions. " + - "Hosts are imported to Tower when ANY of the filters match.
" + - "Limit to hosts having a tag:tag-key=TowerManaged\n" + - "Limit to hosts using either key pair:
key-name=staging, key-name=production\n" + - "Limit to hosts where the Name tag begins with test:
tag:Name=test*\n" + - "
View the Describe Instances documentation " + - "for a complete list of supported filters.
", - dataContainer: 'body', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, - group_by: { - label: 'Only Group By', - type: 'select', - ngShow: "source && source.value == 'ec2'", - ngOptions: 'source.label for source in group_by_choices track by source.value', - multiSelect: true, - dataTitle: 'Only Group By', - dataPlacement: 'right', - awPopOver: "Select which groups to create automatically. " + - "Tower will create group names similar to the following examples based on the options selected:
If blank, all groups above are created except Instance ID.
", - dataContainer: 'body', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, - inventory_script: { - label : "Custom Inventory Script", - type: 'lookup', - basePath: 'inventory_scripts', - list: 'InventoryScriptsList', - ngShow: "source && source.value === 'custom'", - sourceModel: 'inventory_script', - sourceField: 'name', - awRequiredWhen: { - reqExpression: "source && source.value === 'custom'", - init: "false" - }, - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - }, - custom_variables: { - id: 'custom_variables', - label: 'Environment Variables', //"{{vars_label}}" , - ngShow: "source && source.value=='custom' ", - type: 'textarea', - class: 'Form-textAreaLabel Form-formGroup--fullWidth', - rows: 6, - 'default': '---', - parseTypeName: 'envParseType', - dataTitle: "Environment Variables", - dataPlacement: 'right', - awPopOver: "Provide environment variables to pass to the custom inventory script.
" + - "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + - "JSON:{\n" + - "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + - '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + - 'View YAML examples at docs.ansible.com
', - dataContainer: 'body' - }, - ec2_variables: { - id: 'ec2_variables', - label: 'Source Variables', //"{{vars_label}}" , - ngShow: "source && source.value == 'ec2'", - type: 'textarea', - class: 'Form-textAreaLabel Form-formGroup--fullWidth', - rows: 6, - 'default': '---', - parseTypeName: 'envParseType', - dataTitle: "Source Variables", - dataPlacement: 'right', - awPopOver: "Override variables found in ec2.ini and used by the inventory update script. For a detailed description of these variables " + - "" + - "view ec2.ini in the Ansible github repo.
" + - "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + - "JSON:{\n" + - "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + - '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + - 'View YAML examples at docs.ansible.com
', - dataContainer: 'body' - }, - vmware_variables: { - id: 'vmware_variables', - label: 'Source Variables', //"{{vars_label}}" , - ngShow: "source && source.value == 'vmware'", - type: 'textarea', - class: 'Form-textAreaLabel Form-formGroup--fullWidth', - rows: 6, - 'default': '---', - parseTypeName: 'envParseType', - dataTitle: "Source Variables", - dataPlacement: 'right', - awPopOver: "Override variables found in vmware.ini and used by the inventory update script. For a detailed description of these variables " + - "" + - "view vmware_inventory.ini in the Ansible github repo.
" + - "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + - "JSON:{\n" + - "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + - '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + - 'View YAML examples at docs.ansible.com
', - dataContainer: 'body' - }, - openstack_variables: { - id: 'openstack_variables', - label: 'Source Variables', //"{{vars_label}}" , - ngShow: "source && source.value == 'openstack'", - type: 'textarea', - class: 'Form-textAreaLabel Form-formGroup--fullWidth', - rows: 6, - 'default': '---', - parseTypeName: 'envParseType', - dataTitle: "Source Variables", - dataPlacement: 'right', - awPopOver: "Override variables found in openstack.yml and used by the inventory update script. For an example variable configuration " + - "" + - "view openstack.yml in the Ansible github repo.
" + - "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + - "JSON:{\n" + - "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + - '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + - 'View YAML examples at docs.ansible.com
', - dataContainer: 'body' - }, - checkbox_group: { - label: 'Update Options', - type: 'checkbox_group', - ngShow: "source && (source.value !== '' && source.value !== null)", - class: 'Form-checkbox--stacked', - fields: [{ - name: 'overwrite', - label: 'Overwrite', - type: 'checkbox', - ngShow: "source.value !== '' && source.value !== null", - - - awPopOver: 'If checked, all child groups and hosts not found on the external source will be deleted from ' + - 'the local inventory.
When not checked, local child hosts and groups not found on the external source will ' + - 'remain untouched by the inventory update process.
', - dataTitle: 'Overwrite', - dataContainer: 'body', - dataPlacement: 'right', - labelClass: 'checkbox-options', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, { - name: 'overwrite_vars', - label: 'Overwrite Variables', - type: 'checkbox', - ngShow: "source.value !== '' && source.value !== null", - - - awPopOver: 'If checked, all variables for child groups and hosts will be removed and replaced by those ' + - 'found on the external source.
When not checked, a merge will be performed, combining local variables with ' + - 'those found on the external source.
', - dataTitle: 'Overwrite Variables', - dataContainer: 'body', - dataPlacement: 'right', - labelClass: 'checkbox-options', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, { - name: 'update_on_launch', - label: 'Update on Launch', - type: 'checkbox', - ngShow: "source.value !== '' && source.value !== null", - awPopOver: 'Each time a job runs using this inventory, refresh the inventory from the selected source before ' + - 'executing job tasks.
', - dataTitle: 'Update on Launch', - dataContainer: 'body', - dataPlacement: 'right', - labelClass: 'checkbox-options', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }] - }, - update_cache_timeout: { - label: "Cache Timeout (seconds)", - id: 'source-cache-timeout', - type: 'number', - ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', - integer: true, - min: 0, - ngShow: "source && source.value !== '' && update_on_launch", - spinner: true, - "default": 0, - awPopOver: 'Time in seconds to consider an inventory sync to be current. During job runs and callbacks the task system will ' + - 'evaluate the timestamp of the latest sync. If it is older than Cache Timeout, it is not considered current, ' + - 'and a new inventory sync will be performed.
', - dataTitle: 'Cache Timeout', - dataPlacement: 'right', - dataContainer: "body" - } - }, - - buttons: { - cancel: { - ngClick: 'formCancel()', - ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, - close: { - ngClick: 'formCancel()', - ngShow: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' - }, - save: { - ngClick: 'formSave()', - ngDisabled: true, - ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' - } - } - }; + buttons: { + cancel: { + ngClick: 'formCancel()', + ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + close: { + ngClick: 'formCancel()', + ngShow: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + save: { + ngClick: 'formSave()', + ngDisabled: true, + ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' + } + } +}; diff --git a/awx/ui/client/src/inventories/groups/groups.list.js b/awx/ui/client/src/inventories/groups/groups.list.js index 0536161ab9..20baec28b1 100644 --- a/awx/ui/client/src/inventories/groups/groups.list.js +++ b/awx/ui/client/src/inventories/groups/groups.list.js @@ -17,19 +17,6 @@ export default { basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/root_groups/', fields: { - sync_status: { - label: '', - nosort: true, - mode: 'all', - iconOnly: true, - ngClick: 'viewUpdateStatus(group.id)', - awToolTip: "{{ group.status_tooltip }}", - dataTipWatch: "group.status_tooltip", - icon: "{{ 'fa icon-cloud-' + group.status_class }}", - ngClass: "group.status_class", - dataPlacement: "top", - columnClass: 'status-column List-staticColumn--smallStatus' - }, failed_hosts: { label: '', nosort: true, diff --git a/awx/ui/client/src/inventories/groups/list/groups-list.controller.js b/awx/ui/client/src/inventories/groups/list/groups-list.controller.js index a9db830841..2889b745f9 100644 --- a/awx/ui/client/src/inventories/groups/list/groups-list.controller.js +++ b/awx/ui/client/src/inventories/groups/list/groups-list.controller.js @@ -50,13 +50,8 @@ group = {}; } - let group_status, hosts_status; + let hosts_status; - group_status = GetSyncStatusMsg({ - status: group.summary_fields.inventory_source.status, - has_inventory_sources: group.has_inventory_sources, - source: ( (group.summary_fields.inventory_source) ? group.summary_fields.inventory_source.source : null ) - }); hosts_status = GetHostsStatusMsg({ active_failures: group.hosts_with_active_failures, total_hosts: group.total_hosts, @@ -64,15 +59,8 @@ group_id: group.id }); _.assign(group, - {status_class: group_status.class}, - {status_tooltip: group_status.tooltip}, - {launch_tooltip: group_status.launch_tip}, - {launch_class: group_status.launch_class}, - {group_schedule_tooltip: group_status.schedule_tip}, {hosts_status_tip: hosts_status.tooltip}, - {hosts_status_class: hosts_status.class}, - {source: group.summary_fields.inventory_source ? group.summary_fields.inventory_source.source : null}, - {status: group.summary_fields.inventory_source ? group.summary_fields.inventory_source.status : null}); + {hosts_status_class: hosts_status.class}); } $scope.groupSelect = function(id){ diff --git a/awx/ui/client/src/inventories/inventories.partial.html b/awx/ui/client/src/inventories/inventories.partial.html index 875d23486b..032a4ec352 100644 --- a/awx/ui/client/src/inventories/inventories.partial.html +++ b/awx/ui/client/src/inventories/inventories.partial.html @@ -1,6 +1,7 @@Variables defined here apply to all child groups and hosts.
" + + "Enter variables using either JSON or YAML syntax. Use the " + + "radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body', + tab: 'properties' + }, + source: { + label: 'Source', + type: 'select', + ngOptions: 'source.label for source in source_type_options track by source.value', + ngChange: 'sourceChange(source)', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + ngModel: 'source' + }, + credential: { + // initializes a default value for this search param + // search params with default values set will not generate user-interactable search tags + search: { + kind: null + }, + label: 'Cloud Credential', + type: 'lookup', + list: 'CredentialList', + basePath: 'credentials', + ngShow: "source && source.value !== '' && source.value !== 'custom'", + sourceModel: 'credential', + sourceField: 'name', + ngClick: 'lookupCredential()', + awRequiredWhen: { + reqExpression: "cloudCredentialRequired", + init: "false" + }, + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + watchBasePath: "credentialBasePath" + }, + source_regions: { + label: 'Regions', + type: 'select', + ngOptions: 'source.label for source in source_region_choices track by source.value', + multiSelect: true, + ngShow: "source && (source.value == 'rax' || source.value == 'ec2' || source.value == 'gce' || source.value == 'azure' || source.value == 'azure_rm')", + + + dataTitle: 'Source Regions', + dataPlacement: 'right', + awPopOver: "Click on the regions field to see a list of regions for your cloud provider. You can select multiple regions, " + + "or choose All to include all regions. Tower will only be updated with Hosts associated with the selected regions." + + "
", + dataContainer: 'body', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + instance_filters: { + label: 'Instance Filters', + type: 'text', + ngShow: "source && source.value == 'ec2'", + dataTitle: 'Instance Filters', + dataPlacement: 'right', + awPopOver: "Provide a comma-separated list of filter expressions. " + + "Hosts are imported to Tower when ANY of the filters match.
" + + "Limit to hosts having a tag:tag-key=TowerManaged\n" + + "Limit to hosts using either key pair:
key-name=staging, key-name=production\n" + + "Limit to hosts where the Name tag begins with test:
tag:Name=test*\n" + + "
View the Describe Instances documentation " + + "for a complete list of supported filters.
", + dataContainer: 'body', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + group_by: { + label: 'Only Group By', + type: 'select', + ngShow: "source && source.value == 'ec2'", + ngOptions: 'source.label for source in group_by_choices track by source.value', + multiSelect: true, + dataTitle: 'Only Group By', + dataPlacement: 'right', + awPopOver: "Select which groups to create automatically. " + + "Tower will create group names similar to the following examples based on the options selected:
If blank, all groups above are created except Instance ID.
", + dataContainer: 'body', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + inventory_script: { + label : "Custom Inventory Script", + type: 'lookup', + basePath: 'inventory_scripts', + list: 'InventoryScriptsList', + ngShow: "source && source.value === 'custom'", + sourceModel: 'inventory_script', + sourceField: 'name', + awRequiredWhen: { + reqExpression: "source && source.value === 'custom'", + init: "false" + }, + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + }, + custom_variables: { + id: 'custom_variables', + label: 'Environment Variables', //"{{vars_label}}" , + ngShow: "source && source.value=='custom' ", + type: 'textarea', + class: 'Form-textAreaLabel Form-formGroup--fullWidth', + rows: 6, + 'default': '---', + parseTypeName: 'envParseType', + dataTitle: "Environment Variables", + dataPlacement: 'right', + awPopOver: "Provide environment variables to pass to the custom inventory script.
" + + "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body' + }, + ec2_variables: { + id: 'ec2_variables', + label: 'Source Variables', //"{{vars_label}}" , + ngShow: "source && source.value == 'ec2'", + type: 'textarea', + class: 'Form-textAreaLabel Form-formGroup--fullWidth', + rows: 6, + 'default': '---', + parseTypeName: 'envParseType', + dataTitle: "Source Variables", + dataPlacement: 'right', + awPopOver: "Override variables found in ec2.ini and used by the inventory update script. For a detailed description of these variables " + + "" + + "view ec2.ini in the Ansible github repo.
" + + "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body' + }, + vmware_variables: { + id: 'vmware_variables', + label: 'Source Variables', //"{{vars_label}}" , + ngShow: "source && source.value == 'vmware'", + type: 'textarea', + class: 'Form-textAreaLabel Form-formGroup--fullWidth', + rows: 6, + 'default': '---', + parseTypeName: 'envParseType', + dataTitle: "Source Variables", + dataPlacement: 'right', + awPopOver: "Override variables found in vmware.ini and used by the inventory update script. For a detailed description of these variables " + + "" + + "view vmware_inventory.ini in the Ansible github repo.
" + + "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body' + }, + openstack_variables: { + id: 'openstack_variables', + label: 'Source Variables', //"{{vars_label}}" , + ngShow: "source && source.value == 'openstack'", + type: 'textarea', + class: 'Form-textAreaLabel Form-formGroup--fullWidth', + rows: 6, + 'default': '---', + parseTypeName: 'envParseType', + dataTitle: "Source Variables", + dataPlacement: 'right', + awPopOver: "Override variables found in openstack.yml and used by the inventory update script. For an example variable configuration " + + "" + + "view openstack.yml in the Ansible github repo.
" + + "Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two.
" + + "JSON:{\n" + + "YAML:
\"somevar\": \"somevalue\",
\"password\": \"magic\"
}
---\n" + + '
somevar: somevalue
password: magic
View JSON examples at www.json.org
' + + 'View YAML examples at docs.ansible.com
', + dataContainer: 'body' + }, + checkbox_group: { + label: 'Update Options', + type: 'checkbox_group', + ngShow: "source && (source.value !== '' && source.value !== null)", + class: 'Form-checkbox--stacked', + fields: [{ + name: 'overwrite', + label: 'Overwrite', + type: 'checkbox', + ngShow: "source.value !== '' && source.value !== null", + + + awPopOver: 'If checked, all child groups and hosts not found on the external source will be deleted from ' + + 'the local inventory.
When not checked, local child hosts and groups not found on the external source will ' + + 'remain untouched by the inventory update process.
', + dataTitle: 'Overwrite', + dataContainer: 'body', + dataPlacement: 'right', + labelClass: 'checkbox-options', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, { + name: 'overwrite_vars', + label: 'Overwrite Variables', + type: 'checkbox', + ngShow: "source.value !== '' && source.value !== null", + + + awPopOver: 'If checked, all variables for child groups and hosts will be removed and replaced by those ' + + 'found on the external source.
When not checked, a merge will be performed, combining local variables with ' + + 'those found on the external source.
', + dataTitle: 'Overwrite Variables', + dataContainer: 'body', + dataPlacement: 'right', + labelClass: 'checkbox-options', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, { + name: 'update_on_launch', + label: 'Update on Launch', + type: 'checkbox', + ngShow: "source.value !== '' && source.value !== null", + awPopOver: 'Each time a job runs using this inventory, refresh the inventory from the selected source before ' + + 'executing job tasks.
', + dataTitle: 'Update on Launch', + dataContainer: 'body', + dataPlacement: 'right', + labelClass: 'checkbox-options', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }] + }, + update_cache_timeout: { + label: "Cache Timeout (seconds)", + id: 'source-cache-timeout', + type: 'number', + ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', + integer: true, + min: 0, + ngShow: "source && source.value !== '' && update_on_launch", + spinner: true, + "default": 0, + awPopOver: 'Time in seconds to consider an inventory sync to be current. During job runs and callbacks the task system will ' + + 'evaluate the timestamp of the latest sync. If it is older than Cache Timeout, it is not considered current, ' + + 'and a new inventory sync will be performed.
', + dataTitle: 'Cache Timeout', + dataPlacement: 'right', + dataContainer: "body" + } + }, + + buttons: { + cancel: { + ngClick: 'formCancel()', + ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + close: { + ngClick: 'formCancel()', + ngShow: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)' + }, + save: { + ngClick: 'formSave()', + ngDisabled: true, + ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' + } + } +}; diff --git a/awx/ui/client/src/inventories/sources/sources.list.js b/awx/ui/client/src/inventories/sources/sources.list.js new file mode 100644 index 0000000000..cfd714072f --- /dev/null +++ b/awx/ui/client/src/inventories/sources/sources.list.js @@ -0,0 +1,146 @@ +/************************************************* + * Copyright (c) 2017 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +export default { + name: 'inventory_sources', + iterator: 'inventory_source', + editTitle: '{{ inventory_source.name }}', + well: true, + wellOverride: true, + index: false, + hover: true, + multiSelect: true, + trackBy: 'inventory_source.id', + basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/inventory_sources/', + + fields: { + sync_status: { + label: '', + nosort: true, + mode: 'all', + iconOnly: true, + ngClick: 'viewUpdateStatus(inventory_source.id)', + awToolTip: "{{ inventory_source.status_tooltip }}", + dataTipWatch: "inventory_source.status_tooltip", + icon: "{{ 'fa icon-cloud-' + inventory_source.status_class }}", + ngClass: "inventory_source.status_class", + dataPlacement: "top", + columnClass: 'status-column List-staticColumn--smallStatus' + }, + name: { + label: 'Sources', + key: true, + ngClick: "groupSelect(inventory_source.id)", + columnClass: 'col-lg-6 col-md-6 col-sm-6 col-xs-6', + class: 'InventoryManage-breakWord', + } + }, + + actions: { + refresh: { + mode: 'all', + awToolTip: "Refresh the page", + ngClick: "refreshGroups()", + ngShow: "socketStatus == 'error'", + actionClass: 'btn List-buttonDefault', + buttonContent: 'REFRESH' + }, + // launch: { + // mode: 'all', + // // $scope.$parent is governed by InventoryManageController, + // ngDisabled: '!$parent.groupsSelected && !$parent.hostsSelected', + // ngClick: '$parent.setAdhocPattern()', + // awToolTip: "Select an inventory source by clicking the check box beside it. The inventory source can be a single group or host, a selection of multiple hosts, or a selection of multiple groups.", + // dataTipWatch: "adhocCommandTooltip", + // actionClass: 'btn List-buttonDefault', + // buttonContent: 'RUN COMMANDS', + // showTipWhenDisabled: true, + // tooltipInnerClass: "Tooltip-wide", + // ngShow: 'canAdhoc' + // // TODO: set up a tip watcher and change text based on when + // // things are selected/not selected. This is started and + // // commented out in the inventory controller within the watchers. + // // awToolTip: "{{ adhocButtonTipContents }}", + // // dataTipWatch: "adhocButtonTipContents" + // }, + create: { + mode: 'all', + ngClick: "createSource()", + awToolTip: "Create a new source", + actionClass: 'btn List-buttonSubmit', + buttonContent: '+ ADD SOURCE', + ngShow: 'canAdd', + dataPlacement: "top", + } + }, + + fieldActions: { + + columnClass: 'col-lg-6 col-md-6 col-sm-6 col-xs-6 text-right', + + group_update: { + //label: 'Sync', + mode: 'all', + ngClick: 'updateSource(inventory_source)', + awToolTip: "{{ inventory_source.launch_tooltip }}", + dataTipWatch: "inventory_source.launch_tooltip", + ngShow: "(inventory_source.status !== 'running' && inventory_source.status " + + "!== 'pending' && inventory_source.status !== 'updating') && inventory_source.summary_fields.user_capabilities.start", + ngClass: "inventory_source.launch_class", + dataPlacement: "top", + }, + cancel: { + //label: 'Cancel', + mode: 'all', + ngClick: "cancelUpdate(inventory_source.id)", + awToolTip: "Cancel sync process", + 'class': 'red-txt', + ngShow: "(inventory_source.status == 'running' || inventory_source.status == 'pending' " + + "|| inventory_source.status == 'updating') && inventory_source.summary_fields.user_capabilities.start", + dataPlacement: "top", + iconClass: "fa fa-minus-circle" + }, + copy: { + mode: 'all', + ngClick: "copyMoveSource(inventory_source.id)", + awToolTip: 'Copy or move source', + ngShow: "inventory_source.id > 0 && inventory_source.summary_fields.user_capabilities.copy", + dataPlacement: "top" + }, + schedule: { + mode: 'all', + ngClick: "scheduleSource(inventory_source.id)", + awToolTip: "{{ inventory_source.group_schedule_tooltip }}", + ngClass: "inventory_source.scm_type_class", + dataPlacement: 'top', + ngShow: "!(inventory_source.summary_fields.inventory_source.source === '')" + }, + edit: { + //label: 'Edit', + mode: 'all', + ngClick: "editSource(inventory_source.id)", + awToolTip: 'Edit source', + dataPlacement: "top", + ngShow: "inventory_source.summary_fields.user_capabilities.edit" + }, + view: { + //label: 'Edit', + mode: 'all', + ngClick: "editSource(inventory_source.id)", + awToolTip: 'View source', + dataPlacement: "top", + ngShow: "!inventory_source.summary_fields.user_capabilities.edit" + }, + "delete": { + //label: 'Delete', + mode: 'all', + ngClick: "deleteSource(inventory_source)", + awToolTip: 'Delete source', + dataPlacement: "top", + ngShow: "inventory_source.summary_fields.user_capabilities.delete" + } + } +}; diff --git a/awx/ui/client/src/inventories/sources/sources.service.js b/awx/ui/client/src/inventories/sources/sources.service.js new file mode 100644 index 0000000000..a913951806 --- /dev/null +++ b/awx/ui/client/src/inventories/sources/sources.service.js @@ -0,0 +1,113 @@ +export default + ['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait', function($rootScope, Rest, GetBasePath, ProcessErrors, Wait){ + return { + stringifyParams: function(params){ + return _.reduce(params, (result, value, key) => { + return result + key + '=' + value + '&'; + }, ''); + }, + // cute abstractions via fn.bind() + url: function(){ + return ''; + }, + error: function(data, status) { + ProcessErrors($rootScope, data, status, null, { hdr: 'Error!', + msg: 'Call to ' + this.url + '. GET returned: ' + status }); + }, + success: function(data){ + return data; + }, + // HTTP methods + get: function(params){ + Wait('start'); + this.url = GetBasePath('inventory_sources') + '?' + this.stringifyParams(params); + Rest.setUrl(this.url); + return Rest.get() + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + post: function(inventory_source){ + Wait('start'); + this.url = GetBasePath('inventory_sources'); + Rest.setUrl(this.url); + return Rest.post(inventory_source) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + put: function(inventory_source){ + Wait('start'); + this.url = GetBasePath('inventory_sources') + inventory_source.id; + Rest.setUrl(this.url); + return Rest.put(inventory_source) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + delete: function(id){ + Wait('start'); + this.url = GetBasePath('inventory_sources') + id; + Rest.setUrl(this.url); + return Rest.destroy() + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + getCredential: function(id){ + Wait('start'); + this.url = GetBasePath('credentials') + id; + Rest.setUrl(this.url); + return Rest.get() + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + getInventorySource: function(params){ + Wait('start'); + this.url = GetBasePath('inventory_sources') + '?' + this.stringifyParams(params); + Rest.setUrl(this.url); + return Rest.get() + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + putInventorySource: function(params, url){ + Wait('start'); + this.url = url; + Rest.setUrl(this.url); + return Rest.put(params) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + // these relationship setters could be consolidated, but verbosity makes the operation feel more clear @ controller level + associateGroup: function(group, target){ + Wait('start'); + this.url = GetBasePath('groups') + target + '/children/'; + Rest.setUrl(this.url); + return Rest.post(group) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + disassociateGroup: function(group, parent){ + Wait('start'); + this.url = GetBasePath('groups') + parent + '/children/'; + Rest.setUrl(this.url); + return Rest.post({id: group, disassociate: 1}) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + }, + promote: function(group, inventory){ + Wait('start'); + this.url = GetBasePath('inventory') + inventory + '/groups/'; + Rest.setUrl(this.url); + return Rest.post({id: group, disassociate: 1}) + .success(this.success.bind(this)) + .error(this.error.bind(this)) + .finally(Wait('stop')); + } + }; + }]; diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index b131ff4c95..785a1414e7 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -246,6 +246,7 @@ function($injector, $stateExtender, $log, i18n) { * @returns {array} Array of state definitions [{...}, {...}, ...] */ generateFormListDefinitions: function(form, formStateDefinition, params) { + var that = this; function buildRbacUserTeamDirective(){ let states = []; @@ -559,11 +560,23 @@ function($injector, $stateExtender, $log, i18n) { states = _.flatten(states); } if(field && field.addState){ - states.push(field.addState(field, formStateDefinition, params)); + let formState = field.addState(field, formStateDefinition, params); + states.push(formState); + // intent here is to add lookup states for any add-forms + if(field.includeForm){ + let form = field.includeForm ? $injector.get(field.includeForm) : field; + states.push(that.generateLookupNodes(form, formState)); + } states = _.flatten(states); } if(field && field.editState){ - states.push(field.editState(field, formStateDefinition, params)); + let formState = field.editState(field, formStateDefinition, params); + states.push(formState); + // intent here is to add lookup states for any edit-forms + if(field.includeForm){ + let form = field.includeForm ? $injector.get(field.includeForm) : field; + states.push(that.generateLookupNodes(form, formState)); + } states = _.flatten(states); } }