mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
add inventory prompt to wf editor
This commit is contained in:
@@ -97,12 +97,12 @@ function atLaunchTemplateCtrl (
|
|||||||
extra_vars: wfjtData.data.extra_vars
|
extra_vars: wfjtData.data.extra_vars
|
||||||
};
|
};
|
||||||
const promptData = {
|
const promptData = {
|
||||||
launchConf: launchData.data,
|
launchConf: selectedWorkflowJobTemplate.getLaunchConf(),
|
||||||
launchOptions: launchOptions.data,
|
launchOptions: launchOptions.data,
|
||||||
template: vm.template.id,
|
template: vm.template.id,
|
||||||
templateType: vm.template.type,
|
templateType: vm.template.type,
|
||||||
prompts: PromptService.processPromptValues({
|
prompts: PromptService.processPromptValues({
|
||||||
launchConf: launchData.data,
|
launchConf: selectedWorkflowJobTemplate.getLaunchConf(),
|
||||||
launchOptions: launchOptions.data
|
launchOptions: launchOptions.data
|
||||||
}),
|
}),
|
||||||
triggerModalOpen: true,
|
triggerModalOpen: true,
|
||||||
|
|||||||
@@ -47,8 +47,15 @@ function getSurveyQuestions (id) {
|
|||||||
return $http(req);
|
return $http(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLaunchConf () {
|
||||||
|
// this method is just a pass-through to the underlying launch GET data
|
||||||
|
// we use it to make the access patterns consistent across both types of
|
||||||
|
// templates
|
||||||
|
return this.model.launch.GET;
|
||||||
|
}
|
||||||
|
|
||||||
function canLaunchWithoutPrompt () {
|
function canLaunchWithoutPrompt () {
|
||||||
const launchData = this.model.launch.GET;
|
const launchData = this.getLaunchConf();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
launchData.can_start_without_user_input &&
|
launchData.can_start_without_user_input &&
|
||||||
@@ -61,7 +68,8 @@ function canLaunchWithoutPrompt () {
|
|||||||
!launchData.ask_skip_tags_on_launch &&
|
!launchData.ask_skip_tags_on_launch &&
|
||||||
!launchData.ask_variables_on_launch &&
|
!launchData.ask_variables_on_launch &&
|
||||||
!launchData.ask_diff_mode_on_launch &&
|
!launchData.ask_diff_mode_on_launch &&
|
||||||
!launchData.survey_enabled
|
!launchData.survey_enabled &&
|
||||||
|
launchData.variables_needed_to_start.length === 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +93,7 @@ function JobTemplateModel (method, resource, config) {
|
|||||||
this.getLaunch = getLaunch.bind(this);
|
this.getLaunch = getLaunch.bind(this);
|
||||||
this.postLaunch = postLaunch.bind(this);
|
this.postLaunch = postLaunch.bind(this);
|
||||||
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
||||||
|
this.getLaunchConf = getLaunchConf.bind(this);
|
||||||
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
||||||
|
|
||||||
this.model.launch = {};
|
this.model.launch = {};
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
/* eslint camelcase: 0 */
|
||||||
let Base;
|
let Base;
|
||||||
let $http;
|
let $http;
|
||||||
|
let $q;
|
||||||
|
|
||||||
function optionsLaunch (id) {
|
function optionsLaunch (id) {
|
||||||
const req = {
|
const req = {
|
||||||
@@ -11,16 +13,19 @@ function optionsLaunch (id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLaunch (id) {
|
function getLaunch (id) {
|
||||||
const req = {
|
const urls = [
|
||||||
method: 'GET',
|
`${this.path}${id}/`,
|
||||||
url: `${this.path}${id}/launch/`
|
`${this.path}${id}/launch/`,
|
||||||
};
|
];
|
||||||
|
|
||||||
return $http(req)
|
const promises = urls.map(url => $http({ method: 'GET', url }));
|
||||||
.then(res => {
|
|
||||||
this.model.launch.GET = res.data;
|
|
||||||
|
|
||||||
return res;
|
return $q.all(promises)
|
||||||
|
.then(([res, launchRes]) => {
|
||||||
|
this.model.GET = res.data;
|
||||||
|
this.model.launch.GET = launchRes.data;
|
||||||
|
|
||||||
|
return launchRes;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,14 +51,40 @@ function getSurveyQuestions (id) {
|
|||||||
return $http(req);
|
return $http(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLaunchConf () {
|
||||||
|
// We may need api updates to align /:id/launch data with what is returned for job templates.
|
||||||
|
// For now, we splice values from the different endpoints to get the launchData we need.
|
||||||
|
const {
|
||||||
|
ask_inventory_on_launch,
|
||||||
|
ask_variables_on_launch,
|
||||||
|
survey_enabled,
|
||||||
|
} = this.model.GET;
|
||||||
|
|
||||||
|
const {
|
||||||
|
can_start_without_user_input,
|
||||||
|
variables_needed_to_start,
|
||||||
|
} = this.model.launch.GET;
|
||||||
|
|
||||||
|
const launchConf = {
|
||||||
|
ask_inventory_on_launch,
|
||||||
|
ask_variables_on_launch,
|
||||||
|
can_start_without_user_input,
|
||||||
|
survey_enabled,
|
||||||
|
variables_needed_to_start,
|
||||||
|
};
|
||||||
|
|
||||||
|
return launchConf;
|
||||||
|
}
|
||||||
|
|
||||||
function canLaunchWithoutPrompt () {
|
function canLaunchWithoutPrompt () {
|
||||||
const launchData = this.model.launch.GET;
|
const launchData = this.getLaunchConf();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// TODO: may need api update
|
launchData.can_start_without_user_input &&
|
||||||
// launchData.can_start_without_user_input &&
|
!launchData.ask_inventory_on_launch &&
|
||||||
|
!launchData.ask_variables_on_launch &&
|
||||||
!launchData.survey_enabled &&
|
!launchData.survey_enabled &&
|
||||||
!this.model.GET.ask_inventory_on_launch
|
launchData.variables_needed_to_start.length === 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +96,7 @@ function WorkflowJobTemplateModel (method, resource, config) {
|
|||||||
this.getLaunch = getLaunch.bind(this);
|
this.getLaunch = getLaunch.bind(this);
|
||||||
this.postLaunch = postLaunch.bind(this);
|
this.postLaunch = postLaunch.bind(this);
|
||||||
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
||||||
|
this.getLaunchConf = getLaunchConf.bind(this);
|
||||||
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
||||||
|
|
||||||
this.model.launch = {};
|
this.model.launch = {};
|
||||||
@@ -72,16 +104,18 @@ function WorkflowJobTemplateModel (method, resource, config) {
|
|||||||
return this.create(method, resource, config);
|
return this.create(method, resource, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
function WorkflowJobTemplateModelLoader (BaseModel, _$http_) {
|
function WorkflowJobTemplateModelLoader (BaseModel, _$http_, _$q_) {
|
||||||
Base = BaseModel;
|
Base = BaseModel;
|
||||||
$http = _$http_;
|
$http = _$http_;
|
||||||
|
$q = _$q_;
|
||||||
|
|
||||||
return WorkflowJobTemplateModel;
|
return WorkflowJobTemplateModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkflowJobTemplateModelLoader.$inject = [
|
WorkflowJobTemplateModelLoader.$inject = [
|
||||||
'BaseModel',
|
'BaseModel',
|
||||||
'$http'
|
'$http',
|
||||||
|
'$q',
|
||||||
];
|
];
|
||||||
|
|
||||||
export default WorkflowJobTemplateModelLoader;
|
export default WorkflowJobTemplateModelLoader;
|
||||||
|
|||||||
@@ -242,28 +242,30 @@ function PromptService (Empty, $filter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const launchConfDefaults = _.get(params, ['promptData', 'launchConf', 'defaults'], {});
|
||||||
|
|
||||||
if(_.has(params, 'promptData.prompts.jobType.value.value') && _.get(params, 'promptData.launchConf.ask_job_type_on_launch')) {
|
if(_.has(params, 'promptData.prompts.jobType.value.value') && _.get(params, 'promptData.launchConf.ask_job_type_on_launch')) {
|
||||||
promptDataToSave.job_type = params.promptData.launchConf.defaults.job_type && params.promptData.launchConf.defaults.job_type === params.promptData.prompts.jobType.value.value ? null : params.promptData.prompts.jobType.value.value;
|
promptDataToSave.job_type = launchConfDefaults.job_type && launchConfDefaults.job_type === params.promptData.prompts.jobType.value.value ? null : params.promptData.prompts.jobType.value.value;
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.tags.value') && _.get(params, 'promptData.launchConf.ask_tags_on_launch')){
|
if(_.has(params, 'promptData.prompts.tags.value') && _.get(params, 'promptData.launchConf.ask_tags_on_launch')){
|
||||||
const templateDefaultJobTags = params.promptData.launchConf.defaults.job_tags.split(',');
|
const templateDefaultJobTags = launchConfDefaults.job_tags.split(',');
|
||||||
promptDataToSave.job_tags = (_.isEqual(templateDefaultJobTags.sort(), params.promptData.prompts.tags.value.map(a => a.value).sort())) ? null : params.promptData.prompts.tags.value.map(a => a.value).join();
|
promptDataToSave.job_tags = (_.isEqual(templateDefaultJobTags.sort(), params.promptData.prompts.tags.value.map(a => a.value).sort())) ? null : params.promptData.prompts.tags.value.map(a => a.value).join();
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.skipTags.value') && _.get(params, 'promptData.launchConf.ask_skip_tags_on_launch')){
|
if(_.has(params, 'promptData.prompts.skipTags.value') && _.get(params, 'promptData.launchConf.ask_skip_tags_on_launch')){
|
||||||
const templateDefaultSkipTags = params.promptData.launchConf.defaults.skip_tags.split(',');
|
const templateDefaultSkipTags = launchConfDefaults.skip_tags.split(',');
|
||||||
promptDataToSave.skip_tags = (_.isEqual(templateDefaultSkipTags.sort(), params.promptData.prompts.skipTags.value.map(a => a.value).sort())) ? null : params.promptData.prompts.skipTags.value.map(a => a.value).join();
|
promptDataToSave.skip_tags = (_.isEqual(templateDefaultSkipTags.sort(), params.promptData.prompts.skipTags.value.map(a => a.value).sort())) ? null : params.promptData.prompts.skipTags.value.map(a => a.value).join();
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.limit.value') && _.get(params, 'promptData.launchConf.ask_limit_on_launch')){
|
if(_.has(params, 'promptData.prompts.limit.value') && _.get(params, 'promptData.launchConf.ask_limit_on_launch')){
|
||||||
promptDataToSave.limit = params.promptData.launchConf.defaults.limit && params.promptData.launchConf.defaults.limit === params.promptData.prompts.limit.value ? null : params.promptData.prompts.limit.value;
|
promptDataToSave.limit = launchConfDefaults.limit && launchConfDefaults.limit === params.promptData.prompts.limit.value ? null : params.promptData.prompts.limit.value;
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.verbosity.value.value') && _.get(params, 'promptData.launchConf.ask_verbosity_on_launch')){
|
if(_.has(params, 'promptData.prompts.verbosity.value.value') && _.get(params, 'promptData.launchConf.ask_verbosity_on_launch')){
|
||||||
promptDataToSave.verbosity = params.promptData.launchConf.defaults.verbosity && params.promptData.launchConf.defaults.verbosity === params.promptData.prompts.verbosity.value.value ? null : params.promptData.prompts.verbosity.value.value;
|
promptDataToSave.verbosity = launchConfDefaults.verbosity && launchConfDefaults.verbosity === params.promptData.prompts.verbosity.value.value ? null : params.promptData.prompts.verbosity.value.value;
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.inventory.value') && _.get(params, 'promptData.launchConf.ask_inventory_on_launch')){
|
if(_.has(params, 'promptData.prompts.inventory.value') && _.get(params, 'promptData.launchConf.ask_inventory_on_launch')){
|
||||||
promptDataToSave.inventory = params.promptData.launchConf.defaults.inventory && params.promptData.launchConf.defaults.inventory.id === params.promptData.prompts.inventory.value.id ? null : params.promptData.prompts.inventory.value.id;
|
promptDataToSave.inventory = launchConfDefaults.inventory && launchConfDefaults.inventory.id === params.promptData.prompts.inventory.value.id ? null : params.promptData.prompts.inventory.value.id;
|
||||||
}
|
}
|
||||||
if(_.has(params, 'promptData.prompts.diffMode.value') && _.get(params, 'promptData.launchConf.ask_diff_mode_on_launch')){
|
if(_.has(params, 'promptData.prompts.diffMode.value') && _.get(params, 'promptData.launchConf.ask_diff_mode_on_launch')){
|
||||||
promptDataToSave.diff_mode = params.promptData.launchConf.defaults.diff_mode && params.promptData.launchConf.defaults.diff_mode === params.promptData.prompts.diffMode.value ? null : params.promptData.prompts.diffMode.value;
|
promptDataToSave.diff_mode = launchConfDefaults.diff_mode && launchConfDefaults.diff_mode === params.promptData.prompts.diffMode.value ? null : params.promptData.prompts.diffMode.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return promptDataToSave;
|
return promptDataToSave;
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ export default [
|
|||||||
'$scope', 'WorkflowForm', 'GenerateForm', 'Alert', 'ProcessErrors',
|
'$scope', 'WorkflowForm', 'GenerateForm', 'Alert', 'ProcessErrors',
|
||||||
'Wait', '$state', 'CreateSelect2', 'TemplatesService',
|
'Wait', '$state', 'CreateSelect2', 'TemplatesService',
|
||||||
'ToJSON', 'ParseTypeChange', '$q', 'Rest', 'GetBasePath', 'availableLabels', 'i18n',
|
'ToJSON', 'ParseTypeChange', '$q', 'Rest', 'GetBasePath', 'availableLabels', 'i18n',
|
||||||
'resolvedModels', 'Inventory',
|
'resolvedModels',
|
||||||
function($scope, WorkflowForm, GenerateForm, Alert, ProcessErrors,
|
function($scope, WorkflowForm, GenerateForm, Alert, ProcessErrors,
|
||||||
Wait, $state, CreateSelect2, TemplatesService, ToJSON,
|
Wait, $state, CreateSelect2, TemplatesService, ToJSON,
|
||||||
ParseTypeChange, $q, Rest, GetBasePath, availableLabels, i18n,
|
ParseTypeChange, $q, Rest, GetBasePath, availableLabels, i18n,
|
||||||
resolvedModels, Inventory) {
|
resolvedModels) {
|
||||||
|
|
||||||
// Inject dynamic view
|
// Inject dynamic view
|
||||||
let form = WorkflowForm(),
|
let form = WorkflowForm(),
|
||||||
@@ -51,12 +51,6 @@ export default [
|
|||||||
$scope.workflowEditorTooltip = i18n._("Please save before defining the workflow graph.");
|
$scope.workflowEditorTooltip = i18n._("Please save before defining the workflow graph.");
|
||||||
$scope.surveyTooltip = i18n._('Please save before adding a survey to this workflow.');
|
$scope.surveyTooltip = i18n._('Please save before adding a survey to this workflow.');
|
||||||
|
|
||||||
|
|
||||||
if (Inventory){
|
|
||||||
$scope.inventory = Inventory.id;
|
|
||||||
$scope.inventory_name = Inventory.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.formSave = function () {
|
$scope.formSave = function () {
|
||||||
let fld, data = {};
|
let fld, data = {};
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export default [
|
|||||||
ProcessErrors, GetBasePath, $q, ParseTypeChange, Wait, Empty,
|
ProcessErrors, GetBasePath, $q, ParseTypeChange, Wait, Empty,
|
||||||
ToJSON, SurveyControllerInit, $state, CreateSelect2, ParseVariableString,
|
ToJSON, SurveyControllerInit, $state, CreateSelect2, ParseVariableString,
|
||||||
TemplatesService, Rest, ToggleNotification, OrgAdminLookup, availableLabels, selectedLabels, workflowJobTemplateData, i18n,
|
TemplatesService, Rest, ToggleNotification, OrgAdminLookup, availableLabels, selectedLabels, workflowJobTemplateData, i18n,
|
||||||
workflowLaunch, $transitions, WorkflowJobTemplate, Inventory,
|
workflowLaunch, $transitions, WorkflowJobTemplate, Inventory
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$scope.missingTemplates = _.has(workflowLaunch, 'node_templates_missing') && workflowLaunch.node_templates_missing.length > 0 ? true : false;
|
$scope.missingTemplates = _.has(workflowLaunch, 'node_templates_missing') && workflowLaunch.node_templates_missing.length > 0 ? true : false;
|
||||||
|
|||||||
@@ -568,7 +568,6 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
|||||||
/* EDIT NODE FUNCTIONS */
|
/* EDIT NODE FUNCTIONS */
|
||||||
|
|
||||||
$scope.startEditNode = function (nodeToEdit) {
|
$scope.startEditNode = function (nodeToEdit) {
|
||||||
|
|
||||||
if (!$scope.nodeBeingEdited || ($scope.nodeBeingEdited && $scope.nodeBeingEdited.id !== nodeToEdit.id)) {
|
if (!$scope.nodeBeingEdited || ($scope.nodeBeingEdited && $scope.nodeBeingEdited.id !== nodeToEdit.id)) {
|
||||||
if ($scope.placeholderNode || $scope.nodeBeingEdited) {
|
if ($scope.placeholderNode || $scope.nodeBeingEdited) {
|
||||||
$scope.cancelNodeForm();
|
$scope.cancelNodeForm();
|
||||||
@@ -1005,7 +1004,8 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
|||||||
|
|
||||||
$q.all([jobTemplate.optionsLaunch(selectedTemplate.id), jobTemplate.getLaunch(selectedTemplate.id)])
|
$q.all([jobTemplate.optionsLaunch(selectedTemplate.id), jobTemplate.getLaunch(selectedTemplate.id)])
|
||||||
.then((responses) => {
|
.then((responses) => {
|
||||||
let launchConf = responses[1].data;
|
const launchConf = jobTemplate.getLaunchConf();
|
||||||
|
|
||||||
if (selectedTemplate.type === 'job_template') {
|
if (selectedTemplate.type === 'job_template') {
|
||||||
if ((!selectedTemplate.inventory && !launchConf.ask_inventory_on_launch) || !selectedTemplate.project) {
|
if ((!selectedTemplate.inventory && !launchConf.ask_inventory_on_launch) || !selectedTemplate.project) {
|
||||||
$scope.selectedTemplateInvalid = true;
|
$scope.selectedTemplateInvalid = true;
|
||||||
@@ -1022,24 +1022,13 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
|||||||
|
|
||||||
$scope.selectedTemplate = angular.copy(selectedTemplate);
|
$scope.selectedTemplate = angular.copy(selectedTemplate);
|
||||||
|
|
||||||
if (!launchConf.survey_enabled &&
|
if (jobTemplate.canLaunchWithoutPrompt()) {
|
||||||
!launchConf.ask_inventory_on_launch &&
|
|
||||||
!launchConf.ask_credential_on_launch &&
|
|
||||||
!launchConf.ask_verbosity_on_launch &&
|
|
||||||
!launchConf.ask_job_type_on_launch &&
|
|
||||||
!launchConf.ask_limit_on_launch &&
|
|
||||||
!launchConf.ask_tags_on_launch &&
|
|
||||||
!launchConf.ask_skip_tags_on_launch &&
|
|
||||||
!launchConf.ask_diff_mode_on_launch &&
|
|
||||||
!launchConf.credential_needed_to_start &&
|
|
||||||
!launchConf.ask_variables_on_launch &&
|
|
||||||
launchConf.variables_needed_to_start.length === 0) {
|
|
||||||
$scope.showPromptButton = false;
|
$scope.showPromptButton = false;
|
||||||
$scope.promptModalMissingReqFields = false;
|
$scope.promptModalMissingReqFields = false;
|
||||||
} else {
|
} else {
|
||||||
$scope.showPromptButton = true;
|
$scope.showPromptButton = true;
|
||||||
|
|
||||||
if (selectedTemplate.type === 'job_template') {
|
if (['job_template', 'workflow_job_template'].includes(selectedTemplate.type)) {
|
||||||
if (launchConf.ask_inventory_on_launch && !_.has(launchConf, 'defaults.inventory')) {
|
if (launchConf.ask_inventory_on_launch && !_.has(launchConf, 'defaults.inventory')) {
|
||||||
$scope.promptModalMissingReqFields = true;
|
$scope.promptModalMissingReqFields = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -1059,9 +1048,8 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.missingSurveyValue = processed.missingSurveyValue;
|
$scope.missingSurveyValue = processed.missingSurveyValue;
|
||||||
|
|
||||||
$scope.promptData = {
|
$scope.promptData = {
|
||||||
launchConf: responses[1].data,
|
launchConf,
|
||||||
launchOptions: responses[0].data,
|
launchOptions: responses[0].data,
|
||||||
surveyQuestions: processed.surveyQuestions,
|
surveyQuestions: processed.surveyQuestions,
|
||||||
template: selectedTemplate.id,
|
template: selectedTemplate.id,
|
||||||
@@ -1084,8 +1072,9 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
|||||||
watchForPromptChanges();
|
watchForPromptChanges();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$scope.promptData = {
|
$scope.promptData = {
|
||||||
launchConf: responses[1].data,
|
launchConf,
|
||||||
launchOptions: responses[0].data,
|
launchOptions: responses[0].data,
|
||||||
template: selectedTemplate.id,
|
template: selectedTemplate.id,
|
||||||
prompts: PromptService.processPromptValues({
|
prompts: PromptService.processPromptValues({
|
||||||
|
|||||||
Reference in New Issue
Block a user