From 64151eee28f70371a6a90302f74a02645e3cf66a Mon Sep 17 00:00:00 2001
From: Mathieu Othacehe <othacehe@gnu.org>
Date: Thu, 18 Feb 2021 15:22:59 +0100
Subject: [PATCH] Add an evaluation restart button.

* src/cuirass/http.scm (url-handler): New route
"/admin/evaluation/<id>/restart".
* src/cuirass/templates.scm (evaluation-info-table): Add an evaluation restart
button.
---
 src/cuirass/http.scm      | 13 +++++++++++++
 src/cuirass/templates.scm | 20 ++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index afd5410f..73f71511 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -491,6 +491,19 @@ Hydra format."
        #:headers `((location . ,(string->uri-reference
                                  (string-append "/build/" id "/details")))))
       #:body ""))
+
+    (('GET "admin" "evaluation" id "restart")
+     (let* ((eval (db-get-evaluation id))
+            (specification (assq-ref eval #:specification)))
+       (db-restart-evaluation! (string->number id))
+       (respond
+        (build-response
+         #:code 302
+         #:headers `((location
+                      . ,(string->uri-reference
+                          (string-append "/jobset/" specification)))))
+        #:body "")))
+
     (('GET "admin")
      (respond-html (html-page
                     "Cuirass [Admin]"
diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
index c9294e3f..a57653b2 100644
--- a/src/cuirass/templates.scm
+++ b/src/cuirass/templates.scm
@@ -495,7 +495,8 @@ system whose names start with " (code "guile-") ":" (br)
               (tr
                (th (@ (scope "col")) "#")
                (th (@ (scope "col")) "Input changes")
-               (th (@ (scope "col")) Success)))
+               (th (@ (scope "col")) Success)
+               (th (@ (scope "col")) Action)))
              (tbody
               ,@(map
                  (lambda (row)
@@ -503,7 +504,22 @@ system whose names start with " (code "guile-") ":" (br)
                             (a (@ (href "/eval/" ,(assq-ref row #:id)))
                                ,(assq-ref row #:id)))
                         (td ,(input-changes (assq-ref row #:checkouts)))
-                        (td ,@(evaluation-badges row))))
+                        (td ,@(evaluation-badges row))
+                        (td
+                         (div (@ (class "dropdown"))
+                              (a (@ (class "oi oi-menu dropdown-toggle")
+                                    (href "#")
+                                    (data-toggle "dropdown")
+                                    (role "button")
+                                    (aria-haspopup "true")
+                                    (aria-expanded "false"))
+                                 " ")
+                              (div (@ (class "dropdown-menu"))
+                                   (a (@ (class "dropdown-item")
+                                         (href "/admin/evaluation/"
+                                               ,(assq-ref row #:id)
+                                               "/restart"))
+                                      "Restart"))))))
                  evaluations)))))
     ,(if (null? evaluations)
          (pagination "" "" "" "")
-- 
GitLab