diff --git a/awx/ui/client/legacy-styles/ansible-ui.less b/awx/ui/client/legacy-styles/ansible-ui.less index 825576f8c8..4cc306cb36 100644 --- a/awx/ui/client/legacy-styles/ansible-ui.less +++ b/awx/ui/client/legacy-styles/ansible-ui.less @@ -2247,6 +2247,10 @@ html input[disabled] { cursor: not-allowed; } +.CodeMirror { + font-family: Monaco, Menlo, Consolas, "Courier New", monospace; +} + .CodeMirror--disabled .CodeMirror.cm-s-default, .CodeMirror--disabled .CodeMirror-line { background-color: #f6f6f6; diff --git a/awx/ui/client/src/job-results/job-results.controller.js b/awx/ui/client/src/job-results/job-results.controller.js index c53ccb0e63..188a26a2bd 100644 --- a/awx/ui/client/src/job-results/job-results.controller.js +++ b/awx/ui/client/src/job-results/job-results.controller.js @@ -1,5 +1,5 @@ -export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService', -function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService) { +export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService', 'statusSocket', +function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService, statusSocket) { var toDestroy = []; var cancelRequests = false; var runTimeElapsedTimer = null; @@ -671,6 +671,14 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy }); })); + // get previously set up socket messages from resolve + if (statusSocket && statusSocket[0] && statusSocket[0].job_status) { + $scope.job_status = statusSocket[0].job_status; + } + if ($scope.job_status === "running" && !$scope.job.elapsed) { + runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer); + } + // Processing of job-status messages from the websocket toDestroy.push($scope.$on(`ws-jobs`, function(e, data) { if (parseInt(data.unified_job_id, 10) === @@ -678,7 +686,9 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy // controller is defined, so set the job_status $scope.job_status = data.status; if (data.status === "running") { - runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer); + if (!runTimeElapsedTimer) { + runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer); + } } else if (data.status === "successful" || data.status === "failed" || data.status === "error" || @@ -706,7 +716,14 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy } })); + if (statusSocket && statusSocket[1]) { + statusSocket[1](); + } + $scope.$on('$destroy', function(){ + if (statusSocket && statusSocket[1]) { + statusSocket[1](); + } $( ".JobResultsStdOut-aLineOfStdOut" ).remove(); cancelRequests = true; eventQueue.initialize(); diff --git a/awx/ui/client/src/job-results/job-results.route.js b/awx/ui/client/src/job-results/job-results.route.js index 755735ddc8..4ea38a97ba 100644 --- a/awx/ui/client/src/job-results/job-results.route.js +++ b/awx/ui/client/src/job-results/job-results.route.js @@ -36,6 +36,16 @@ export default { } }, resolve: { + statusSocket: ['$rootScope', '$stateParams', function($rootScope, $stateParams) { + var preScope = {}; + var eventOn = $rootScope.$on(`ws-jobs`, function(e, data) { + if (parseInt(data.unified_job_id, 10) === + parseInt($stateParams.id,10)) { + preScope.job_status = data.status; + } + }); + return [preScope, eventOn]; + }], // the GET for the particular job jobData: ['Rest', 'GetBasePath', '$stateParams', '$q', '$state', 'Alert', 'jobResultsService', function(Rest, GetBasePath, $stateParams, $q, $state, Alert, jobResultsService) { return jobResultsService.getJobData($stateParams.id); diff --git a/awx/ui/karma.conf.js b/awx/ui/karma.conf.js index 4d7d4c8363..1a22f476b2 100644 --- a/awx/ui/karma.conf.js +++ b/awx/ui/karma.conf.js @@ -20,7 +20,6 @@ module.exports = function(config) { './client/src/app.js', './node_modules/angular-mocks/angular-mocks.js', { pattern: './tests/**/*-test.js' }, - { pattern: './tests/**/*.json', included: false}, 'client/src/**/*.html' ], preprocessors: { diff --git a/awx/ui/tests/spec/job-results/job-results.controller-test.js b/awx/ui/tests/spec/job-results/job-results.controller-test.js index f0b7f3ecea..e9a1629143 100644 --- a/awx/ui/tests/spec/job-results/job-results.controller-test.js +++ b/awx/ui/tests/spec/job-results/job-results.controller-test.js @@ -5,8 +5,12 @@ describe('Controller: jobResultsController', () => { // Setup let jobResultsController; - let jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, eventResolve, populateResolve, $rScope, q, $log, Dataset, Rest, $state, QuerySet, i18n,fieldChoices, fieldLabels, $interval, workflowResultsService; + let jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, eventResolve, populateResolve, $rScope, q, $log, Dataset, Rest, $state, QuerySet, i18n,fieldChoices, fieldLabels, $interval, workflowResultsService, statusSocket; + statusSocket = function() { + var fn = function() {}; + return fn; + } jobData = { related: {} }; @@ -70,6 +74,8 @@ describe('Controller: jobResultsController', () => { return jasmine.createSpyObj('workflowResultsService', ['createOneSecondTimer', 'destroyTimer']); }); + $provide.value('statusSocket', statusSocket); + $provide.value('jobData', jobData); $provide.value('jobDataOptions', jobDataOptions); $provide.value('jobLabels', jobLabels); @@ -90,7 +96,7 @@ describe('Controller: jobResultsController', () => { }; let injectVals = () => { - angular.mock.inject((_jobData_, _jobDataOptions_, _jobLabels_, _jobFinished_, _count_, _ParseTypeChange_, _ParseVariableString_, _jobResultsService_, _eventQueue_, _$compile_, $rootScope, $controller, $q, $httpBackend, _$log_, _Dataset_, _Rest_, _$state_, _QuerySet_, _$interval_, _workflowResultsService_) => { + angular.mock.inject((_jobData_, _jobDataOptions_, _jobLabels_, _jobFinished_, _count_, _ParseTypeChange_, _ParseVariableString_, _jobResultsService_, _eventQueue_, _$compile_, $rootScope, $controller, $q, $httpBackend, _$log_, _Dataset_, _Rest_, _$state_, _QuerySet_, _$interval_, _workflowResultsService_, _statusSocket_) => { // when you call $scope.$apply() (which you need to do to // to get inside of .then blocks to test), something is // causing a request for all static files. @@ -127,6 +133,7 @@ describe('Controller: jobResultsController', () => { QuerySet = _QuerySet_; $interval = _$interval_; workflowResultsService = _workflowResultsService_; + statusSocket = _statusSocket_; jobResultsService.getEvents.and .returnValue(eventResolve); @@ -157,7 +164,8 @@ describe('Controller: jobResultsController', () => { Dataset: Dataset, Rest: Rest, $state: $state, - QuerySet: QuerySet + QuerySet: QuerySet, + statusSocket: statusSocket }); }); };