mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 11:10:03 -03:30
Merge pull request #198 from jaredevantabor/adhoc-commands
Adhoc commands
This commit is contained in:
@@ -86,7 +86,7 @@ export default [
|
|||||||
// does a string.split(', ') w/ an extra space
|
// does a string.split(', ') w/ an extra space
|
||||||
// behind the comma.
|
// behind the comma.
|
||||||
if(key === "AD_HOC_COMMANDS"){
|
if(key === "AD_HOC_COMMANDS"){
|
||||||
$scope[key] = data[key].toString();
|
$scope[key] = data[key];
|
||||||
} else if (key === "AUTH_LDAP_USER_SEARCH" || key === "AUTH_LDAP_GROUP_SEARCH") {
|
} else if (key === "AUTH_LDAP_USER_SEARCH" || key === "AUTH_LDAP_GROUP_SEARCH") {
|
||||||
$scope[key] = JSON.stringify(data[key]);
|
$scope[key] = JSON.stringify(data[key]);
|
||||||
} else {
|
} else {
|
||||||
@@ -321,6 +321,9 @@ export default [
|
|||||||
// We need to re-instantiate the Select2 element
|
// We need to re-instantiate the Select2 element
|
||||||
// after resetting the value. Example:
|
// after resetting the value. Example:
|
||||||
$scope.$broadcast(key+'_populated', null, false);
|
$scope.$broadcast(key+'_populated', null, false);
|
||||||
|
if(key === "AD_HOC_COMMANDS"){
|
||||||
|
$scope.$broadcast(key+'_reverted', null, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){
|
else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){
|
||||||
$scope.$broadcast(key+'_reverted');
|
$scope.$broadcast(key+'_reverted');
|
||||||
@@ -379,10 +382,10 @@ export default [
|
|||||||
//Parse dropdowns and dropdowns labeled as lists
|
//Parse dropdowns and dropdowns labeled as lists
|
||||||
if($scope[key] === null) {
|
if($scope[key] === null) {
|
||||||
payload[key] = null;
|
payload[key] = null;
|
||||||
} else if($scope[key][0] && $scope[key][0].value !== undefined) {
|
} else if(!_.isEmpty($scope[`${key}_values`])) {
|
||||||
if(multiselectDropdowns.indexOf(key) !== -1) {
|
if(multiselectDropdowns.indexOf(key) !== -1) {
|
||||||
// Handle AD_HOC_COMMANDS
|
// Handle AD_HOC_COMMANDS
|
||||||
payload[key] = ConfigurationUtils.listToArray(_.map($scope[key], 'value').join(','));
|
payload[key] = $scope[`${key}_values`];
|
||||||
} else {
|
} else {
|
||||||
payload[key] = _.map($scope[key], 'value').join(',');
|
payload[key] = _.map($scope[key], 'value').join(',');
|
||||||
}
|
}
|
||||||
@@ -501,6 +504,9 @@ export default [
|
|||||||
// We need to re-instantiate the Select2 element
|
// We need to re-instantiate the Select2 element
|
||||||
// after resetting the value. Example:
|
// after resetting the value. Example:
|
||||||
$scope.$broadcast(key+'_populated', null, false);
|
$scope.$broadcast(key+'_populated', null, false);
|
||||||
|
if(key === "AD_HOC_COMMANDS"){
|
||||||
|
$scope.$broadcast(key+'_reverted', null, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){
|
else if($scope[key + '_field'].reset === "CUSTOM_LOGO"){
|
||||||
$scope.$broadcast(key+'_reverted');
|
$scope.$broadcast(key+'_reverted');
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ export default [
|
|||||||
noPanel: true
|
noPanel: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// Flag to avoid re-rendering and breaking Select2 dropdowns on tab switching
|
|
||||||
var dropdownRendered = false;
|
|
||||||
|
|
||||||
function initializeCodeInput () {
|
function initializeCodeInput () {
|
||||||
let name = 'AWX_TASK_ENV';
|
let name = 'AWX_TASK_ENV';
|
||||||
|
|
||||||
@@ -95,35 +92,49 @@ export default [
|
|||||||
$scope.parseTypeChange('parseType', name);
|
$scope.parseTypeChange('parseType', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateAdhocCommand(flag){
|
function loadAdHocCommands () {
|
||||||
$scope.$parent.AD_HOC_COMMANDS = $scope.$parent.AD_HOC_COMMANDS.toString();
|
$scope.$parent.AD_HOC_COMMANDS_values = $scope.$parent.AD_HOC_COMMANDS.map(value => value);
|
||||||
var ad_hoc_commands = $scope.$parent.AD_HOC_COMMANDS.split(',');
|
$scope.$parent.AD_HOC_COMMANDS = $scope.$parent.AD_HOC_COMMANDS.map(value => ({
|
||||||
$scope.$parent.AD_HOC_COMMANDS = _.map(ad_hoc_commands, function(item){
|
value,
|
||||||
let option = _.find($scope.$parent.AD_HOC_COMMANDS_options, { value: item });
|
name: value,
|
||||||
if(!option){
|
label: value
|
||||||
option = {
|
}));
|
||||||
name: item,
|
|
||||||
value: item,
|
$scope.$parent.AD_HOC_COMMANDS_options = $scope.$parent.AD_HOC_COMMANDS.map(tag => tag);
|
||||||
label: item
|
|
||||||
};
|
CreateSelect2({
|
||||||
$scope.$parent.AD_HOC_COMMANDS_options.push(option);
|
element: '#configuration_jobs_template_AD_HOC_COMMANDS',
|
||||||
}
|
multiple: true,
|
||||||
return option;
|
addNew: true,
|
||||||
|
placeholder: i18n._('Select commands')
|
||||||
});
|
});
|
||||||
|
|
||||||
if(flag !== undefined){
|
}
|
||||||
dropdownRendered = flag;
|
|
||||||
}
|
function revertAdHocCommands () {
|
||||||
|
$scope.$parent.AD_HOC_COMMANDS = $scope.$parent.configDataResolve.AD_HOC_COMMANDS.default.map(value => ({
|
||||||
|
value,
|
||||||
|
name: value,
|
||||||
|
label: value
|
||||||
|
}));
|
||||||
|
|
||||||
|
$('.select2-selection__choice').each(function(i, element){
|
||||||
|
if(!_.contains($scope.$parent.configDataResolve.AD_HOC_COMMANDS.default, element.title)){
|
||||||
|
$(`#configuration_jobs_template_AD_HOC_COMMANDS option[value='${element.title}']`).remove();
|
||||||
|
element.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$parent.AD_HOC_COMMANDS_options = $scope.$parent.AD_HOC_COMMANDS.map(tag => tag);
|
||||||
|
$scope.$parent.AD_HOC_COMMANDS_values = $scope.$parent.AD_HOC_COMMANDS.map(tag => tag.value);
|
||||||
|
CreateSelect2({
|
||||||
|
element: '#configuration_jobs_template_AD_HOC_COMMANDS',
|
||||||
|
multiple: true,
|
||||||
|
addNew: true,
|
||||||
|
placeholder: i18n._('Select commands'),
|
||||||
|
options: $scope.$parent.AD_HOC_COMMANDS_options
|
||||||
|
});
|
||||||
|
|
||||||
if(!dropdownRendered) {
|
|
||||||
dropdownRendered = true;
|
|
||||||
CreateSelect2({
|
|
||||||
element: '#configuration_jobs_template_AD_HOC_COMMANDS',
|
|
||||||
multiple: true,
|
|
||||||
addNew: true,
|
|
||||||
placeholder: i18n._('Select commands')
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix for bug where adding selected opts causes form to be $dirty and triggering modal
|
// Fix for bug where adding selected opts causes form to be $dirty and triggering modal
|
||||||
@@ -132,10 +143,26 @@ export default [
|
|||||||
$scope.$parent.configuration_jobs_template_form.$setPristine();
|
$scope.$parent.configuration_jobs_template_form.$setPristine();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
$scope.$on('AD_HOC_COMMANDS_populated', function(e, data, flag) {
|
|
||||||
populateAdhocCommand(flag);
|
// Managing the state of select2's tags since the behavior is unpredictable otherwise.
|
||||||
|
let commandsElement = $('#configuration_jobs_template_AD_HOC_COMMANDS');
|
||||||
|
|
||||||
|
commandsElement.on('select2:select', event => {
|
||||||
|
let command = event.params.data.text;
|
||||||
|
let commands = $scope.$parent.AD_HOC_COMMANDS_values;
|
||||||
|
|
||||||
|
commands.push(command);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
commandsElement.on('select2:unselect', event => {
|
||||||
|
let command = event.params.data.text;
|
||||||
|
let commands = $scope.$parent.AD_HOC_COMMANDS_values;
|
||||||
|
|
||||||
|
$scope.$parent.AD_HOC_COMMANDS_values = commands.filter(value => value !== command);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$on('AD_HOC_COMMANDS_reverted', () => revertAdHocCommands());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controllers for each tab are initialized when configuration is opened. A listener
|
* Controllers for each tab are initialized when configuration is opened. A listener
|
||||||
* on the URL itself is necessary to determine which tab is active. If a non-active
|
* on the URL itself is necessary to determine which tab is active. If a non-active
|
||||||
@@ -163,7 +190,7 @@ export default [
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This event is fired if the user navigates directly to this tab, where the
|
* This event is fired if the user navigates directly to this tab, where the
|
||||||
* $locationChangeStart does not. Watching this and location ensure proper display on
|
* $locationChangeStart does not. Watching this and location ensure proper display on
|
||||||
* direct load of this tab or if the user comes from a different tab.
|
* direct load of this tab or if the user comes from a different tab.
|
||||||
*/
|
*/
|
||||||
$scope.$on('populated', () => {
|
$scope.$on('populated', () => {
|
||||||
@@ -174,7 +201,7 @@ export default [
|
|||||||
codeInputInitialized = true;
|
codeInputInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
populateAdhocCommand(false);
|
loadAdHocCommands();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user