1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Merge pull request #6862 from mabashian/6427-project-inv-source

Only auto-populate inventory source project when the user selects scm type
This commit is contained in:
Michael Abashian 2017-07-11 14:13:46 -04:00 committed by GitHub
commit e5f8edacbe
5 changed files with 17 additions and 75 deletions

View File

@ -18,8 +18,9 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
init(); init();
function init() { function init() {
$scope.mode = 'add';
// apply form definition's default field values // apply form definition's default field values
GenerateForm.applyDefaults(form, $scope); GenerateForm.applyDefaults(form, $scope, true);
$scope.canAdd = inventorySourcesOptions.actions.POST; $scope.canAdd = inventorySourcesOptions.actions.POST;
$scope.envParseType = 'yaml'; $scope.envParseType = 'yaml';
initSources(); initSources();
@ -46,36 +47,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
} }
}; };
// Detect and alert user to potential SCM status issues
var checkSCMStatus = function () {
if (!Empty($scope.project)) {
Rest.setUrl(GetBasePath('projects') + $scope.project + '/');
Rest.get()
.success(function (data) {
var msg;
switch (data.status) {
case 'failed':
msg = "<div>The Project selected has a status of \"failed\". You must run a successful update before you can select an inventory file.";
break;
case 'never updated':
msg = "<div>The Project selected has a status of \"never updated\". You must run a successful update before you can select an inventory file.";
break;
case 'missing':
msg = '<div>The selected project has a status of \"missing\". Please check the server and make sure ' +
' the directory exists and file permissions are set correctly.</div>';
break;
}
if (msg) {
Alert('Warning', msg, 'alert-info alert-info--noTextTransform', null, null, null, null, true);
}
})
.error(function (data, status) {
ProcessErrors($scope, data, status, form, { hdr: 'Error!',
msg: 'Failed to get project ' + $scope.project + '. GET returned status: ' + status });
});
}
};
// Register a watcher on project_name // Register a watcher on project_name
if ($scope.getInventoryFilesUnregister) { if ($scope.getInventoryFilesUnregister) {
$scope.getInventoryFilesUnregister(); $scope.getInventoryFilesUnregister();
@ -83,7 +54,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
$scope.getInventoryFilesUnregister = $scope.$watch('project', function (newValue, oldValue) { $scope.getInventoryFilesUnregister = $scope.$watch('project', function (newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
getInventoryFiles(newValue); getInventoryFiles(newValue);
checkSCMStatus();
} }
}); });
@ -118,7 +88,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
}); });
}; };
$scope.projectBasePath = GetBasePath('projects');
$scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network'; $scope.credentialBasePath = GetBasePath('credentials') + '?credential_type__kind__in=cloud,network';
$scope.sourceChange = function(source) { $scope.sourceChange = function(source) {
@ -144,10 +113,11 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
} }
if (source === 'scm') { if (source === 'scm') {
$scope.overwrite_vars = true; $scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
$scope.inventory_source_form.inventory_file.$setPristine(); $scope.overwrite_vars = true;
$scope.inventory_source_form.inventory_file.$setPristine();
} else { } else {
$scope.overwrite_vars = false; $scope.overwrite_vars = false;
} }
// reset fields // reset fields

View File

@ -8,15 +8,15 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService', 'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty', 'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'Wait', 'Rest', 'Alert',
function($state, $stateParams, $scope, ParseVariableString, function($state, $stateParams, $scope, ParseVariableString,
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService, rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty, inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty,
Wait, Rest, Alert, ProcessErrors) { Wait, Rest, Alert) {
function init() { function init() {
$scope.projectBasePath = GetBasePath('projects'); $scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
$scope.canAdd = inventorySourcesOptions.actions.POST; $scope.canAdd = inventorySourcesOptions.actions.POST;
// instantiate expected $scope values from inventorySourceData // instantiate expected $scope values from inventorySourceData
_.assign($scope, _.assign($scope,
@ -136,33 +136,6 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
Wait('stop'); Wait('stop');
}); });
} }
if (!Empty($scope.project)) {
Rest.setUrl(GetBasePath('projects') + $scope.project + '/');
Rest.get()
.success(function (data) {
var msg;
switch (data.status) {
case 'failed':
msg = "<div>The Project selected has a status of \"failed\". You must run a successful update before you can select an inventory file.";
break;
case 'never updated':
msg = "<div>The Project selected has a status of \"never updated\". You must run a successful update before you can select an inventory file.";
break;
case 'missing':
msg = '<div>The selected project has a status of \"missing\". Please check the server and make sure ' +
' the directory exists and file permissions are set correctly.</div>';
break;
}
if (msg) {
Alert('Warning', msg, 'alert-info alert-info--noTextTransform', null, null, null, null, true);
}
})
.error(function (data, status) {
ProcessErrors($scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to get project ' + $scope.project + '. GET returned status: ' + status });
});
}
} }
function initSourceSelect() { function initSourceSelect() {

View File

@ -4,6 +4,7 @@ export default {
value: { value: {
page_size:"5", page_size:"5",
order_by:"name", order_by:"name",
not__status:"never updated",
role_level:"use_role", role_level:"use_role",
}, },
dynamic:true, dynamic:true,

View File

@ -564,10 +564,6 @@ function(ConfigurationUtils, i18n, $rootScope) {
_doAutoPopulate(); _doAutoPopulate();
} }
}); });
if (attrs.watchbasepath === 'projectBasePath') {
_doAutoPopulate();
}
} }
function _doAutoPopulate() { function _doAutoPopulate() {

View File

@ -375,11 +375,13 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
return this.build(options); return this.build(options);
}, },
applyDefaults: function (form, scope) { applyDefaults: function (form, scope, ignoreMode) {
// Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js if(!ignoreMode) {
// The mode is needed by the awlookup directive to auto-populate form fields when there is a // Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js
// single related resource. // The mode is needed by the awlookup directive to auto-populate form fields when there is a
scope.mode = this.mode; // single related resource.
scope.mode = this.mode;
}
for (var fld in form.fields) { for (var fld in form.fields) {
if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) { if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) {