1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
5 ;;; This program is free software: you can redistribute it and/or
6 ;;; modify it under the terms of the GNU Affero General Public License
7 ;;; as published by the Free Software Foundation, either version 3 of
8 ;;; the License, or (at your option) any later version.
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;; Affero General Public License for more details.
15 ;;; You should have received a copy of the GNU Affero General Public
16 ;;; License along with this program. If not, see
17 ;;; <http://www.gnu.org/licenses/>.
19 (define-module (mumi web view html
)
20 #:use-module
(debbugs bug
)
21 #:use-module
(email email
)
22 #:use-module
(mumi config
)
23 #:use-module
(mumi messages
)
24 #:use-module
(mumi web view utils
)
25 #:use-module
(ice-9 match
)
26 #:use-module
(srfi srfi-1
)
27 #:use-module
(srfi srfi-19
)
33 list-of-matching-bugs
))
35 (define (bug-subject* bug
)
36 (or (bug-subject bug
) "(no subject)"))
38 (define (status-tag bug
)
39 "Return a colored tag indicating the BUG status."
40 (let ((status (if (bug-done bug
) "Done" "Open")))
41 `(span (@ (class ,(string-append "status-tag "
42 (string-downcase status
))))
45 (define* (layout #:key
48 (title "Guix issue tracker")
50 `(#:sxml
((doctype "html")
54 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
55 (meta (@ (http-equiv "Content-Language") (content "en")))
56 (meta (@ (name "author") (content "Ricardo Wurmus")))
57 (meta (@ (name "viewport")
58 (content "width=device-width, initial-scale=1")))
63 (href "/css/reset.css")))
68 (href "/css/bootstrap.css")))
74 (href "/css/screen.css")))
79 (href "/css/code.css"))))
81 (footer (@ (class "text-center"))
82 (p "Copyright © 2016—2020 by the GNU Guix community."
84 "Now with even more " (span (@ (class "lambda")) "λ") "! ")
85 (p "This is free software. Download the "
86 (a (@ (href "https://git.elephly.net/software/mumi.git"))
87 "source code here") ".")))
89 (@ (type "text/javascript")
90 (src "/js/sort-table.js")))))
91 #:extra-headers
,extra-headers
))
93 (define* (search-form #:key
(standalone?
#f
) (text ""))
94 `(form (@ (id "search")
97 '(class "form-inline"))
100 (@ (class ,(if standalone?
101 "input-group input-group-lg"
103 (input (@ (type "text")
104 (class "form-control")
108 (placeholder "Input your search query...")))
109 (span (@ (class "input-group-append"))
112 (class ,(string-append (if standalone?
"btn-lg " "")
114 ;; This SVG is part of Bootstrap and is available
115 ;; under the Expat license.
117 (@ (class "bi bi-search")
120 (viewBox "0 0 16 16")
121 (fill "currentColor")
122 (xmlns "http://www.w3.org/2000/svg"))
124 (path (@ (fill-rule "evenodd")
125 (d "M10.442 10.442a1 1 0 011.415 0l3.85 3.85a1 1 0 01-1.414 1.415l-3.85-3.85a1 1 0 010-1.415z")
126 (clip-rule "evenodd")) "")
127 (path (@ (fill-rule "evenodd")
128 (d "M6.5 12a5.5 5.5 0 100-11 5.5 5.5 0 000 11zM13 6.5a6.5 6.5 0 11-13 0 6.5 6.5 0 0113 0z")
129 (clip-rule "evenodd")) "")))))))
132 (define* (search-widget #:key
(text ""))
134 (@ (class "card mb-3"))
135 (div (@ (class "card-body bg-light"))
136 ,(search-form #:standalone?
#t
#:text text
)
138 (summary (strong "Hint"))
140 "Refine your search with filters like "
141 (span (@ (class "filter"))
144 (span (@ (class "filter"))
147 (span (@ (class "filter"))
150 (span (@ (class "filter"))
153 (span (@ (class "filter"))
154 "date:2018-04-01..2018-04-02")
156 (span (@ (class "filter"))
159 (a (@ (href "help#search"))
162 (define* (header #:key
(search-bar?
#t
))
164 (@ (class "navbar navbar-expand navbar-light bg-light"))
165 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
166 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
174 '((cache-control .
((max-age .
60))))
176 `(,(header #:search-bar?
#f
)
178 (@ (class "container"))
179 (h1 "Guix issue tracker")
180 (p (@ (class "lead"))
181 "This is a web frontend to the Guix patch and bug trackers. Send email to "
182 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
183 ,(%config
'submission-email-address
))
184 " to submit a patch, or email "
185 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
186 ,(%config
'submission-bug-email-address
))
187 " to submit a bug report.")
190 (div (@ (class "mt-4 h4")) "Recent activity")
192 (@ (class "table table-borderless table-hover js-sort-table"))
194 (tr (@ (class "heading"))
195 (th (@ (class "js-sort-number")) "ID")
197 (th "Date submitted")
200 ,@(list-of-bugs (recent-bugs 10))))
202 (div (@ (class "mt-4 h4")) "Priority bugs")
204 (@ (class "table table-borderless table-hover js-sort-table"))
206 (tr (@ (class "heading"))
207 (th (@ (class "js-sort-number")) "ID")
209 (th "Date submitted")
212 ,@(priority-bugs)))))))
217 ;; Cache for 24 hours.
218 '((cache-control .
((max-age .
86400))))
220 `(,(header #:search-bar?
#f
)
222 (@ (class "container"))
224 (a (@ (href "search")))
225 (p "You can improve the search results by making use of the
226 simple query language. Here is a list of supported query terms with
232 (th (@ (class "col-md-3")) "Filter")
233 (th (@ (class "col-md-9")) "Description")))
236 (td (span (@ (class "filter")) "is:open") ", "
237 (span (@ (class "filter")) "is:pending"))
240 (td (span (@ (class "filter")) "is:closed") ", "
241 (span (@ (class "filter")) "is:done"))
242 (td "Issues marked as done."))
244 (td (span (@ (class "filter")) "submitter:<who>"))
245 (td "Issues submitted by a person named " (strong "who")
247 (span (@ (class "filter")) "submitter:ludo")
248 " for all issues submitted by ludo. "
249 "The filter matches both the email address and the name."))
251 (td (span (@ (class "filter")) "author:<who>"))
252 (td "Issues where a person named " (strong "who")
253 " has commented, e.g. "
254 (span (@ (class "filter")) "author:rekado")
255 " for all messages where rekado has commented. "
256 "The filter matches both the email address and the name."))
258 (td (span (@ (class "filter")) "date:<start>..<end>"))
259 (td "Issues or comments submitted within the provided range. "
260 (strong "start") " and " (strong "end") " can be one of "
261 (strong "now") ", " (strong "today")
262 ", a date in the formats "
263 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
264 ", or an amount and a unit for a point in the past, such as "
265 (strong "12d..") " for 12 days ago. "
266 "Supported units are: "
267 (strong "h") " (hours), "
268 (strong "d") " (days), "
269 (strong "w") " (weeks), "
270 (strong "m") " (months), and "
271 (strong "y") " (years)."))))))))
277 (div (@ (class "container"))
278 (h1 "Patch not found")
279 (p "There is no submission with id " (strong ,id
))
280 (p (a (@ (href "/")) "Try another one?"))))))
282 (define (error-page message
)
286 (div (@ (class "container"))
288 (p "An error occurred. Sorry about that!")
290 (p (a (@ (href "/")) "Try something else?"))))))
292 (define (issue-page bug
)
293 "Render the conversation for the given BUG."
294 (define id
(bug-num bug
))
295 (define messages
(patch-messages id
))
296 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
297 (participants (filter identity messages
)))
299 (string< (extract-email a
)
300 (extract-email b
)))))
301 (define (show-message message-number message previous-subject
)
302 `((div (@ (class "mb-5"))
303 (a (@ (id ,(number->string message-number
))))
306 (style ,(string-append "background-color:"
307 (avatar-color (sender-email message
)
308 (map extract-email parties
)))))
309 ,(string-upcase (string-take (sender-name message
) 1)))
311 (@ (class "message"))
315 (@ (class "card-header"))
320 (style ,(string-append "background-color:"
321 (avatar-color (sender-email message
)
322 (map extract-email parties
)))))
323 ,(string-upcase (string-take (sender-name message
) 1)))
324 (span (@ (class "address")) ,(sender-name message
))
326 (span (@ (class "date"))
327 (a (@ (href ,(string-append "#" (number->string
329 ,(date->string
(date message
)))))
330 ,@(if (string-suffix? previous-subject
(subject message
))
332 `((div (@ (class "subject")) ,(subject message
))))
334 (@ (class "details"))
336 (@ (class "recipients"))
337 (label "Recipients:")
338 ,(map (lambda (address)
339 `(span (@ (class "address")) ,address
))
340 (recipients message
)))
342 (@ (class "message-id"))
343 (label "Message-ID:")
344 ,(message-id message
))))
346 (@ (class "body card-body"))
347 ,(display-message-body id message-number message
)))))
348 ,@(if (closing? message id
)
350 (@ (class "row event"))
352 (@ (class "col-md-11 offset-md-1 text-center"))
353 (div (@ (class "badge badge-primary closed")) "Closed"))))
356 #:title
(bug-subject* bug
)
360 ;; Tell browser to cache this for 12 hours.
361 '((cache-control .
((max-age .
43200)))))
363 ;; Tell browser to cache this for 1 hour.
364 '((cache-control .
((max-age .
3600)))))
369 (@ (class "container"))
371 (@ (class "title col-md-12"))
372 (h1 ,(bug-subject* bug
))
373 (span (@ (class "details"))
375 ,(string-append "Submitted by "
376 ;; We don't use bug-originator here
377 ;; because it includes the email address.
378 ;; We cannot use extract-name on the
379 ;; return value, because it swallows
380 ;; non-ASCII characters.
381 (sender-name (first messages
))
383 ,@(if (bug-mergedwith bug
)
384 `((ul (@ (class "merged"))
387 `(li (a (@ (href ,(string-append "/issue/" id
)))
389 ;; XXX: This field can either hold a
390 ;; string of multiple ids, or a single
391 ;; number. Deal with this mess.
392 (match (bug-mergedwith bug
)
394 (string-split str
#\space
))
396 (list (number->string n
)))))))
398 ,@(if (bug-blocks bug
)
399 `((ul (@ (class "blocks"))
402 `(li (a (@ (href ,(string-append "/issue/" id
)))
404 ;; XXX: This field can either hold a
405 ;; string of multiple ids, or a single
406 ;; number. Deal with this mess.
407 (match (bug-blocks bug
)
409 (string-split str
#\space
))
411 (list (number->string n
)))))))
413 ,@(if (bug-blockedby bug
)
414 `((ul (@ (class "blockedby"))
417 `(li (a (@ (href ,(string-append "/issue/" id
)))
419 ;; XXX: This field can either hold a
420 ;; string of multiple ids, or a single
421 ;; number. Deal with this mess.
422 (match (bug-blockedby bug
)
424 (string-split str
#\space
))
426 (list (number->string n
)))))))
428 (div (@ (class "row"))
430 (@ (class "conversation col-md-9"))
431 ,(let ((msgs (filter (lambda (msg)
434 ;; internal messages.
437 (not (internal-message? msg
))))
439 (map (lambda (message-number msg previous-subject
)
440 (show-message message-number msg previous-subject
))
443 (cons (bug-subject* bug
)
444 (map subject msgs
))))
446 (@ (class "comment-box"))
447 (a (@ (id "comment")))
450 (style "background-color:#bc80bd")) "?")
452 (@ (class "message"))
456 (@ (class "card-header"))
457 (div (@ (class "from"))
458 (span (@ (class "address")) "Your comment")))
460 (@ (class "body card-body"))
461 (p "Comments via the web interface are not currently
462 supported. To comment on this conversation "
463 (a (@ (href ,(string-append "mailto:"
464 (number->string id
) "@" (%config
'debbugs-domain
)
465 "?subject=" (bug-subject* bug
))))
466 ,(string-append "send email to "
467 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
470 (@ (class "info col-md-3"))
473 ,@(let ((num (length parties
)))
476 (string-append (number->string num
)
479 (ul ,(map (lambda (name)
480 `(li (span (@ (class "name")))
482 (map extract-name parties
)))))))
487 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
491 (dd ,(bug-severity bug
)))
495 (dd ,(status-tag bug
)))))))))
497 (define (list-of-bugs bugs
)
498 "Return table rows for all BUGS."
500 (let ((id (number->string
(bug-num bug
))))
501 `(tr (@ (class ,(bug-severity bug
)))
504 ,@(if (member (bug-severity bug
) '("serious" "important"))
505 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
506 (xmlns:xlink
"http://www.w3.org/1999/xlink")
507 (viewBox "0 0 14 16")
511 (aria-hidden "true"))
512 (title ,(bug-severity bug
))
513 (path (@ (fill-rule "evenodd")
515 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
516 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
517 c0-3.14 2.56-5.7 5.7-5.7z\
518 M7 1C3.14 1 0 4.14 0 8\
519 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
520 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
523 `(a (@ (href ,(string-append "/issue/" id
)))
526 (td ,(date->string
(bug-date bug
)))
527 (td ,(status-tag bug
)))))
530 (define (priority-bugs)
533 (bugs-by-severity "serious" "open")
534 (bugs-by-severity "important" "open"))
535 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
537 (define (list-of-matching-bugs query bugs
)
540 `(,(header #:search-bar?
#f
)
542 (@ (class "container"))
543 (h1 "Your search for " (code ,query
))
544 ,(search-widget #:text query
)
547 (@ (class "alert alert-warning")
550 (@ (class "alert-heading"))
552 (p "We could not find any issues matching your query "
555 "Try searching for something else?")))
557 (@ (class "table table-borderless table-hover js-sort-table"))
559 (tr (@ (class "heading"))
560 (th (@ (class "js-sort-number")) "ID")
562 (th "Date submitted")
565 ,@(list-of-bugs bugs
))))))))