aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/web/jobs
diff options
context:
space:
mode:
authorDanjela Lura <danielaluraa@gmail.com>2020-04-20 09:44:33 +0200
committerChristopher Baines <mail@cbaines.net>2020-04-20 21:02:22 +0100
commit60cb07f469c6ad0a1dd483c5ad217b20073d9e77 (patch)
tree1f22980da9a8be5bcb786456d5ed403974fc24a9 /guix-data-service/web/jobs
parentd09a1ca791007aac5dd0a873b2705ee5e2ffa730 (diff)
downloaddata-service-60cb07f469c6ad0a1dd483c5ad217b20073d9e77.tar
data-service-60cb07f469c6ad0a1dd483c5ad217b20073d9e77.tar.gz
Add JSON representation for the Jobs page
Signed-off-by: Christopher Baines <mail@cbaines.net>
Diffstat (limited to 'guix-data-service/web/jobs')
-rw-r--r--guix-data-service/web/jobs/controller.scm41
-rw-r--r--guix-data-service/web/jobs/html.scm9
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"))