Added support for displaying a link in the job details view that points to the Schedule when a job is kicked off in that fashion. This link opens a modal and allows the end user to edit the Schedule in line without a page refresh.

This commit is contained in:
Michael Abashian 2015-11-25 09:54:06 -05:00
parent 156b165065
commit 11048ab92e
3 changed files with 61 additions and 10 deletions

View File

@ -3,7 +3,7 @@
*
* All Rights Reserved
*************************************************/
/**
* @ngdoc function
* @name controllers.function:JobDetail
@ -13,7 +13,7 @@
export function JobDetailController ($location, $rootScope, $filter, $scope, $compile, $routeParams, $log, ClearScope, Breadcrumbs, LoadBreadCrumbs, GetBasePath, Wait, Rest,
ProcessErrors, SelectPlay, SelectTask, Socket, GetElapsed, DrawGraph, LoadHostSummary, ReloadHostSummaryList, JobIsFinished, SetTaskStyles, DigestEvent,
UpdateDOM, EventViewer, DeleteJob, PlaybookRun, HostEventsViewer, LoadPlays, LoadTasks, LoadHosts, HostsEdit, ParseVariableString, GetChoices, fieldChoices, fieldLabels) {
UpdateDOM, EventViewer, DeleteJob, PlaybookRun, HostEventsViewer, LoadPlays, LoadTasks, LoadHosts, HostsEdit, ParseVariableString, GetChoices, fieldChoices, fieldLabels, EditSchedule) {
ClearScope();
@ -705,8 +705,21 @@ export function JobDetailController ($location, $rootScope, $filter, $scope, $co
scope.verbosity = data.verbosity;
scope.job_tags = data.job_tags;
scope.variables = ParseVariableString(data.extra_vars);
scope.users_url = (data.summary_fields.created_by) ? '/#/users/' + data.summary_fields.created_by.id : '';
scope.created_by = (data.summary_fields.created_by) ? data.summary_fields.created_by.username : '';
// If we get created_by back from the server then use it. This means that the job was kicked
// off by a user and not a schedule AND that the user still exists in the system.
if(data.summary_fields.created_by) {
scope.users_url = '/#/users/' + data.summary_fields.created_by.id;
scope.created_by = data.summary_fields.created_by.username;
}
else {
if(data.summary_fields.schedule) {
// Build the Launched By link to point to the schedule that kicked it off
scope.scheduled_by = (data.summary_fields.schedule.name) ? data.summary_fields.schedule.name.toString() : '';
}
// If there is no schedule or created_by then we can assume that the job was
// created by a deleted user
}
if (data.summary_fields.credential) {
scope.credential_name = data.summary_fields.credential.name;
@ -1391,10 +1404,39 @@ export function JobDetailController ($location, $rootScope, $filter, $scope, $co
selected_group_id: null
});
};
scope.editSchedule = function() {
// We need to get the schedule's ID out of the related links
// An example of the related schedule link looks like /api/v1/schedules/5
// where 5 is the ID we are trying to capture
var regex = /\/api\/v1\/schedules\/(\d+)\//;
var id = scope.job.related.schedule.match(regex)[1];
if (id) {
// If we get an ID from the regular expression go ahead and open up the
// modal via the EditSchedule service
EditSchedule({
scope: scope,
id: parseInt(id),
callback: 'SchedulesRefresh'
});
}
};
// SchedulesRefresh is the callback string that we passed to the edit schedule modal
// When the modal successfully updates the schedule it will emit this event and pass
// the updated schedule object
if (scope.removeSchedulesRefresh) {
scope.removeSchedulesRefresh();
}
scope.$on('SchedulesRefresh', function(e, data) {
if (data) {
scope.scheduled_by = data.name;
}
});
}
JobDetailController.$inject = [ '$location', '$rootScope', '$filter', '$scope', '$compile', '$routeParams', '$log', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'GetBasePath',
'Wait', 'Rest', 'ProcessErrors', 'SelectPlay', 'SelectTask', 'Socket', 'GetElapsed', 'DrawGraph', 'LoadHostSummary', 'ReloadHostSummaryList',
'JobIsFinished', 'SetTaskStyles', 'DigestEvent', 'UpdateDOM', 'EventViewer', 'DeleteJob', 'PlaybookRun', 'HostEventsViewer', 'LoadPlays', 'LoadTasks',
'LoadHosts', 'HostsEdit', 'ParseVariableString', 'GetChoices', 'fieldChoices', 'fieldLabels'
'LoadHosts', 'HostsEdit', 'ParseVariableString', 'GetChoices', 'fieldChoices', 'fieldLabels', 'EditSchedule'
];

View File

@ -183,11 +183,11 @@ export default
if (scope.removeScheduleSaved) {
scope.removeScheduleSaved();
}
scope.removeScheduleSaved = scope.$on('ScheduleSaved', function() {
scope.removeScheduleSaved = scope.$on('ScheduleSaved', function(e, data) {
Wait('stop');
$('#scheduler-modal-dialog').dialog('close');
if (callback) {
scope.$emit(callback);
scope.$emit(callback, data);
}
});
@ -310,11 +310,11 @@ export default
if (scope.removeScheduleSaved) {
scope.removeScheduleSaved();
}
scope.removeScheduleSaved = scope.$on('ScheduleSaved', function() {
scope.removeScheduleSaved = scope.$on('ScheduleSaved', function(e, data) {
Wait('stop');
$('#scheduler-modal-dialog').dialog('close');
if (callback) {
scope.$emit(callback);
scope.$emit(callback, data);
}
});
@ -390,7 +390,7 @@ export default
Rest.put(schedule)
.success(function(){
if (callback) {
scope.$emit(callback);
scope.$emit(callback, schedule);
}
else {
Wait('stop');

View File

@ -86,6 +86,13 @@
</div>
</div>
<div class="form-group toggle-show" style="display:none;" ng-show="scheduled_by">
<label class="col-lg-2 col-md-2 col-sm-2 col-xs-3 control-label">Launched By</label>
<div class="col-lg-10- col-md-10 col-sm-10 col-xs-9">
<a href aw-tool-tip="Edit the Schedule" data-placement="top" ng-click="editSchedule()">{{scheduled_by}}</a>
</div>
</div>
<div class="form-group toggle-show" style="display:none;" ng-show="inventory_name">
<label class="col-lg-2 col-md-2 col-sm-2 col-xs-3 control-label">Inventory</label>
<div class="col-lg-10- col-md-10 col-sm-10 col-xs-9">
@ -522,4 +529,6 @@
<div id="host-modal-dialog" style="display: none;" class="dialog-content"></div>
<div ng-include="'/static/partials/schedule_dialog.html'"></div>
</div>