# HG changeset patch # User Sebastien Jodogne # Date 1526054286 -7200 # Node ID b3da733d984c5600af4df572843fdf9de8b286cb # Parent 8da2cffc23787e695c5d7fe750991c7127d6e4cd job actions in Orthanc Explorer diff -r 8da2cffc2378 -r b3da733d984c OrthancExplorer/explorer.html --- a/OrthancExplorer/explorer.html Fri May 11 17:33:19 2018 +0200 +++ b/OrthancExplorer/explorer.html Fri May 11 17:58:06 2018 +0200 @@ -448,8 +448,7 @@
- - + diff -r 8da2cffc2378 -r b3da733d984c OrthancExplorer/explorer.js --- a/OrthancExplorer/explorer.js Fri May 11 17:33:19 2018 +0200 +++ b/OrthancExplorer/explorer.js Fri May 11 17:58:06 2018 +0200 @@ -1218,7 +1218,7 @@ target.listview('refresh'); - $('#job-delete').closest('.ui-btn').show(); + $('#job-cancel').closest('.ui-btn').hide(); $('#job-retry').closest('.ui-btn').hide(); $('#job-resubmit').closest('.ui-btn').hide(); $('#job-pause').closest('.ui-btn').hide(); @@ -1227,6 +1227,7 @@ if (job.State == 'Running' || job.State == 'Pending' || job.State == 'Retry') { + $('#job-cancel').closest('.ui-btn').show(); $('#job-pause').closest('.ui-btn').show(); } else if (job.State == 'Success') { @@ -1241,3 +1242,33 @@ }); } }); + + + +function TriggerJobAction(action) +{ + $.ajax({ + url: '../jobs/' + $.mobile.pageData.uuid + '/' + action, + type: 'POST', + async: false, + complete: function(s) { + window.location.reload(); + } + }); +} + +$('#job-cancel').live('click', function() { + TriggerJobAction('cancel'); +}); + +$('#job-resubmit').live('click', function() { + TriggerJobAction('resubmit'); +}); + +$('#job-pause').live('click', function() { + TriggerJobAction('pause'); +}); + +$('#job-resume').live('click', function() { + TriggerJobAction('resume'); +}); diff -r 8da2cffc2378 -r b3da733d984c OrthancServer/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Fri May 11 17:33:19 2018 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Fri May 11 17:58:06 2018 +0200 @@ -317,11 +317,45 @@ } } - static void PauseJob(RestApiPostCall& call) + + enum JobAction + { + JobAction_Cancel, + JobAction_Pause, + JobAction_Resubmit, + JobAction_Resume + }; + + template + static void ApplyJobAction(RestApiPostCall& call) { std::string id = call.GetUriComponent("id", ""); - if (OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id)) + bool ok = false; + + switch (action) + { + case JobAction_Cancel: + ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Cancel(id); + break; + + case JobAction_Pause: + ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Pause(id); + break; + + case JobAction_Resubmit: + ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resubmit(id); + break; + + case JobAction_Resume: + ok = OrthancRestApi::GetContext(call).GetJobsEngine().GetRegistry().Resume(id); + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + if (ok) { call.GetOutput().AnswerBuffer("{}", "application/json"); } @@ -347,6 +381,9 @@ Register("/jobs", ListJobs); Register("/jobs/{id}", GetJobInfo); - Register("/jobs/{id}/pause", PauseJob); + Register("/jobs/{id}/cancel", ApplyJobAction); + Register("/jobs/{id}/pause", ApplyJobAction); + Register("/jobs/{id}/resubmit", ApplyJobAction); + Register("/jobs/{id}/resume", ApplyJobAction); } }