Added socket button to projects. Project page now updated realtime with job status.

This commit is contained in:
Chris Houseknecht
2014-04-23 19:04:23 -04:00
parent 49c26aad10
commit 389d99875f
4 changed files with 60 additions and 18 deletions

View File

@@ -495,6 +495,8 @@ function InventoriesEdit($scope, $location, $routeParams, $compile, $log, $rootS
} }
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) { $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) {
var group, stat; var group, stat;
Wait('stop');
$log.debug(data);
if ($scope.groups) { if ($scope.groups) {
// Assuming we have a list of groups available // Assuming we have a list of groups available
group = Find({ list: $scope.groups, key: 'group_id', val: data.group_id }); group = Find({ list: $scope.groups, key: 'group_id', val: data.group_id });

View File

@@ -76,6 +76,36 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
} }
}); });
// Handle project update status changes
if ($rootScope.rmoveJobStatusChange) {
$rootScope.removeJobStatusChange();
}
$rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) {
var project;
Wait('stop');
$log.debug(data);
if ($scope.projects) {
// Assuming we have a list of projects available
project = Find({ list: $scope.projects, key: 'id', val: data.project_id });
if (project) {
// And we found the affected project
$log.debug('Received event for project: ' + project.name);
$log.debug('Status changed to: ' + data.status);
if (data.status === 'successful' || data.status === 'failed') {
project.scm_update_tooltip = "Start an SCM update";
project.scm_type_class = "";
}
else {
project.scm_update_tooltip = "SCM update currently running";
project.scm_type_class = "btn-disabled";
}
project.status = data.status;
project.statusIcon = GetProjectIcon(data.status);
project.statusTip = GetProjectToolTip(data.status);
}
}
});
if ($scope.removeChoicesHere) { if ($scope.removeChoicesHere) {
$scope.removeChoicesHere(); $scope.removeChoicesHere();
} }
@@ -312,8 +342,8 @@ function ProjectsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
// Do not respond. Button appears greyed out as if it is disabled. Not disabled though, because we need mouse over event // Do not respond. Button appears greyed out as if it is disabled. Not disabled though, because we need mouse over event
// to work. So user can click, but we just won't do anything. // to work. So user can click, but we just won't do anything.
//Alert('Missing SCM Setup', 'Before running an SCM update, edit the project and provide the SCM access information.', 'alert-info'); //Alert('Missing SCM Setup', 'Before running an SCM update, edit the project and provide the SCM access information.', 'alert-info');
} else if (project.status === 'updating' || project.status === 'running') { } else if (project.status === 'updating' || project.status === 'running' || project.status === 'pending') {
Alert('Update in Progress', 'The SCM update process is running. Use the Refresh button to monitor the status.', 'alert-info'); // Alert('Update in Progress', 'The SCM update process is running. Use the Refresh button to monitor the status.', 'alert-info');
} else { } else {
ProjectUpdate({ scope: $scope, project_id: project.id }); ProjectUpdate({ scope: $scope, project_id: project.id });
} }

View File

