From 75d89fcda19995f5eec6864d2cb0a2c9eb1b27d7 Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Sat, 28 Jan 2017 11:45:08 -0500 Subject: [PATCH] Add workflow job templates to the recently used templates list on the dashboard --- awx/ui/client/src/controllers/Home.js | 4 +-- .../job-templates-list.directive.js | 25 ++++++++++++++++--- .../job-templates-list.partial.html | 4 +-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/awx/ui/client/src/controllers/Home.js b/awx/ui/client/src/controllers/Home.js index a4999487f6..3c81e7a798 100644 --- a/awx/ui/client/src/controllers/Home.js +++ b/awx/ui/client/src/controllers/Home.js @@ -47,7 +47,7 @@ export function Home($scope, $compile, $stateParams, $rootScope, $location, $log ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard jobs list: ' + status }); }); - Rest.setUrl(GetBasePath("job_templates") + "?order_by=-last_job_run&page_size=5&last_job_run__isnull=false"); + Rest.setUrl(GetBasePath("unified_job_templates") + "?order_by=-last_job_run&page_size=5&last_job_run__isnull=false&type=workflow_job_template,job_template"); Rest.get() .success(function (data) { $scope.dashboardJobTemplatesListData = data.results; @@ -123,7 +123,7 @@ export function Home($scope, $compile, $stateParams, $rootScope, $location, $log .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', msg: 'Failed to get dashboard jobs list: ' + status }); }); - Rest.setUrl(GetBasePath("job_templates") + "?order_by=-last_job_run&page_size=5&last_job_run__isnull=false"); + Rest.setUrl(GetBasePath("unified_job_templates") + "?order_by=-last_job_run&page_size=5&last_job_run__isnull=false&type=workflow_job_template,job_template"); Rest.get() .success(function (data) { data = data.results; diff --git a/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.directive.js b/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.directive.js index 82aca5b377..13fbfd8d6f 100644 --- a/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.directive.js +++ b/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.directive.js @@ -3,7 +3,8 @@ export default [ 'InitiatePlaybookRun', 'templateUrl', '$state', - function JobTemplatesList(InitiatePlaybookRun, templateUrl, $state) { + 'Alert', + function JobTemplatesList(InitiatePlaybookRun, templateUrl, $state, Alert) { return { restrict: 'E', link: link, @@ -32,7 +33,8 @@ export default launch_url: job_template.url, edit_url: job_template.url.replace('api/v1', '#'), name: job_template.name, - id: job_template.id + id: job_template.id, + type: job_template.type }; }); scope.snapRows = (list.length < 4); @@ -42,8 +44,23 @@ export default return (status === "successful"); }; - scope.launchJobTemplate = function(jobTemplateId){ - InitiatePlaybookRun({ scope: scope, id: jobTemplateId, job_type: 'job_template' }); + scope.launchJobTemplate = function(template){ + if(template) { + if(template.type && (template.type === 'Job Template' || template.type === 'job_template')) { + InitiatePlaybookRun({ scope: scope, id: template.id, job_type: 'job_template' }); + } + else if(template.type && (template.type === 'Workflow Job Template' || template.type === 'workflow_job_template')) { + InitiatePlaybookRun({ scope: scope, id: template.id, job_type: 'workflow_job_template' }); + } + 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.editJobTemplate = function (jobTemplateId) { diff --git a/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.partial.html b/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.partial.html index 8b404d9076..cffd21ce5c 100644 --- a/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.partial.html +++ b/awx/ui/client/src/dashboard/lists/job-templates/job-templates-list.partial.html @@ -1,7 +1,7 @@

- RECENTLY USED JOB TEMPLATES + RECENTLY USED TEMPLATES

VIEW ALL @@ -34,7 +34,7 @@
-