From a6cd32522f10cad406cf45311a5d01d7ed8e92b9 Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 24 Feb 2020 11:32:11 -0500 Subject: [PATCH] Removes GET requests in response to websocket messages on the org job templates list. List is solely updated based on data from the websocket messages. --- .../organizations-job-templates.controller.js | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) 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 d01049ed21..ff67fce559 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 @@ -4,25 +4,41 @@ * All Rights Reserved *************************************************/ -export default ['$scope', '$rootScope', - '$stateParams', 'Rest', 'ProcessErrors', - 'GetBasePath', 'Wait', - '$state', 'OrgJobTemplateList', 'OrgJobTemplateDataset', 'QuerySet', - function($scope, $rootScope, - $stateParams, Rest, ProcessErrors, - GetBasePath, Wait, - $state, OrgJobTemplateList, Dataset, qs) { +export default ['$scope', '$stateParams', 'Rest', 'GetBasePath', '$state', 'OrgJobTemplateList', 'OrgJobTemplateDataset', + function($scope, $stateParams, Rest, GetBasePath, $state, OrgJobTemplateList, Dataset) { var list = OrgJobTemplateList, orgBase = GetBasePath('organizations'); - $scope.$on(`ws-jobs`, function () { - let path = GetBasePath(list.basePath) || GetBasePath(list.name); - qs.search(path, $state.params[`${list.iterator}_search`]) - .then(function(searchResponse) { - $scope[`${list.iterator}_dataset`] = searchResponse.data; - $scope[list.name] = $scope[`${list.iterator}_dataset`].results; - }); + $scope.$on(`ws-jobs`, function (e, msg) { + if (msg.unified_job_template_id && $scope[list.name]) { + const template = $scope[list.name].find((t) => t.id === msg.unified_job_template_id); + if (template) { + if (msg.status === 'pending') { + // This is a new job - add it to the front of the + // recent_jobs array + if (template.summary_fields.recent_jobs.length === 10) { + template.summary_fields.recent_jobs.pop(); + } + + template.summary_fields.recent_jobs.unshift({ + id: msg.unified_job_id, + status: msg.status, + type: msg.type + }); + } else { + // This is an update to an existing job. Check to see + // if we have it in our array of recent_jobs + for (let i=0; i