@@ -382,15 +382,15 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
} }
scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function() { scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function() {
// Refresh the project list after update request submitted // Refresh the project list after update request submitted
Wait('stop');
Alert('Update Started', 'The request to start the SCM update process was submitted. ' +
'To monitor the update status, refresh the page by clicking the <i class="fa fa-refresh"></i> button.', 'alert-info');
if (scope.refreshJobs) { if (scope.refreshJobs) {
Wait('stop');
Alert('Update Started', 'The request to start the SCM update process was submitted. ' +
'To monitor the update status, refresh the page by clicking the <i class="fa fa-refresh"></i> button.', 'alert-info');
scope.refreshJobs(); scope.refreshJobs();
} }
else if (scope.refresh) { //else if (scope.refresh) {
scope.refresh(); // scope.refresh();
} //}
}); });
if (scope.removePromptForPasswords) { if (scope.removePromptForPasswords) {
@@ -413,9 +413,9 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
Rest.get() Rest.get()
.success(function (data) { .success(function (data) {
project = data; project = data;
Wait('stop');
if (project.can_update) { if (project.can_update) {
if (project.passwords_needed_to_updated) { if (project.passwords_needed_to_updated) {
Wait('stop');
scope.$emit('PromptForPasswords'); scope.$emit('PromptForPasswords');
} }
else { else {
@@ -443,8 +443,8 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
var scope = params.scope, var scope = params.scope,
url = params.url, url = params.url,
group_id = params.group_id, //group_id = params.group_id,
tree_id = params.tree_id, //tree_id = params.tree_id,
//base = $location.path().replace(/^\//, '').split('/')[0], //base = $location.path().replace(/^\//, '').split('/')[0],
inventory_source; inventory_source;
@@ -460,7 +460,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
} }
});*/ });*/
function getJobID(url) { /*function getJobID(url) {
var result=''; var result='';
url.split(/\//).every(function(path) { url.split(/\//).every(function(path) {
if (/^\d+$/.test(path)) { if (/^\d+$/.test(path)) {
@@ -470,14 +470,14 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
return true; return true;
}); });
return result; return result;
} }*/
if (scope.removeUpdateSubmitted) { if (scope.removeUpdateSubmitted) {
scope.removeUpdateSubmitted(); scope.removeUpdateSubmitted();
} }
scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function () { scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function () {
// Get the current job // Get the current job
var path = url.replace(/update\/$/,''); /*var path = url.replace(/update\/$/,'');
Rest.setUrl(path); Rest.setUrl(path);
Rest.get() Rest.get()
.success(function(data) { .success(function(data) {
@@ -492,7 +492,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to get inventory source ' + url + ' GET returned: ' + status }); msg: 'Failed to get inventory source ' + url + ' GET returned: ' + status });
}); });
*/
//console.log('job submitted. callback returned: '); //console.log('job submitted. callback returned: ');
//console.log(data); //console.log(data);
/*setTimeout(function() { /*setTimeout(function() {
@@ -532,6 +532,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
inventory_source = data; inventory_source = data;
if (data.can_update) { if (data.can_update) {
if (data.passwords_needed_to_update) { if (data.passwords_needed_to_update) {
Wait('stop');
scope.$emit('PromptForPasswords'); scope.$emit('PromptForPasswords');
} }
else { else {

View File

@@ -27,6 +27,7 @@ angular.module('ProjectsListDefinition', [])
iconOnly: true, iconOnly: true,
ngClick: 'showSCMStatus(project.id)', ngClick: 'showSCMStatus(project.id)',
awToolTip: '{{ project.statusTip }}', awToolTip: '{{ project.statusTip }}',
dataTipWatch: 'project.statusTip',
dataPlacement: 'top', dataPlacement: 'top',
icon: "icon-job-{{ project.statusIcon }}", icon: "icon-job-{{ project.statusIcon }}",
columnClass: "col-md-1 col-sm-2 col-xs-3", columnClass: "col-md-1 col-sm-2 col-xs-3",
@@ -75,10 +76,17 @@ angular.module('ProjectsListDefinition', [])
awToolTip: 'Click for help', awToolTip: 'Click for help',
awTipPlacement: 'top' awTipPlacement: 'top'
},*/ },*/
refresh: { /*refresh: {
mode: 'all', mode: 'all',
awToolTip: "Refresh the page", awToolTip: "Refresh the page",
ngClick: "refresh()" ngClick: "refresh()"
},*/
socket: {
mode: 'all',
iconClass: "{{ 'fa fa-power-off fa-lg socket-' + socketStatus }}",
awToolTip: "{{ socketTip }}",
dataTipWatch: "socketTip",
ngClick: "socketToggle()",
}, },
stream: { stream: {
ngClick: "showActivity()", ngClick: "showActivity()",
@@ -91,6 +99,7 @@ angular.module('ProjectsListDefinition', [])
scm_update: { scm_update: {
ngClick: 'SCMUpdate(project.id, $event)', ngClick: 'SCMUpdate(project.id, $event)',
awToolTip: "{{ project.scm_update_tooltip }}", awToolTip: "{{ project.scm_update_tooltip }}",
dataTipWatch: "project.scm_update_tooltip",
ngClass: "project.scm_type_class", ngClass: "project.scm_type_class",
dataPlacement: 'top' dataPlacement: 'top'
}, },
@@ -109,13 +118,13 @@ angular.module('ProjectsListDefinition', [])
"delete": { "delete": {
ngClick: "deleteProject(project.id, project.name)", ngClick: "deleteProject(project.id, project.name)",
awToolTip: 'Delete the project', awToolTip: 'Delete the project',
ngShow: "project.status !== 'updating' && project.status !== 'running'", ngShow: "project.status !== 'updating' && project.status !== 'running' && project.status !== 'pending'",
dataPlacement: 'top' dataPlacement: 'top'
}, },
cancel: { cancel: {
ngClick: "cancelUpdate(project.id, project.name)", ngClick: "cancelUpdate(project.id, project.name)",
awToolTip: 'Cancel the SCM update', awToolTip: 'Cancel the SCM update',
ngShow: "project.status == 'updating' || project.status == 'running'", ngShow: "project.status == 'updating' || project.status == 'running' || project.status == 'pending'",
dataPlacement: 'top' dataPlacement: 'top'
} }
} }