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:
commit
e5f8edacbe
@ -18,8 +18,9 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
init();
|
||||
|
||||
function init() {
|
||||
$scope.mode = 'add';
|
||||
// apply form definition's default field values
|
||||
GenerateForm.applyDefaults(form, $scope);
|
||||
GenerateForm.applyDefaults(form, $scope, true);
|
||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||
$scope.envParseType = 'yaml';
|
||||
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
|
||||
if ($scope.getInventoryFilesUnregister) {
|
||||
$scope.getInventoryFilesUnregister();
|
||||
@ -83,7 +54,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
$scope.getInventoryFilesUnregister = $scope.$watch('project', function (newValue, oldValue) {
|
||||
if (newValue !== oldValue) {
|
||||
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.sourceChange = function(source) {
|
||||
@ -144,10 +113,11 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
}
|
||||
|
||||
if (source === 'scm') {
|
||||
$scope.overwrite_vars = true;
|
||||
$scope.inventory_source_form.inventory_file.$setPristine();
|
||||
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
|
||||
$scope.overwrite_vars = true;
|
||||
$scope.inventory_source_form.inventory_file.$setPristine();
|
||||
} else {
|
||||
$scope.overwrite_vars = false;
|
||||
$scope.overwrite_vars = false;
|
||||
}
|
||||
|
||||
// reset fields
|
||||
|
@ -8,15 +8,15 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
|
||||
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
||||
'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
|
||||
'Wait', 'Rest', 'Alert', 'ProcessErrors',
|
||||
'Wait', 'Rest', 'Alert',
|
||||
function($state, $stateParams, $scope, ParseVariableString,
|
||||
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
|
||||
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
|
||||
inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty,
|
||||
Wait, Rest, Alert, ProcessErrors) {
|
||||
Wait, Rest, Alert) {
|
||||
|
||||
function init() {
|
||||
$scope.projectBasePath = GetBasePath('projects');
|
||||
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
|
||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||
// instantiate expected $scope values from inventorySourceData
|
||||
_.assign($scope,
|
||||
@ -136,33 +136,6 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
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() {
|
||||
|
@ -4,6 +4,7 @@ export default {
|
||||
value: {
|
||||
page_size:"5",
|
||||
order_by:"name",
|
||||
not__status:"never updated",
|
||||
role_level:"use_role",
|
||||
},
|
||||
dynamic:true,
|
||||
|
@ -564,10 +564,6 @@ function(ConfigurationUtils, i18n, $rootScope) {
|
||||
_doAutoPopulate();
|
||||
}
|
||||
});
|
||||
|
||||
if (attrs.watchbasepath === 'projectBasePath') {
|
||||
_doAutoPopulate();
|
||||
}
|
||||
}
|
||||
|
||||
function _doAutoPopulate() {
|
||||
|
@ -375,11 +375,13 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
|
||||
return this.build(options);
|
||||
},
|
||||
|
||||
applyDefaults: function (form, scope) {
|
||||
// Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js
|
||||
// The mode is needed by the awlookup directive to auto-populate form fields when there is a
|
||||
// single related resource.
|
||||
scope.mode = this.mode;
|
||||
applyDefaults: function (form, scope, ignoreMode) {
|
||||
if(!ignoreMode) {
|
||||
// Note: This is a hack. Ideally, mode should be set in each <resource>-<mode>.controller.js
|
||||
// The mode is needed by the awlookup directive to auto-populate form fields when there is a
|
||||
// single related resource.
|
||||
scope.mode = this.mode;
|
||||
}
|
||||
|
||||
for (var fld in form.fields) {
|
||||
if (form.fields[fld]['default'] || form.fields[fld]['default'] === 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user