mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
add inventory prompt to wf editor
This commit is contained in:
parent
7178fb83b0
commit
2bd25b1fba
@ -97,12 +97,12 @@ function atLaunchTemplateCtrl (
|
||||
extra_vars: wfjtData.data.extra_vars
|
||||
};
|
||||
const promptData = {
|
||||
launchConf: launchData.data,
|
||||
launchConf: selectedWorkflowJobTemplate.getLaunchConf(),
|
||||
launchOptions: launchOptions.data,
|
||||
template: vm.template.id,
|
||||
templateType: vm.template.type,
|
||||
prompts: PromptService.processPromptValues({
|
||||
launchConf: launchData.data,
|
||||
launchConf: selectedWorkflowJobTemplate.getLaunchConf(),
|
||||
launchOptions: launchOptions.data
|
||||
}),
|
||||
triggerModalOpen: true,
|
||||
|
||||
@ -47,8 +47,15 @@ function getSurveyQuestions (id) {
|
||||
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 () {
|
||||
const launchData = this.model.launch.GET;
|
||||
const launchData = this.getLaunchConf();
|
||||
|
||||
return (
|
||||
launchData.can_start_without_user_input &&
|
||||
@ -61,7 +68,8 @@ function canLaunchWithoutPrompt () {
|
||||
!launchData.ask_skip_tags_on_launch &&
|
||||
!launchData.ask_variables_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.postLaunch = postLaunch.bind(this);
|
||||
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
||||
this.getLaunchConf = getLaunchConf.bind(this);
|
||||
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
||||
|
||||
this.model.launch = {};
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
/* eslint camelcase: 0 */
|
||||
let Base;
|
||||
let $http;
|
||||
let $q;
|
||||
|
||||
function optionsLaunch (id) {
|
||||
const req = {
|
||||
@ -11,16 +13,19 @@ function optionsLaunch (id) {
|
||||
}
|
||||
|
||||
function getLaunch (id) {
|
||||
const req = {
|
||||
method: 'GET',
|
||||
url: `${this.path}${id}/launch/`
|
||||
};
|
||||
const urls = [
|
||||
`${this.path}${id}/`,
|
||||
`${this.path}${id}/launch/`,
|
||||
];
|
||||
|
||||
return $http(req)
|
||||
.then(res => {
|
||||
this.model.launch.GET = res.data;
|
||||
const promises = urls.map(url => $http({ method: 'GET', url }));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 () {
|
||||
const launchData = this.model.launch.GET;
|
||||
const launchData = this.getLaunchConf();
|
||||
|
||||
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 &&
|
||||
!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.postLaunch = postLaunch.bind(this);
|
||||
this.getSurveyQuestions = getSurveyQuestions.bind(this);
|
||||
this.getLaunchConf = getLaunchConf.bind(this);
|
||||
this.canLaunchWithoutPrompt = canLaunchWithoutPrompt.bind(this);
|
||||
|
||||
this.model.launch = {};
|
||||
@ -72,16 +104,18 @@ function WorkflowJobTemplateModel (method, resource, config) {
|
||||
return this.create(method, resource, config);
|
||||
}
|
||||
|
||||
function WorkflowJobTemplateModelLoader (BaseModel, _$http_) {
|
||||
function WorkflowJobTemplateModelLoader (BaseModel, _$http_, _$q_) {
|
||||
Base = BaseModel;
|
||||
$http = _$http_;
|
||||
$q = _$q_;
|
||||
|
||||
return WorkflowJobTemplateModel;
|
||||
}
|
||||
|
||||
WorkflowJobTemplateModelLoader.$inject = [
|
||||
'BaseModel',
|
||||
'$http'
|
||||
'$http',
|
||||
'$q',
|
||||
];
|
||||
|
||||
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')) {
|
||||
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')){
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
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')){
|
||||
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')){
|
||||
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')){
|
||||
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;
|
||||
|
||||
@ -8,11 +8,11 @@ export default [
|
||||
'$scope', 'WorkflowForm', 'GenerateForm', 'Alert', 'ProcessErrors',
|
||||
'Wait', '$state', 'CreateSelect2', 'TemplatesService',
|
||||
'ToJSON', 'ParseTypeChange', '$q', 'Rest', 'GetBasePath', 'availableLabels', 'i18n',
|
||||
'resolvedModels', 'Inventory',
|
||||
'resolvedModels',
|
||||
function($scope, WorkflowForm, GenerateForm, Alert, ProcessErrors,
|
||||
Wait, $state, CreateSelect2, TemplatesService, ToJSON,
|
||||
ParseTypeChange, $q, Rest, GetBasePath, availableLabels, i18n,
|
||||
resolvedModels, Inventory) {
|
||||
resolvedModels) {
|
||||
|
||||
// Inject dynamic view
|
||||
let form = WorkflowForm(),
|
||||
@ -51,12 +51,6 @@ export default [
|
||||
$scope.workflowEditorTooltip = i18n._("Please save before defining the workflow graph.");
|
||||
$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 () {
|
||||
let fld, data = {};
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ export default [
|
||||
ProcessErrors, GetBasePath, $q, ParseTypeChange, Wait, Empty,
|
||||
ToJSON, SurveyControllerInit, $state, CreateSelect2, ParseVariableString,
|
||||
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;
|
||||
|
||||
@ -568,7 +568,6 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
||||
/* EDIT NODE FUNCTIONS */
|
||||
|
||||
$scope.startEditNode = function (nodeToEdit) {
|
||||
|
||||
if (!$scope.nodeBeingEdited || ($scope.nodeBeingEdited && $scope.nodeBeingEdited.id !== nodeToEdit.id)) {
|
||||
if ($scope.placeholderNode || $scope.nodeBeingEdited) {
|
||||
$scope.cancelNodeForm();
|
||||
@ -1005,7 +1004,8 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
||||
|
||||
$q.all([jobTemplate.optionsLaunch(selectedTemplate.id), jobTemplate.getLaunch(selectedTemplate.id)])
|
||||
.then((responses) => {
|
||||
let launchConf = responses[1].data;
|
||||
const launchConf = jobTemplate.getLaunchConf();
|
||||
|
||||
if (selectedTemplate.type === 'job_template') {
|
||||
if ((!selectedTemplate.inventory && !launchConf.ask_inventory_on_launch) || !selectedTemplate.project) {
|
||||
$scope.selectedTemplateInvalid = true;
|
||||
@ -1022,24 +1022,13 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
||||
|
||||
$scope.selectedTemplate = angular.copy(selectedTemplate);
|
||||
|
||||
if (!launchConf.survey_enabled &&
|
||||
!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) {
|
||||
if (jobTemplate.canLaunchWithoutPrompt()) {
|
||||
$scope.showPromptButton = false;
|
||||
$scope.promptModalMissingReqFields = false;
|
||||
} else {
|
||||
$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')) {
|
||||
$scope.promptModalMissingReqFields = true;
|
||||
} else {
|
||||
@ -1059,9 +1048,8 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
||||
});
|
||||
|
||||
$scope.missingSurveyValue = processed.missingSurveyValue;
|
||||
|
||||
$scope.promptData = {
|
||||
launchConf: responses[1].data,
|
||||
launchConf,
|
||||
launchOptions: responses[0].data,
|
||||
surveyQuestions: processed.surveyQuestions,
|
||||
template: selectedTemplate.id,
|
||||
@ -1084,8 +1072,9 @@ export default ['$scope', 'WorkflowService', 'TemplatesService',
|
||||
watchForPromptChanges();
|
||||
});
|
||||
} else {
|
||||
|
||||
$scope.promptData = {
|
||||
launchConf: responses[1].data,
|
||||
launchConf,
|
||||
launchOptions: responses[0].data,
|
||||
template: selectedTemplate.id,
|
||||
prompts: PromptService.processPromptValues({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user