Changing naming convention for socket-message event listeners

to use <stateName>-<group_name>
This commit is contained in:
Jared Tabor 2016-09-13 18:21:56 -07:00
parent f875d65ef7
commit 0f32faec60
13 changed files with 88 additions and 58 deletions

View File

@ -28,7 +28,7 @@ export function Home($scope, $compile, $stateParams, $rootScope, $location, $log
var dataCount = 0;
$rootScope.$on('JobStatusChange-home', function () {
$rootScope.$on('dashboard-jobs', function () {
Rest.setUrl(GetBasePath('dashboard'));
Rest.get()
.success(function (data) {

View File

@ -113,14 +113,14 @@ export function JobsListController ($rootScope, $log, $scope, $compile, $statePa
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobs', function() {
$rootScope.removeJobStatusChange = $rootScope.$on('jobs-jobs', function() {
$scope.refreshJobs();
});
if ($rootScope.removeScheduleStatusChange) {
$rootScope.removeScheduleStatusChange();
}
$rootScope.removeScheduleStatusChange = $rootScope.$on('ScheduleStatusChange', function() {
$rootScope.removeScheduleStatusChange = $rootScope.$on('jobs-schedules', function() {
if (api_complete) {
scheduled_scope.search('schedule');
}

View File

@ -90,7 +90,7 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams,
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-projects', function(e, data) {
$rootScope.removeJobStatusChange = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data) {
var project;
$log.debug(data);
if ($scope.projects) {

View File

@ -58,7 +58,7 @@ function JobStatusGraphData(Rest, getBasePath, processErrors, $rootScope, $q) {
destroyWatcher: angular.noop,
setupWatcher: function(period, jobType) {
this.destroyWatcher =
$rootScope.$on('JobStatusChange-home', function() {
$rootScope.$on('dashboard-jobs', function() {
getData(period, jobType).then(function(result) {
$rootScope.
$broadcast('DataReceived:JobStatusGraph',

View File

@ -104,7 +104,7 @@
if ($rootScope.inventoryManageStatus) {
$rootScope.inventoryManageStatus();
}
$rootScope.inventoryManageStatus = $rootScope.$on('JobStatusChange-inventory', function(e, data){
$rootScope.inventoryManageStatus = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data){
var group = Find({ list: $scope.groups, key: 'id', val: data.group_id });
if(data.status === 'failed' || data.status === 'successful'){
$state.reload();

View File

@ -60,11 +60,10 @@
}
});
// UnifiedJob.def socketio_emit_status() from /awx/main.models.unified_jobs.py
if ($rootScope.removeJobSummaryComplete) {
$rootScope.removeJobSummaryComplete();
}
$rootScope.removeJobSummaryComplete = $rootScope.$on('JobStatusChange-jobDetails', function(e, data) {
$rootScope.removeJobSummaryComplete = $rootScope.$on('jobDetail-jobs', function(e, data) {
if (parseInt($stateParams.id) === data.unified_job_id){
$scope.status = data.status;
}

View File

@ -9,6 +9,11 @@ import {templateUrl} from '../../shared/template-url/template-url.factory';
export default {
name: 'jobDetail.host-summary',
url: '/event-summary',
socket: {
"groups":{
"jobs": ["status_changed"]
}
},
views:{
'host-summary': {
controller: 'HostSummaryController',

View File

@ -201,7 +201,7 @@ export default
if ($rootScope.removeJobEventChange) {
$rootScope.removeJobEventChange();
}
$rootScope.removeJobEventChange = $rootScope.$on("job_events-" + job_id, function(e, data) {
$rootScope.removeJobEventChange = $rootScope.$on(`${$state.current.name}-job_events-${job_id}`, function(e, data) {
// update elapsed time on each event received
scope.job_status.elapsed = GetElapsed({
start: scope.job.created,
@ -225,7 +225,7 @@ export default
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobDetails', function(e, data) {
$rootScope.removeJobStatusChange = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data) {
// if we receive a status change event for the current job indicating the job
// is finished, stop event queue processing and reload
if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10)) {

View File

@ -90,7 +90,7 @@ export default ['$scope', '$rootScope', '$location', '$log',
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-projects', function(e, data) {
$rootScope.removeJobStatusChange = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data) {
var project;
$log.debug(data);
if ($scope.projects) {

View File

@ -16,7 +16,7 @@ export function PortalModeJobsController($scope, $rootScope, GetBasePath, Genera
if ($rootScope.removeJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange-portal', function() {
$rootScope.removeJobStatusChange = $rootScope.$on('portalMode-jobs', function() {
$scope.search('job');
});

View File

@ -33,55 +33,81 @@ export default
self.socket.onmessage = function (e) {
$log.debug('Received From Server: ' + e.data);
var data = JSON.parse(e.data);
if(data.group_name==="jobs"){
if (!('status' in data)){
// we know that this must have been a
// summary complete message
$log.debug('Job summary_complete ' + data.unified_job_id);
$rootScope.$emit('JobSummaryComplete', data);
}
if ($state.is('jobs')) {
$rootScope.$emit('JobStatusChange-jobs', data);
} else if ($state.includes('jobDetail') ||
$state.is('adHocJobStdout') ||
$state.is('inventorySyncStdout') ||
$state.is('managementJobStdout') ||
$state.is('scmUpdateStdout')) {
$log.debug("sending status to standard out");
$rootScope.$emit('JobStatusChange-jobStdout', data);
}
if ($state.includes('jobDetail')) {
$rootScope.$emit('JobStatusChange-jobDetails', data);
} else if ($state.is('dashboard')) {
$rootScope.$emit('JobStatusChange-home', data);
} else if ($state.is('portalMode')) {
$rootScope.$emit('JobStatusChange-portal', data);
} else if ($state.is('projects')) {
$rootScope.$emit('JobStatusChange-projects', data);
} else if ($state.is('inventoryManage') ||
$state.includes('inventoryManage')) {
$rootScope.$emit('JobStatusChange-inventory', data);
}
var data = JSON.parse(e.data), str = "";
if(data.group_name==="jobs" && !('status' in data)){
// we know that this must have been a
// summary complete message
$log.debug('Job summary_complete ' + data.unified_job_id);
$rootScope.$emit('JobSummaryComplete', data);
}
if(data.group_name==="job_events"){
$rootScope.$emit('job_events-'+data.job, data);
else if(data.group_name==="job_events"){
str = `${$state.current.name}-${data.group_name}-${data.job}`;
}
if(data.group_name==="schedules"){
$log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status);
$rootScope.$emit('ScheduleStatusChange', data);
else if(data.group_name==="ad_hoc_command_events"){
str = `${$state.current.name}-${data.group_name}-${data.ad_hoc_command}`;
}
if(data.group_name==="ad_hoc_command_events"){
$rootScope.$emit('ad_hoc_command_events-'+data.ad_hoc_command, data);
}
if(data.group_name==="control"){
else if(data.group_name==="control"){
$log.debug(data.reason);
$rootScope.sessionTimer.expireSession('session_limit');
$state.go('signOut');
}
else {
// The naming scheme for emitting socket messages to the
// correct route is the route name followed by a
// dash (-) and the group_name.
// ex: 'jobDetail-job_events'
str = `${$state.current.name}-${data.group_name}`;
}
$rootScope.$emit(str, data);
// if(data.group_name==="jobs"){
//
// if (!('status' in data)){
// // we know that this must have been a
// // summary complete message
// $log.debug('Job summary_complete ' + data.unified_job_id);
// $rootScope.$emit('JobSummaryComplete', data);
// }
//
// if ($state.is('jobs')) {
// $rootScope.$emit('JobStatusChange-jobs', data);
// }
// else if ($state.includes('jobDetail') ||
// $state.is('adHocJobStdout') ||
// $state.is('inventorySyncStdout') ||
// $state.is('managementJobStdout') ||
// $state.is('scmUpdateStdout')) {
//
// $log.debug("sending status to standard out");
// $rootScope.$emit('JobStatusChange-jobStdout', data);
// }
// if ($state.includes('jobDetail')) {
// $rootScope.$emit('JobStatusChange-jobDetails', data);
// } else if ($state.is('dashboard')) {
// $rootScope.$emit('JobStatusChange-home', data);
// } else if ($state.is('portalMode')) {
// $rootScope.$emit('JobStatusChange-portal', data);
// } else if ($state.is('projects')) {
// $rootScope.$emit('JobStatusChange-projects', data);
// } else if ($state.is('inventoryManage') ||
// $state.includes('inventoryManage')) {
// $rootScope.$emit('JobStatusChange-inventory', data);
// }
// }
// if(data.group_name==="job_events"){
// $rootScope.$emit('job_events-'+data.job, data);
// }
// if(data.group_name==="schedules"){
// $log.debug('Schedule ' + data.unified_job_id + ' status changed to ' + data.status);
// $rootScope.$emit('ScheduleStatusChange', data);
// }
// if(data.group_name==="ad_hoc_command_events"){
// $rootScope.$emit('ad_hoc_command_events-'+data.ad_hoc_command, data);
// }
// if(data.group_name==="control"){
// $log.debug(data.reason);
// $rootScope.sessionTimer.expireSession('session_limit');
// $state.go('signOut');
// }
return self.socket;

View File

@ -22,7 +22,7 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
function openSockets() {
if ($state.current.name === 'jobDetail') {
$log.debug("socket watching on job_events-" + job_id);
$rootScope.$on("job_events-" + job_id, function() {
$rootScope.$on(`${$state.current.name}-job_events-${job_id}`, function() {
$log.debug("socket fired on job_events-" + job_id);
if (api_complete) {
event_queue++;
@ -36,7 +36,7 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
}
if ($state.current.name === 'adHocJobStdout') {
$log.debug("socket watching on ad_hoc_command_events-" + job_id);
$rootScope.$on("ad_hoc_command_events-" + job_id, function() {
$rootScope.$on(`${$state.current.name}-ad_hoc_command_events-${job_id}`, function() {
$log.debug("socket fired on ad_hoc_command_events-" + job_id);
if (api_complete) {
event_queue++;
@ -192,7 +192,7 @@ export default ['$log', '$rootScope', '$scope', '$state', '$stateParams', 'Proce
if ($scope.removeJobStatusChange) {
$scope.removeJobStatusChange();
}
$scope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobStdout', function(e, data) {
$scope.removeJobStatusChange = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data) {
if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10)) {
if (data.status === 'failed' || data.status === 'canceled' ||
data.status === 'error' || data.status === 'successful') {

View File

@ -28,7 +28,7 @@ export function JobStdoutController ($rootScope, $scope, $state, $stateParams,
if ($scope.removeJobStatusChange) {
$scope.removeJobStatusChange();
}
$scope.removeJobStatusChange = $rootScope.$on('JobStatusChange-jobStdout', function(e, data) {
$scope.removeJobStatusChange = $rootScope.$on(`${$state.current.name}-jobs`, function(e, data) {
if (parseInt(data.unified_job_id, 10) === parseInt(job_id,10) && $scope.job) {
$scope.job.status = data.status;
}