changeset 2582:b3da733d984c jobs

job actions in Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 May 2018 17:58:06 +0200
parents 8da2cffc2378
children 1b6a6d80b6f2
files OrthancExplorer/explorer.html OrthancExplorer/explorer.js OrthancServer/OrthancRestApi/OrthancRestSystem.cpp
diffstat 3 files changed, 73 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
         <fieldset class="ui-grid-b">
           <div class="ui-block-a"></div>
 	  <div class="ui-block-b">
-            <button id="job-delete" data-theme="b">Delete job</button>         
-            <button id="job-retry" data-theme="b">Retry job</button>         
+            <button id="job-cancel" data-theme="b">Cancel job</button>         
             <button id="job-resubmit" data-theme="b">Resubmit job</button>         
             <button id="job-pause" data-theme="b">Pause job</button>         
             <button id="job-resume" data-theme="b">Resume job</button>         
--- 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');
+});
--- 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 <JobAction action>
+  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<JobAction_Cancel>);
+    Register("/jobs/{id}/pause", ApplyJobAction<JobAction_Pause>);
+    Register("/jobs/{id}/resubmit", ApplyJobAction<JobAction_Resubmit>);
+    Register("/jobs/{id}/resume", ApplyJobAction<JobAction_Resume>);
   }
 }