From ae55f1c0d38ba90ed178c0e1514a34152a0d421c Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Wed, 5 Nov 2014 13:07:23 -0500 Subject: [PATCH] Websockets live updating portal mode fixed issue with websockets not updating view in portal mode --- awx/ui/static/js/config.js | 2 +- awx/ui/static/js/controllers/Jobs.js | 3 +- awx/ui/static/js/controllers/Portal.js | 69 ++++++++++------------- awx/ui/static/js/helpers/JobSubmission.js | 4 +- awx/ui/static/js/helpers/Jobs.js | 3 + awx/ui/static/js/lists/PortalJobs.js | 10 ++-- awx/ui/static/js/widgets/PortalJobs.js | 30 +--------- awx/ui/static/lib/ansible/Socket.js | 1 - 8 files changed, 43 insertions(+), 79 deletions(-) diff --git a/awx/ui/static/js/config.js b/awx/ui/static/js/config.js index ce064c6eba..abed710242 100644 --- a/awx/ui/static/js/config.js +++ b/awx/ui/static/js/config.js @@ -19,7 +19,7 @@ tooltip_delay: {show: 500, hide: 100}, // Default number of milliseconds to delay displaying/hiding tooltips - debug_mode: true, // Enable console logging messages + debug_mode: false, // Enable console logging messages password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong. // This value controls progress bar colors: diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index 7f95a68d0b..cbafb57b89 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -77,10 +77,9 @@ function JobsListController ($rootScope, $log, $scope, $compile, $routeParams, C case 'pending': case 'waiting': queued_scope.search('queued_job'); - break; - case 'successful': completed_scope.search('completed_job'); break; + case 'successful': case 'failed': case 'error': case 'canceled': diff --git a/awx/ui/static/js/controllers/Portal.js b/awx/ui/static/js/controllers/Portal.js index c936f7be4a..0956cb09ed 100644 --- a/awx/ui/static/js/controllers/Portal.js +++ b/awx/ui/static/js/controllers/Portal.js @@ -79,7 +79,6 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location, searchSize: 'col-lg-6 col-md-6' }); - $rootScope.flashMessage = null; SearchInit({ scope: $scope, @@ -120,48 +119,40 @@ function PortalController($scope, $compile, $routeParams, $rootScope, $location, $('.list-well:eq(1)').css('margin-top' , '0px'); }); - // function processEvent(event) { - // switch(event.status) { - // case 'running': - // jobs_scope.search('running_job'); - // jobs_scope.search('queued_job'); - - // break; - // case 'new': - // case 'pending': - // case 'waiting': - // jobs_scope.search('queued_job'); - - // break; - // case 'successful': - // jobs_scope.search('completed_job'); - // case 'failed': - // case 'error': - // case 'canceled': - // jobs_scope.search('completed_job'); - // jobs_scope.search('running_job'); - // jobs_scope.search('queued_job'); - // } - // } + function processEvent(event) { + switch(event.status) { + case 'running': + jobs_scope.search('portal_job'); + // queued_scope.search('queued_job'); + break; + case 'new': + case 'pending': + jobs_scope.search('portal_job'); + break; + case 'waiting': + jobs_scope.search('portal_job'); + // completed_scope.search('completed_job'); + break; + case 'successful': + // // console.log('successful'); + // running_scope.search('running_job'); + // completed_scope.search('completed_job'); + // break; + case 'failed': + case 'error': + case 'canceled': + jobs_scope.search('portal_job'); + // running_scope.search('running_job'); + // queued_scope.search('queued_job'); + } + } if ($rootScope.removeJobStatusChange) { $rootScope.removeJobStatusChange(); } - $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function() { - jobs_scope.refreshJobs(); - // if(data.status==='pending'){ - // // $scope.refresh(); - // $('#portal-jobs').empty(); - // // $rootScope.flashMessage = null; - // PortalJobsWidget({ - // scope: $scope, - // target: 'portal-jobs', - // searchSize: 'col-lg-6 col-md-6' - // }); - // } - - - //x`processEvent(data); + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, event) { + // jobs_scope.search('portal_job'); + processEvent(event); }); diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index 67097137a5..feb860a0b9 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -53,7 +53,7 @@ angular.module('JobSubmissionHelper', [ 'RestServices', 'Utilities', 'Credential $('#password-modal').dialog('close'); } scope.$emit(callback, data); - scope.$destroy(); + // scope.$destroy(); }) .error(function(data, status) { ProcessErrors(scope, data, status, null, { hdr: 'Error!', @@ -764,7 +764,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi } scope.removePlaybookLaunchFinished = scope.$on('PlaybookLaunchFinished', function(e, data) { //var base = $location.path().replace(/^\//, '').split('/')[0]; - if(scope.portalMode===false ){ + if(scope.portalMode===false || scope.$parent.portalMode===false ){ $location.path('/jobs/' + data.job); } diff --git a/awx/ui/static/js/helpers/Jobs.js b/awx/ui/static/js/helpers/Jobs.js index 32411cade4..a227faf2cd 100644 --- a/awx/ui/static/js/helpers/Jobs.js +++ b/awx/ui/static/js/helpers/Jobs.js @@ -405,6 +405,9 @@ angular.module('JobsHelper', ['Utilities', 'RestServices', 'FormGenerator', 'Job JobsControllerInit({ scope: scope, parent_scope: parent_scope }); JobsListUpdate({ scope: scope, parent_scope: parent_scope, list: list }); parent_scope.$emit('listLoaded'); + // setTimeout(function(){ + // scope.$apply(); + // }, 300); }); if (base === 'jobs' && list.name === 'completed_jobs') { diff --git a/awx/ui/static/js/lists/PortalJobs.js b/awx/ui/static/js/lists/PortalJobs.js index 733dd78b90..22dd48031e 100644 --- a/awx/ui/static/js/lists/PortalJobs.js +++ b/awx/ui/static/js/lists/PortalJobs.js @@ -14,8 +14,8 @@ angular.module('PortalJobsListDefinition', []) .value( 'PortalJobsList', { - name: 'jobs', - iterator: 'job', + name: 'portal_jobs', + iterator: 'portal_job', editTitle: 'Jobs', 'class': 'table-condensed', index: false, @@ -39,8 +39,8 @@ angular.module('PortalJobsListDefinition', []) columnClass: 'col-lg-1 col-md-2 col-sm-2 col-xs-2', // awToolTip: "{{ job.status_tip }}", // awTipPlacement: "top", - dataTitle: "{{ job.status_popover_title }}", - icon: 'icon-job-{{ job.status }}', + dataTitle: "{{ portal_job.status_popover_title }}", + icon: 'icon-job-{{ portal_job.status }}', iconOnly: true, // ngClick:"viewJobLog(job.id)", searchable: true, @@ -73,7 +73,7 @@ angular.module('PortalJobsListDefinition', []) fieldActions: { job_details: { mode: 'all', - ngClick: "viewJobLog(job.id)", + ngClick: "viewJobLog(portal_job.id)", awToolTip: 'View job details', dataPlacement: 'top' } diff --git a/awx/ui/static/js/widgets/PortalJobs.js b/awx/ui/static/js/widgets/PortalJobs.js index 3b2a65c7dd..b70455b489 100644 --- a/awx/ui/static/js/widgets/PortalJobs.js +++ b/awx/ui/static/js/widgets/PortalJobs.js @@ -76,39 +76,11 @@ angular.module('PortalJobsWidget', ['RestServices', 'Utilities']) scope: jobs_scope, list: PortalJobsList, id: 'active-jobs', - url: GetBasePath('unified_jobs') + '?status__in=running,completed,failed,successful,error,canceled', + url: GetBasePath('jobs'), //+ '?type__in=job' , //&status__in=running,completed,failed,successful,error,canceled', pageSize: max_rows, spinner: true }); - // completed_scope.showJobType = true; - // LoadJobsScope({ - // parent_scope: scope, - // scope: completed_scope, - // list: PortalJobsList, - // id: 'active-jobs', - // url: GetBasePath('unified_jobs') + '?or__status=successful&or__status=failed&or__status=error&or__status=canceled', - // // searchParams: search_params, - // pageSize: max_rows - // }); - - // LoadJobsScope({ - // parent_scope: scope, - // scope: running_scope, - // list: PortalJobsList, - // id: 'active-jobs', - // url: GetBasePath('unified_jobs') + '?status=running', - // pageSize: max_rows - // }); - - // LoadJobsScope({ - // parent_scope: scope, - // scope: queued_scope, - // list: PortalJobsList, - // id: 'active-jobs', - // url: GetBasePath('unified_jobs') + '?or__status=pending&or__status=waiting&or__status=new', - // pageSize: max_rows - // }); $(window).resize(_.debounce(function() { resizePortalJobsWidget(); diff --git a/awx/ui/static/lib/ansible/Socket.js b/awx/ui/static/lib/ansible/Socket.js index 9dc7c9cd92..ccbd4ec150 100644 --- a/awx/ui/static/lib/ansible/Socket.js +++ b/awx/ui/static/lib/ansible/Socket.js @@ -28,7 +28,6 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) endpoint = params.endpoint, protocol = $location.protocol(), config, socketPort, - // handshakeData, url; // Since some pages are opened in a new tab, we might get here before AnsibleConfig is available.