diff --git a/awx/ui/client/features/templates/list-templates.controller.js b/awx/ui/client/features/templates/list-templates.controller.js
index 550a6fbe9c..321c991011 100644
--- a/awx/ui/client/features/templates/list-templates.controller.js
+++ b/awx/ui/client/features/templates/list-templates.controller.js
@@ -18,7 +18,6 @@ function ListTemplatesController(
Dataset,
ProcessErrors,
Prompt,
- PromptService,
resolvedModels,
strings,
Wait
@@ -68,21 +67,6 @@ function ListTemplatesController(
}
};
- vm.runTemplate = template => {
- if (!template) {
- Alert(strings.get('error.LAUNCH'), strings.get('alert.MISSING_PARAMETER'));
- return;
- }
-
- if (isJobTemplate(template)) {
- runJobTemplate(template);
- } else if (isWorkflowTemplate(template)) {
- runWorkflowTemplate(template);
- } else {
- Alert(strings.get('error.UNKNOWN'), strings.get('alert.UNKNOWN_LAUNCH'));
- }
- };
-
vm.scheduleTemplate = template => {
if (!template) {
Alert(strings.get('error.SCHEDULE'), strings.get('alert.MISSING_PARAMETER'));
@@ -323,120 +307,6 @@ function ListTemplatesController(
return html;
}
-
- function runJobTemplate(template) {
- const selectedJobTemplate = jobTemplate.create();
- const preLaunchPromises = [
- selectedJobTemplate.getLaunch(template.id),
- selectedJobTemplate.optionsLaunch(template.id),
- ];
-
- Promise.all(preLaunchPromises)
- .then(([launchData, launchOptions]) => {
- if (selectedJobTemplate.canLaunchWithoutPrompt()) {
- return selectedJobTemplate
- .postLaunch({ id: template.id })
- .then(({ data }) => {
- $state.go('jobResult', { id: data.job }, { reload: true });
- });
- }
-
- const promptData = {
- launchConf: launchData.data,
- launchOptions: launchOptions.data,
- template: template.id,
- templateType: template.type,
- prompts: PromptService.processPromptValues({
- launchConf: launchData.data,
- launchOptions: launchOptions.data
- }),
- triggerModalOpen: true,
- };
-
- if (launchData.data.survey_enabled) {
- selectedJobTemplate.getSurveyQuestions(template.id)
- .then(({ data }) => {
- const processed = PromptService.processSurveyQuestions({ surveyQuestions: data.spec });
- promptData.surveyQuestions = processed.surveyQuestions;
- $scope.promptData = promptData;
- });
- } else {
- $scope.promptData = promptData;
- }
- });
- }
-
- function runWorkflowTemplate(template) {
- const selectedWorkflowJobTemplate = workflowTemplate.create();
- const preLaunchPromises = [
- selectedWorkflowJobTemplate.getLaunch(template.id),
- selectedWorkflowJobTemplate.optionsLaunch(template.id),
- ];
-
- Promise.all(preLaunchPromises)
- .then(([launchData, launchOptions]) => {
- if (selectedWorkflowJobTemplate.canLaunchWithoutPrompt()) {
- return selectedWorkflowJobTemplate
- .postLaunch({ id: template.id })
- .then(({ data }) => {
- $state.go('workflowResults', { id: data.workflow_job }, { reload: true });
- });
- }
-
- const promptData = {
- launchConf: launchData.data,
- launchOptions: launchOptions.data,
- template: template.id,
- templateType: template.type,
- prompts: PromptService.processPromptValues({
- launchConf: launchData.data,
- launchOptions: launchOptions.data
- }),
- triggerModalOpen: true,
- };
-
- if (launchData.data.survey_enabled) {
- selectedWorkflowJobTemplate.getSurveyQuestions(template.id)
- .then(({ data }) => {
- const processed = PromptService.processSurveyQuestions({ surveyQuestions: data.spec });
- promptData.surveyQuestions = processed.surveyQuestions;
- $scope.promptData = promptData;
- });
- } else {
- $scope.promptData = promptData;
- }
- });
- }
-
- $scope.launchJob = () => {
- const jobLaunchData = PromptService.bundlePromptDataForLaunch($scope.promptData);
-
- // If the extra_vars dict is empty, we don't want to include it if we didn't prompt for anything.
- if(_.isEmpty(jobLaunchData.extra_vars) && !($scope.promptData.launchConf.ask_variables_on_launch && $scope.promptData.launchConf.survey_enabled && $scope.promptData.surveyQuestions.length > 0)){
- delete jobLaunchData.extra_vars;
- }
-
- if($scope.promptData.templateType === 'job_template') {
- jobTemplate.create().postLaunch({
- id: $scope.promptData.template,
- launchData: jobLaunchData
- })
- .then((launchRes) => {
- $state.go('jobResult', { id: launchRes.data.job }, { reload: true });
- })
- .catch(createErrorHandler('launch job template', 'POST'));
- } else if($scope.promptData.templateType === 'workflow_job_template') {
- workflowTemplate.create().postLaunch({
- id: $scope.promptData.template,
- launchData: jobLaunchData
- })
- .then((launchRes) => {
- $state.go('workflowResults', { id: launchRes.data.workflow_job }, { reload: true });
- })
- .catch(createErrorHandler('launch workflow job template', 'POST'));
- }
-
- };
}
ListTemplatesController.$inject = [
@@ -447,7 +317,6 @@ ListTemplatesController.$inject = [
'Dataset',
'ProcessErrors',
'Prompt',
- 'PromptService',
'resolvedModels',
'TemplatesStrings',
'Wait'
diff --git a/awx/ui/client/features/templates/list.route.js b/awx/ui/client/features/templates/list.route.js
index 2750a0e8a7..e08b2fc863 100644
--- a/awx/ui/client/features/templates/list.route.js
+++ b/awx/ui/client/features/templates/list.route.js
@@ -27,7 +27,7 @@ export default {
dynamic: true,
value: {
type: 'workflow_job_template,job_template',
- },
+ },
}
},
searchPrefix: 'template',
@@ -61,7 +61,7 @@ export default {
Wait('start');
return qs.search(searchPath, searchParam)
- .finally(() => Wait('stop'))
+ .finally(() => Wait('stop'));
}
],
}
diff --git a/awx/ui/client/features/templates/list.view.html b/awx/ui/client/features/templates/list.view.html
index d91e5f281e..a6557423ce 100644
--- a/awx/ui/client/features/templates/list.view.html
+++ b/awx/ui/client/features/templates/list.view.html
@@ -98,9 +98,9 @@
-
-
+
@@ -121,5 +121,4 @@
query-set="querySet">
-
diff --git a/awx/ui/client/lib/components/_index.less b/awx/ui/client/lib/components/_index.less
index 6fdef9ece1..ae992079c9 100644
--- a/awx/ui/client/lib/components/_index.less
+++ b/awx/ui/client/lib/components/_index.less
@@ -1,11 +1,12 @@
@import 'action/_index';
@import 'input/_index';
+@import 'launchTemplateButton/_index';
@import 'layout/_index';
@import 'list/_index';
@import 'modal/_index';
@import 'panel/_index';
@import 'popover/_index';
+@import 'relaunchButton/_index';
@import 'tabs/_index';
-@import 'utility/_index';
@import 'truncate/_index';
-@import 'relaunchButton/_index';
\ No newline at end of file
+@import 'utility/_index';
diff --git a/awx/ui/client/lib/components/index.js b/awx/ui/client/lib/components/index.js
index d33e79329a..9ac933628c 100644
--- a/awx/ui/client/lib/components/index.js
+++ b/awx/ui/client/lib/components/index.js
@@ -16,23 +16,24 @@ import inputSlider from '~components/input/slider.directive';
import inputText from '~components/input/text.directive';
import inputTextarea from '~components/input/textarea.directive';
import inputTextareaSecret from '~components/input/textarea-secret.directive';
+import launchTemplate from '~components/launchTemplateButton/launchTemplateButton.component';
import layout from '~components/layout/layout.directive';
import list from '~components/list/list.directive';
-import row from '~components/list/row.directive';
-import rowItem from '~components/list/row-item.directive';
-import rowAction from '~components/list/row-action.directive';
import modal from '~components/modal/modal.directive';
import panel from '~components/panel/panel.directive';
import panelBody from '~components/panel/body.directive';
import panelHeading from '~components/panel/heading.directive';
import popover from '~components/popover/popover.directive';
+import relaunch from '~components/relaunchButton/relaunchButton.component';
+import row from '~components/list/row.directive';
+import rowItem from '~components/list/row-item.directive';
+import rowAction from '~components/list/row-action.directive';
import sideNav from '~components/layout/side-nav.directive';
import sideNavItem from '~components/layout/side-nav-item.directive';
import tab from '~components/tabs/tab.directive';
import tabGroup from '~components/tabs/group.directive';
import topNavItem from '~components/layout/top-nav-item.directive';
import truncate from '~components/truncate/truncate.directive';
-import relaunch from '~components/relaunchButton/relaunchButton.component';
import BaseInputController from '~components/input/base.controller';
import ComponentsStrings from '~components/components.strings';
@@ -59,8 +60,10 @@ angular
.directive('atInputText', inputText)
.directive('atInputTextarea', inputTextarea)
.directive('atInputTextareaSecret', inputTextareaSecret)
+ .component('atLaunchTemplate', launchTemplate)
.directive('atLayout', layout)
.directive('atList', list)
+ .component('atRelaunch', relaunch)
.directive('atRow', row)
.directive('atRowItem', rowItem)
.directive('atRowAction', rowAction)
@@ -75,7 +78,6 @@ angular
.directive('atTabGroup', tabGroup)
.directive('atTopNavItem', topNavItem)
.directive('atTruncate', truncate)
- .component('atRelaunch', relaunch)
.service('BaseInputController', BaseInputController)
.service('ComponentsStrings', ComponentsStrings);
diff --git a/awx/ui/client/lib/components/launchTemplateButton/_index.less b/awx/ui/client/lib/components/launchTemplateButton/_index.less
new file mode 100644
index 0000000000..d5c39547ff
--- /dev/null
+++ b/awx/ui/client/lib/components/launchTemplateButton/_index.less
@@ -0,0 +1,24 @@
+.at-LaunchTemplate {
+ margin-left: 15px;
+
+ &--button {
+ font-size: 16px;
+ height: 30px;
+ min-width: 30px;
+ color: #848992;
+ background-color: inherit;
+ border: none;
+ border-radius: 4px;
+ }
+ &--button:hover {
+ background-color: @at-blue;
+ color: white;
+ }
+}
+
+.open {
+ .at-LaunchTemplate--button {
+ background-color: @at-blue;
+ color: white;
+ }
+}
diff --git a/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.component.js b/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.component.js
new file mode 100644
index 0000000000..4081f29bff
--- /dev/null
+++ b/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.component.js
@@ -0,0 +1,152 @@
+import templateUrl from './launchTemplateButton.partial.html';
+
+const atLaunchTemplate = {
+ templateUrl,
+ bindings: {
+ template: '<'
+ },
+ controller: ['JobTemplateModel', 'WorkflowJobTemplateModel', 'PromptService', '$state',
+ 'ProcessErrors', '$scope', 'TemplatesStrings', 'Alert', atLaunchTemplateCtrl],
+ controllerAs: 'vm'
+};
+
+function atLaunchTemplateCtrl (
+ JobTemplate, WorkflowTemplate, PromptService, $state,
+ ProcessErrors, $scope, strings, Alert
+) {
+ const vm = this;
+ const jobTemplate = new JobTemplate();
+ const workflowTemplate = new WorkflowTemplate();
+
+ const createErrorHandler = (path, action) =>
+ ({ data, status }) => {
+ const hdr = strings.get('error.HEADER');
+ const msg = strings.get('error.CALL', { path, action, status });
+ ProcessErrors($scope, data, status, null, { hdr, msg });
+ };
+
+ vm.startLaunchTemplate = () => {
+ if (vm.template.type === 'job_template') {
+ const selectedJobTemplate = jobTemplate.create();
+ const preLaunchPromises = [
+ selectedJobTemplate.getLaunch(vm.template.id),
+ selectedJobTemplate.optionsLaunch(vm.template.id),
+ ];
+
+ Promise.all(preLaunchPromises)
+ .then(([launchData, launchOptions]) => {
+ if (selectedJobTemplate.canLaunchWithoutPrompt()) {
+ selectedJobTemplate
+ .postLaunch({ id: vm.template.id })
+ .then(({ data }) => {
+ $state.go('jobResult', { id: data.job }, { reload: true });
+ });
+ } else {
+ const promptData = {
+ launchConf: launchData.data,
+ launchOptions: launchOptions.data,
+ template: vm.template.id,
+ templateType: vm.template.type,
+ prompts: PromptService.processPromptValues({
+ launchConf: launchData.data,
+ launchOptions: launchOptions.data
+ }),
+ triggerModalOpen: true,
+ };
+
+ if (launchData.data.survey_enabled) {
+ selectedJobTemplate.getSurveyQuestions(vm.template.id)
+ .then(({ data }) => {
+ const processed = PromptService.processSurveyQuestions({
+ surveyQuestions: data.spec
+ });
+ promptData.surveyQuestions = processed.surveyQuestions;
+ vm.promptData = promptData;
+ });
+ } else {
+ vm.promptData = promptData;
+ }
+ }
+ });
+ } else if (vm.template.type === 'workflow_job_template') {
+ const selectedWorkflowJobTemplate = workflowTemplate.create();
+ const preLaunchPromises = [
+ selectedWorkflowJobTemplate.getLaunch(vm.template.id),
+ selectedWorkflowJobTemplate.optionsLaunch(vm.template.id),
+ ];
+
+ Promise.all(preLaunchPromises)
+ .then(([launchData, launchOptions]) => {
+ if (selectedWorkflowJobTemplate.canLaunchWithoutPrompt()) {
+ selectedWorkflowJobTemplate
+ .postLaunch({ id: vm.template.id })
+ .then(({ data }) => {
+ $state.go('workflowResults', { id: data.workflow_job }, { reload: true });
+ });
+ } else {
+ const promptData = {
+ launchConf: launchData.data,
+ launchOptions: launchOptions.data,
+ template: vm.template.id,
+ templateType: vm.template.type,
+ prompts: PromptService.processPromptValues({
+ launchConf: launchData.data,
+ launchOptions: launchOptions.data
+ }),
+ triggerModalOpen: true,
+ };
+
+ if (launchData.data.survey_enabled) {
+ selectedWorkflowJobTemplate.getSurveyQuestions(vm.template.id)
+ .then(({ data }) => {
+ const processed = PromptService.processSurveyQuestions({
+ surveyQuestions: data.spec
+ });
+ promptData.surveyQuestions = processed.surveyQuestions;
+ vm.promptData = promptData;
+ });
+ } else {
+ vm.promptData = promptData;
+ }
+ }
+ });
+ } else {
+ Alert(strings.get('error.UNKNOWN'), strings.get('alert.UNKNOWN_LAUNCH'));
+ }
+ };
+
+ vm.launchTemplateWithPrompts = () => {
+ const jobLaunchData = PromptService.bundlePromptDataForLaunch(vm.promptData);
+
+ // If the extra_vars dict is empty, we don't want to include it
+ // if we didn't prompt for anything.
+ if (
+ _.isEmpty(jobLaunchData.extra_vars) &&
+ !(
+ vm.promptData.launchConf.ask_variables_on_launch &&
+ vm.promptData.launchConf.survey_enabled &&
+ vm.promptData.surveyQuestions.length > 0
+ )
+ ) {
+ delete jobLaunchData.extra_vars;
+ }
+
+ if (vm.promptData.templateType === 'job_template') {
+ jobTemplate.create().postLaunch({
+ id: vm.promptData.template,
+ launchData: jobLaunchData
+ }).then((launchRes) => {
+ $state.go('jobResult', { id: launchRes.data.job }, { reload: true });
+ }).catch(createErrorHandler('launch job template', 'POST'));
+ } else if (vm.promptData.templateType === 'workflow_job_template') {
+ workflowTemplate.create().postLaunch({
+ id: vm.promptData.template,
+ launchData: jobLaunchData
+ }).then((launchRes) => {
+ $state.go('workflowResults', { id: launchRes.data.workflow_job }, { reload: true });
+ }).catch(createErrorHandler('launch workflow job template', 'POST'));
+ }
+ };
+}
+
+export default atLaunchTemplate;
diff --git a/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.partial.html b/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.partial.html
new file mode 100644
index 0000000000..5be2373264
--- /dev/null
+++ b/awx/ui/client/lib/components/launchTemplateButton/launchTemplateButton.partial.html
@@ -0,0 +1,7 @@
+
diff --git a/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js b/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js
index 71024d4b25..045afd3585 100644
--- a/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js
+++ b/awx/ui/client/lib/components/relaunchButton/relaunchButton.component.js
@@ -3,12 +3,12 @@ import templateUrl from './relaunchButton.partial.html';
const atRelaunch = {
templateUrl,
bindings: {
- state: '<'
+ job: '<'
},
controller: ['ProcessErrors', 'AdhocRun', 'ComponentsStrings',
'ProjectModel', 'InventorySourceModel', 'WorkflowJobModel', 'Alert',
'AdHocCommandModel', 'JobModel', 'JobTemplateModel', 'PromptService',
- 'GetBasePath', '$state', '$q', '$scope', atRelaunchCtrl
+ '$state', '$q', '$scope', atRelaunchCtrl
],
controllerAs: 'vm'
};
@@ -17,25 +17,23 @@ function atRelaunchCtrl (
ProcessErrors, AdhocRun, strings,
Project, InventorySource, WorkflowJob, Alert,
AdHocCommand, Job, JobTemplate, PromptService,
- GetBasePath, $state, $q, $scope
+ $state, $q, $scope
) {
const vm = this;
- const scope = $scope.$parent;
- const job = _.get(scope, 'job') || _.get(scope, 'completed_job');
const jobObj = new Job();
const jobTemplate = new JobTemplate();
const checkRelaunchPlaybook = (option) => {
jobObj.getRelaunch({
- id: job.id
+ id: vm.job.id
}).then((getRelaunchRes) => {
if (
getRelaunchRes.data.passwords_needed_to_start &&
getRelaunchRes.data.passwords_needed_to_start.length > 0
) {
const jobPromises = [
- jobObj.request('get', job.id),
- jobTemplate.optionsLaunch(job.unified_job_template)
+ jobObj.request('get', vm.job.id),
+ jobTemplate.optionsLaunch(vm.job.unified_job_template)
];
$q.all(jobPromises)
@@ -66,7 +64,7 @@ function atRelaunchCtrl (
getRelaunchRes.data.passwords_needed_to_start
},
launchOptions: launchOptions.data,
- job: job.id,
+ job: vm.job.id,
relaunchHostType: option ? (option.name).toLowerCase() : null,
prompts: {
credentials: {
@@ -104,7 +102,7 @@ function atRelaunchCtrl (
});
} else {
jobObj.postRelaunch({
- id: job.id
+ id: vm.job.id
}).then((launchRes) => {
if (!$state.includes('jobs')) {
$state.go('jobResult', { id: launchRes.data.id }, { reload: true });
@@ -115,8 +113,8 @@ function atRelaunchCtrl (
};
vm.$onInit = () => {
- vm.showRelaunch = job.type !== 'system_job' && job.summary_fields.user_capabilities.start;
- vm.showDropdown = job.type === 'job' && job.failed === true;
+ vm.showRelaunch = vm.job.type !== 'system_job' && vm.job.summary_fields.user_capabilities.start;
+ vm.showDropdown = vm.job.type === 'job' && vm.job.failed === true;
vm.createDropdown();
vm.createTooltips();
@@ -146,13 +144,13 @@ function atRelaunchCtrl (
};
vm.relaunchJob = () => {
- if (job.type === 'inventory_update') {
+ if (vm.job.type === 'inventory_update') {
const inventorySource = new InventorySource();
- inventorySource.getUpdate(job.inventory_source)
+ inventorySource.getUpdate(vm.job.inventory_source)
.then((getUpdateRes) => {
if (getUpdateRes.data.can_update) {
- inventorySource.postUpdate(job.inventory_source)
+ inventorySource.postUpdate(vm.job.inventory_source)
.then((postUpdateRes) => {
if (!$state.includes('jobs')) {
$state.go('inventorySyncStdout', { id: postUpdateRes.data.id }, { reload: true });
@@ -165,13 +163,13 @@ function atRelaunchCtrl (
);
}
});
- } else if (job.type === 'project_update') {
+ } else if (vm.job.type === 'project_update') {
const project = new Project();
- project.getUpdate(job.project)
+ project.getUpdate(vm.job.project)
.then((getUpdateRes) => {
if (getUpdateRes.data.can_update) {
- project.postUpdate(job.project)
+ project.postUpdate(vm.job.project)
.then((postUpdateRes) => {
if (!$state.includes('jobs')) {
$state.go('scmUpdateStdout', { id: postUpdateRes.data.id }, { reload: true });
@@ -184,30 +182,30 @@ function atRelaunchCtrl (
);
}
});
- } else if (job.type === 'workflow_job') {
+ } else if (vm.job.type === 'workflow_job') {
const workflowJob = new WorkflowJob();
workflowJob.postRelaunch({
- id: job.id
+ id: vm.job.id
}).then((launchRes) => {
if (!$state.includes('jobs')) {
$state.go('workflowResults', { id: launchRes.data.id }, { reload: true });
}
});
- } else if (job.type === 'ad_hoc_command') {
+ } else if (vm.job.type === 'ad_hoc_command') {
const adHocCommand = new AdHocCommand();
adHocCommand.getRelaunch({
- id: job.id
+ id: vm.job.id
}).then((getRelaunchRes) => {
if (
getRelaunchRes.data.passwords_needed_to_start &&
getRelaunchRes.data.passwords_needed_to_start.length > 0
) {
- AdhocRun({ scope, project_id: job.id, relaunch: true });
+ AdhocRun({ scope: $scope, project_id: vm.job.id, relaunch: true });
} else {
adHocCommand.postRelaunch({
- id: job.id
+ id: vm.job.id
}).then((launchRes) => {
if (!$state.includes('jobs')) {
$state.go('adHocJobStdout', { id: launchRes.data.id }, { reload: true });
@@ -215,7 +213,7 @@ function atRelaunchCtrl (
});
}
});
- } else if (job.type === 'job') {
+ } else if (vm.job.type === 'job') {
checkRelaunchPlaybook();
}
};
diff --git a/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.directive.js b/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.directive.js
index 0456388539..7bb40ab40b 100644
--- a/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.directive.js
+++ b/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.directive.js
@@ -2,12 +2,7 @@
export default
[ 'templateUrl',
'$state',
- 'Alert',
- 'JobTemplateModel',
- 'WorkflowJobTemplateModel',
- 'PromptService',
- 'ProcessErrors',
- function JobTemplatesList(templateUrl, $state, Alert, JobTemplate, WorkflowJobTemplate, PromptService, ProcessErrors) {
+ function JobTemplatesList(templateUrl, $state) {
return {
restrict: 'E',
link: link,
@@ -18,8 +13,6 @@ export default
};
function link(scope, element, attr) {
- const jobTemplate = new JobTemplate();
- const workflowTemplate = new WorkflowJobTemplate();
scope.$watch("data", function(data) {
if (data) {
@@ -36,6 +29,7 @@ export default
// smartStatus?, launchUrl, editUrl, name
scope.templates = _.map(list, function(template){ return {
recent_jobs: template.summary_fields.recent_jobs,
+ can_start: template.summary_fields.user_capabilities.start,
name: template.name,
id: template.id,
type: template.type
@@ -46,135 +40,6 @@ export default
return (status === "successful");
};
- scope.launchTemplate = function(template){
- if(template) {
- if(template.type && (template.type === 'Job Template' || template.type === 'job_template')) {
- const selectedJobTemplate = jobTemplate.create();
- const preLaunchPromises = [
- selectedJobTemplate.getLaunch(template.id),
- selectedJobTemplate.optionsLaunch(template.id),
- ];
-
- Promise.all(preLaunchPromises)
- .then(([launchData, launchOptions]) => {
- if (selectedJobTemplate.canLaunchWithoutPrompt()) {
- return selectedJobTemplate
- .postLaunch({ id: template.id })
- .then(({ data }) => {
- $state.go('jobResult', { id: data.job }, { reload: true });
- });
- }
-
- const promptData = {
- launchConf: launchData.data,
- launchOptions: launchOptions.data,
- template: template.id,
- templateType: template.type,
- prompts: PromptService.processPromptValues({
- launchConf: launchData.data,
- launchOptions: launchOptions.data
- }),
- triggerModalOpen: true,
- };
-
- if (launchData.data.survey_enabled) {
- selectedJobTemplate.getSurveyQuestions(template.id)
- .then(({ data }) => {
- const processed = PromptService.processSurveyQuestions({ surveyQuestions: data.spec });
- promptData.surveyQuestions = processed.surveyQuestions;
- scope.promptData = promptData;
- });
- } else {
- scope.promptData = promptData;
- }
- });
- }
- else if(template.type && (template.type === 'Workflow Job Template' || template.type === 'workflow_job_template')) {
- const selectedWorkflowJobTemplate = workflowTemplate.create();
- const preLaunchPromises = [
- selectedWorkflowJobTemplate.getLaunch(template.id),
- selectedWorkflowJobTemplate.optionsLaunch(template.id),
- ];
-
- Promise.all(preLaunchPromises)
- .then(([launchData, launchOptions]) => {
- if (selectedWorkflowJobTemplate.canLaunchWithoutPrompt()) {
- return selectedWorkflowJobTemplate
- .postLaunch({ id: template.id })
- .then(({ data }) => {
- $state.go('workflowResults', { id: data.workflow_job }, { reload: true });
- });
- }
-
- const promptData = {
- launchConf: launchData.data,
- launchOptions: launchOptions.data,
- template: template.id,
- templateType: template.type,
- prompts: PromptService.processPromptValues({
- launchConf: launchData.data,
- launchOptions: launchOptions.data
- }),
- triggerModalOpen: true,
- };
-
- if (launchData.data.survey_enabled) {
- selectedWorkflowJobTemplate.getSurveyQuestions(template.id)
- .then(({ data }) => {
- const processed = PromptService.processSurveyQuestions({ surveyQuestions: data.spec });
- promptData.surveyQuestions = processed.surveyQuestions;
- scope.promptData = promptData;
- });
- } else {
- scope.promptData = promptData;
- }
- });
- }
- else {
- // Something went wrong - Let the user know that we're unable to launch because we don't know
- // what type of job template this is
- Alert('Error: Unable to determine template type', 'We were unable to determine this template\'s type while launching.');
- }
- }
- else {
- Alert('Error: Unable to launch template', 'Template parameter is missing');
- }
- };
-
- scope.launchJob = () => {
- const jobLaunchData = PromptService.bundlePromptDataForLaunch(scope.promptData);
-
- // If the extra_vars dict is empty, we don't want to include it if we didn't prompt for anything.
- if(_.isEmpty(jobLaunchData.extra_vars) && !(scope.promptData.launchConf.ask_variables_on_launch && scope.promptData.launchConf.survey_enabled && scope.promptData.surveyQuestions.length > 0)){
- delete jobLaunchData.extra_vars;
- }
-
- if(scope.promptData.templateType === 'job_template') {
- jobTemplate.create().postLaunch({
- id: scope.promptData.template,
- launchData: jobLaunchData
- })
- .then((launchRes) => {
- $state.go('jobResult', { id: launchRes.data.job }, { reload: true });
- })
- .catch(({data, status}) => {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to launch job template: ' + status });
- });
- } else if(scope.promptData.templateType === 'workflow_job_template') {
- workflowTemplate.create().postLaunch({
- id: scope.promptData.template,
- launchData: jobLaunchData
- })
- .then((launchRes) => {
- $state.go('workflowResults', { id: launchRes.data.workflow_job }, { reload: true });
- })
- .catch(({data, status}) => {
- ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Failed to launch workflow job template: ' + status });
- });
- }
-
- };
-
scope.editTemplate = function (template) {
if(template) {
if(template.type && (template.type === 'Job Template' || template.type === 'job_template')) {
diff --git a/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.partial.html b/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.partial.html
index 67a1795f7d..c80c4f955e 100644
--- a/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.partial.html
+++ b/awx/ui/client/src/home/dashboard/lists/job-templates/job-templates-list.partial.html
@@ -32,9 +32,9 @@
|