guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: Add JSON representation for the Jobs page


From: Christopher Baines
Subject: branch master updated: Add JSON representation for the Jobs page
Date: Mon, 20 Apr 2020 16:05:42 -0400

This is an automated email from the git hooks/post-receive script.

cbaines pushed a commit to branch master
in repository data-service.

The following commit(s) were added to refs/heads/master by this push:
     new 60cb07f  Add JSON representation for the Jobs page
60cb07f is described below

commit 60cb07f469c6ad0a1dd483c5ad217b20073d9e77
Author: Danjela Lura <address@hidden>
AuthorDate: Mon Apr 20 09:44:33 2020 +0200

    Add JSON representation for the Jobs page
    
    Signed-off-by: Christopher Baines <address@hidden>
---
 guix-data-service/web/jobs/controller.scm | 41 +++++++++++++++++++++++++------
 guix-data-service/web/jobs/html.scm       |  9 +++++++
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/guix-data-service/web/jobs/controller.scm 
b/guix-data-service/web/jobs/controller.scm
index 7683a12..24a1274 100644
--- a/guix-data-service/web/jobs/controller.scm
+++ b/guix-data-service/web/jobs/controller.scm
@@ -19,6 +19,7 @@
   #:use-module (ice-9 match)
   #:use-module (guix-data-service web render)
   #:use-module (guix-data-service web query-parameters)
+  #:use-module (guix-data-service web util)
   #:use-module (guix-data-service jobs load-new-guix-revision)
   #:use-module (guix-data-service web jobs html)
   #:export (jobs-controller))
@@ -79,14 +80,38 @@
                 (assq-ref query-parameters 'before_id)
                 limit-results))
          (recent-events (select-recent-job-events conn)))
-    (render-html
-     #:sxml (view-jobs
-             query-parameters
-             jobs
-             recent-events
-             (and limit-results
-                  (>= (length jobs)
-                      limit-results))))))
+    (case (most-appropriate-mime-type
+           '(application/json text/html)
+           mime-types)
+      ((application/json)
+       (render-json
+        `((recent-events
+           . ,(list->vector
+               (map (match-lambda
+                      ((_ commit _ _ event occurred_at)
+                       `((commit . ,commit)
+                         (event . ,event)
+                         (occurred_at . ,occurred_at))))
+                    recent-events)))
+          (jobs
+           . ,(list->vector
+               (map (match-lambda
+                      ((_ commit source _ created-at _ events log)
+                       `((commit . ,commit)
+                         (source . ,source)
+                         (created-at . ,created-at)
+                         (events . ,events)
+                         (log . ,log))))
+                    jobs))))))
+      (else
+       (render-html
+        #:sxml (view-jobs
+                query-parameters
+                jobs
+                recent-events
+                (and limit-results
+                     (>= (length jobs)
+                         limit-results))))))))
 
 (define (render-job-events mime-types conn query-parameters)
   (let* ((limit-results
diff --git a/guix-data-service/web/jobs/html.scm 
b/guix-data-service/web/jobs/html.scm
index bf6b369..742d7bd 100644
--- a/guix-data-service/web/jobs/html.scm
+++ b/guix-data-service/web/jobs/html.scm
@@ -109,6 +109,15 @@
                                (class "btn btn-lg btn-primary"))
                             "Update results")))))))
       (div
+       (@ (class "btn-group pull-right")
+          (role "group"))
+       (a (@ (class "btn btn-lg btn-default")
+             (href ,(string-append
+                     "/jobs.json"))
+             (role "button"))
+          "View JSON"))
+
+      (div
        (@ (class "row"))
        (div
         (@ (class "col-sm-12"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]