diff --git a/awx/ui/client/src/home/home.controller.js b/awx/ui/client/src/home/home.controller.js index dece46ab1c..2a0228c124 100644 --- a/awx/ui/client/src/home/home.controller.js +++ b/awx/ui/client/src/home/home.controller.js @@ -19,6 +19,94 @@ export default ['$scope','Wait', '$timeout', 'i18n', let newJobs = []; let newTemplates =[]; + const fetchDashboardData = () => { + Rest.setUrl(GetBasePath('dashboard')); + Rest.get() + .then(({data}) => { + $scope.dashboardData = data; + }) + .catch(({data, status}) => { + ProcessErrors($scope, data, status, null, { hdr: i18n._('Error!'), msg: i18n._(`Failed to get dashboard host graph data: ${status}`) }); + }); + + if ($scope.graphData) { + Rest.setUrl(`${GetBasePath('dashboard')}graphs/jobs/?period=${$scope.graphData.period}&job_type=${$scope.graphData.jobType}`); + Rest.setHeader({'X-WS-Session-Quiet': true}); + Rest.get() + .then(function(value) { + if($scope.graphData.status === "successful" || $scope.graphData.status === "failed"){ + delete value.data.jobs[$scope.graphData.status]; + } + $scope.graphData.jobStatus = value.data; + }) + .catch(function({data, status}) { + ProcessErrors(null, data, status, null, { hdr: i18n._('Error!'), msg: i18n._(`Failed to get dashboard graph data: ${status}`)}); + }); + } + + pendingDashboardRefresh = false; + dashboardTimerRunning = true; + $timeout(() => { + if (pendingDashboardRefresh) { + fetchDashboardData(); + } else { + dashboardTimerRunning = false; + } + }, 5000); + }; + + const fetchNewJobs = () => { + newJobsTimerRunning = true; + const newJobIdsFilter = newJobs.join(','); + newJobs = []; + Rest.setUrl(`${GetBasePath("unified_jobs")}?id__in=${newJobIdsFilter}&order_by=-finished&finished__isnull=false&type=workflow_job,job&count_disabled=1`); + Rest.get() + .then(({ data }) => { + const joinedJobs = data.results.concat($scope.dashboardJobsListData); + $scope.dashboardJobsListData = + joinedJobs.length > 5 ? joinedJobs.slice(0, 5) : joinedJobs; + $timeout(() => { + if (newJobs.length > 0) { + fetchNewJobs(); + } else { + newJobsTimerRunning = false; + } + }, 5000); + }) + .catch(({ data, status }) => { + ProcessErrors($scope, data, status, null, { + hdr: i18n._('Error!'), + msg: i18n._(`Failed to get new jobs for dashboard: ${status}`) + }); + }); + }; + + const fetchNewTemplates = () => { + newTemplatesTimerRunning = true; + const newTemplateIdsFilter = newTemplates.join(','); + newTemplates = []; + Rest.setUrl(`${GetBasePath("unified_job_templates")}?id__in=${newTemplateIdsFilter}&order_by=-last_job_run&last_job_run__isnull=false&type=workflow_job_template,job_template&count_disabled=1"`); + Rest.get() + .then(({ data }) => { + const joinedTemplates = data.results.concat($scope.dashboardJobTemplatesListData).sort((a, b) => new Date(b.last_job_run) - new Date(a.last_job_run)); + $scope.dashboardJobTemplatesListData = + joinedTemplates.length > 5 ? joinedTemplates.slice(0, 5) : joinedTemplates; + $timeout(() => { + if (newTemplates.length > 0 && !launchModalOpen) { + fetchNewTemplates(); + } else { + newTemplatesTimerRunning = false; + } + }, 5000); + }) + .catch(({ data, status }) => { + ProcessErrors($scope, data, status, null, { + hdr: i18n._('Error!'), + msg: i18n._(`Failed to get new templates for dashboard: ${status}`) + }); + }); + }; + $scope.$on('ws-jobs', function (e, msg) { if (msg.status === 'successful' || msg.status === 'failed' || msg.status === 'canceled') { newJobs.push(msg.unified_job_id); @@ -59,7 +147,7 @@ export default ['$scope','Wait', '$timeout', 'i18n', } break; } - }; + } if (msg.status === 'successful' || msg.status === 'failed' || msg.status === 'canceled') { $scope.dashboardJobTemplatesListData.sort((a, b) => new Date(b.last_job_run) - new Date(a.last_job_run)); @@ -124,96 +212,6 @@ export default ['$scope','Wait', '$timeout', 'i18n', $scope.$emit('dashboardDataLoadComplete'); }); - const fetchDashboardData = () => { - Rest.setUrl(GetBasePath('dashboard')); - Rest.get() - .then(({data}) => { - $scope.dashboardData = data; - }) - .catch(({data, status}) => { - ProcessErrors($scope, data, status, null, { hdr: i18n._('Error!'), msg: i18n._(`Failed to get dashboard host graph data: ${status}`) }); - }); - - if ($scope.graphData) { - Rest.setUrl(`${GetBasePath('dashboard')}graphs/jobs/?period=${$scope.graphData.period}&job_type=${$scope.graphData.jobType}`); - Rest.setHeader({'X-WS-Session-Quiet': true}); - Rest.get() - .then(function(value) { - if($scope.graphData.status === "successful" || $scope.graphData.status === "failed"){ - delete value.data.jobs[$scope.graphData.status]; - } - $scope.graphData.jobStatus = value.data; - }) - .catch(function({data, status}) { - ProcessErrors(null, data, status, null, { hdr: i18n._('Error!'), msg: i18n._(`Failed to get dashboard graph data: ${status}`)}); - }); - } - - pendingDashboardRefresh = false; - dashboardTimerRunning = true; - $timeout(() => { - if (pendingDashboardRefresh) { - fetchDashboardData(); - } else { - dashboardTimerRunning = false; - } - }, 5000); - }; - - const fetchNewJobs = () => { - newJobsTimerRunning = true; - const newJobIdsFilter = newJobs.join(','); - newJobs = []; - Rest.setUrl(`${GetBasePath("unified_jobs")}?id__in=${newJobIdsFilter}&order_by=-finished&finished__isnull=false&type=workflow_job,job&count_disabled=1`); - Rest.get() - .then(({ data }) => { - const joinedJobs = data.results.concat($scope.dashboardJobsListData); - $scope.dashboardJobsListData = joinedJobs.length > 5 - ? joinedJobs.slice(0, 5) - : joinedJobs; - $timeout(() => { - if (newJobs.length > 0) { - fetchNewJobs(); - } else { - newJobsTimerRunning = false; - } - }, 5000); - }) - .catch(({ data, status }) => { - ProcessErrors($scope, data, status, null, { - hdr: i18n._('Error!'), - msg: i18n._(`Failed to get new jobs for dashboard: ${status}`) - }); - }); - }; - - const fetchNewTemplates = () => { - newTemplatesTimerRunning = true; - const newTemplateIdsFilter = newTemplates.join(','); - newTemplates = []; - Rest.setUrl(`${GetBasePath("unified_job_templates")}?id__in=${newTemplateIdsFilter}&order_by=-last_job_run&last_job_run__isnull=false&type=workflow_job_template,job_template&count_disabled=1"`); - Rest.get() - .then(({ data }) => { - const joinedTemplates = data.results.concat($scope.dashboardJobTemplatesListData).sort((a, b) => new Date(b.last_job_run) - new Date(a.last_job_run)); - $scope.dashboardJobTemplatesListData = joinedTemplates.length > 5 - ? joinedTemplates.slice(0, 5) - : joinedTemplates; - $timeout(() => { - if (newTemplates.length > 0 && !launchModalOpen) { - fetchNewTemplates(); - } else { - newTemplatesTimerRunning = false; - } - }, 5000); - }) - .catch(({ data, status }) => { - ProcessErrors($scope, data, status, null, { - hdr: i18n._('Error!'), - msg: i18n._(`Failed to get new templates for dashboard: ${status}`) - }); - }); - }; - Wait('start'); Rest.setUrl(GetBasePath('dashboard')); Rest.get() diff --git a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js index 61c807b25e..5d8cacb915 100644 --- a/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js +++ b/awx/ui/client/src/organizations/linkout/controllers/organizations-job-templates.controller.js @@ -39,7 +39,7 @@ export default ['$scope', '$stateParams', 'Rest', 'GetBasePath', '$state', 'OrgJ } break; } - }; + } } } }