From be999edef9d2cdc532e7615554fe5af570af0e7a Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 27 Aug 2014 12:16:44 -0400 Subject: [PATCH] Projects Add SCM Update button to project detail page: https://trello.com/c/MXrKSBbD/19-should-be-able-to-perform-actions-on-detail-pages --- awx/ui/static/js/controllers/Projects.js | 60 +++++++++++++++++++++-- awx/ui/static/js/forms/Projects.js | 8 +++ awx/ui/static/js/helpers/JobSubmission.js | 4 ++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index 781e8d07dc..9d6ad8d484 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -491,13 +491,13 @@ function ProjectsAdd($scope, $rootScope, $compile, $location, $log, $routeParams } }) .error(function (data, status) { - ProcessErrors($scope, data, status, ProjectsForm, { hdr: 'Error!', + ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to add organization to project. POST returned status: ' + status }); }); }) .error(function (data, status) { Wait('stop'); - ProcessErrors($scope, data, status, ProjectsForm, { hdr: 'Error!', + ProcessErrors($scope, data, status, form, { hdr: 'Error!', msg: 'Failed to create new project. POST returned status: ' + status }); }); }; @@ -533,7 +533,7 @@ ProjectsAdd.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, ProjectsForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, Prompt, ClearScope, GetBasePath, ReturnToCaller, GetProjectPath, Authorization, CredentialList, LookUpInit, GetChoices, - Empty, DebugForm, Wait, Stream, SchedulesControllerInit, SchedulesListInit, SchedulesList) { + Empty, DebugForm, Wait, Stream, SchedulesControllerInit, SchedulesListInit, SchedulesList, ProjectUpdate) { ClearScope('htmlTemplate'); @@ -676,6 +676,19 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam scope: $scope, relatedSets: relatedSets }); + + $scope.scm_update_tooltip = "Start an SCM update"; + $scope.scm_type_class = ""; + if (data.status === 'running' || data.status === 'updating') { + $scope.scm_update_tooltip = "SCM update currently running"; + $scope.scm_type_class = "btn-disabled"; + } + if (Empty(data.scm_type)) { + $scope.scm_update_tooltip = 'Manual projects do not require an SCM update'; + $scope.scm_type_class = "btn-disabled"; + } + + $scope.project_obj = data; $scope.$emit('projectLoaded'); }) .error(function (data, status) { @@ -695,6 +708,29 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam callback: 'choicesReady' }); + // Handle project update status changes + if ($rootScope.removeJobStatusChange) { + $rootScope.removeJobStatusChange(); + } + $rootScope.removeJobStatusChange = $rootScope.$on('JobStatusChange', function(e, data) { + if ($scope.project_obj && data.project_id === $scope.project_obj.id) { + // This is the affected project + $log.debug('Received event for project: ' + $scope.project_obj.name); + $log.debug('Status changed to: ' + data.status); + // Set the status and re-evaluate the update button tooltip and class + $scope.project_obj.status = data.status; + $scope.scm_update_tooltip = "Start an SCM update"; + $scope.scm_type_class = ""; + if (data.status === 'running' || data.status === 'updating') { + $scope.scm_update_tooltip = "SCM update currently running"; + $scope.scm_type_class = "btn-disabled"; + } + if (Empty($scope.project_obj.scm_type)) { + $scope.scm_update_tooltip = 'Manual projects do not require an SCM update'; + $scope.scm_type_class = "btn-disabled"; + } + } + }); // Save changes to the parent $scope.formSave = function () { @@ -726,6 +762,12 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam Rest.put(params) .success(function() { Wait('stop'); + /*$scope.scm_update_tooltip = "Start an SCM update"; + $scope.scm_type_class = ""; + if (Empty($scope.scm_type)) { + $scope.scm_update_tooltip = 'Manual projects do not require an SCM update'; + $scope.scm_type_class = "btn-disabled"; + }*/ ReturnToCaller(); }) .error(function (data, status) { @@ -781,6 +823,16 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam } }; + $scope.SCMUpdate = function () { + if ($scope.project_obj.scm_type === "Manual" || Empty($scope.project_obj.scm_type)) { + // ignore + } else if ($scope.project_obj.status === 'updating' || $scope.project_obj.status === 'running' || $scope.project_obj.status === 'pending') { + Alert('Update in Progress', 'The SCM update process is running.', 'alert-info'); + } else { + ProjectUpdate({ scope: $scope, project_id: $scope.project_obj.id }); + } + }; + // Reset the form $scope.formReset = function () { $rootScope.flashMessage = null; @@ -795,5 +847,5 @@ function ProjectsEdit($scope, $rootScope, $compile, $location, $log, $routeParam ProjectsEdit.$inject = ['$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'ProjectsForm', 'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit', 'RelatedPaginateInit', 'Prompt', 'ClearScope', 'GetBasePath', 'ReturnToCaller', 'GetProjectPath', 'Authorization', 'CredentialList', 'LookUpInit', 'GetChoices', 'Empty', - 'DebugForm', 'Wait', 'Stream', 'SchedulesControllerInit', 'SchedulesListInit', 'SchedulesList' + 'DebugForm', 'Wait', 'Stream', 'SchedulesControllerInit', 'SchedulesListInit', 'SchedulesList', 'ProjectUpdate' ]; diff --git a/awx/ui/static/js/forms/Projects.js b/awx/ui/static/js/forms/Projects.js index ad509c213f..3c4e25a312 100644 --- a/awx/ui/static/js/forms/Projects.js +++ b/awx/ui/static/js/forms/Projects.js @@ -21,6 +21,14 @@ angular.module('ProjectFormDefinition', ['SchedulesListDefinition']) collapseOpen: true, actions: { + scm_update: { + mode: 'edit', + ngClick: 'SCMUpdate()', + awToolTip: "{{ scm_update_tooltip }}", + dataTipWatch: "scm_update_tooltip", + ngClass: "scm_type_class", + dataPlacement: 'top' + }, stream: { 'class': "btn-primary btn-xs activity-btn", ngClick: "showActivity()", diff --git a/awx/ui/static/js/helpers/JobSubmission.js b/awx/ui/static/js/helpers/JobSubmission.js index cf0db35dce..5263ea6004 100644 --- a/awx/ui/static/js/helpers/JobSubmission.js +++ b/awx/ui/static/js/helpers/JobSubmission.js @@ -559,6 +559,10 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi scope.removeUpdateSubmitted = scope.$on('UpdateSubmitted', function() { // Refresh the project list after update request submitted Wait('stop'); + if (/\d$/.test($location.path())) { + //Request submitted from projects/N page. Navigate back to the list so user can see status + $location.path('/projects'); + } if (scope.socketStatus === 'error') { Alert('Update Started', 'The request to start the SCM update process was submitted. ' + 'To monitor the update status, refresh the page by clicking the button.', 'alert-info');