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
(mumi web util
)
26 #:use-module
(ice-9 match
)
27 #:use-module
(srfi srfi-1
)
28 #:use-module
(srfi srfi-19
)
35 list-of-recent-issues
))
37 (define (bug-subject* bug
)
38 (or (bug-subject bug
) "(no subject)"))
40 (define (status-tag bug
)
41 "Return a colored tag indicating the BUG status."
42 (let ((status (if (bug-done bug
) "Done" "Open")))
43 `(span (@ (class ,(string-append "status-tag "
44 (string-downcase status
))))
47 (define* (layout #:key
50 (title "Guix issue tracker"))
55 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
56 (meta (@ (http-equiv "Content-Language") (content "en")))
57 (meta (@ (name "author") (content "Ricardo Wurmus")))
58 (meta (@ (name "viewport")
59 (content "width=device-width, initial-scale=1")))
64 (href "/css/reset.css")))
69 (href "/css/bootstrap.css")))
75 (href "/css/screen.css")))
80 (href "/css/code.css"))))
82 (footer (@ (class "text-center"))
83 (p "Copyright © 2016—2020 by the GNU Guix community."
85 "Now with even more " (span (@ (class "lambda")) "λ") "! ")
86 (p "This is free software. Download the "
87 (a (@ (href "https://git.elephly.net/software/mumi.git"))
88 "source code here") ".")))
90 (@ (type "text/javascript")
91 (src "/js/sort-table.js"))))))
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 `(,(header #:search-bar?
#f
)
176 (@ (class "container"))
177 (h1 "Guix issue tracker")
178 (p (@ (class "lead"))
179 "This is a web frontend to the Guix patch and bug trackers. Send email to "
180 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
181 ,(%config
'submission-email-address
))
182 " to submit a patch, or email "
183 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
184 ,(%config
'submission-bug-email-address
))
185 " to submit a bug report.")
188 (div (@ (class "mt-4 h4")) "Recent activity")
190 (@ (class "table table-borderless table-hover js-sort-table"))
192 (tr (@ (class "heading"))
193 (th (@ (class "js-sort-number")) "ID")
195 (th "Date submitted")
198 ,@(list-of-bugs (recent-bugs 10))))
200 (div (@ (class "mt-4 h4")) "Priority bugs")
202 (@ (class "table table-borderless table-hover js-sort-table"))
204 (tr (@ (class "heading"))
205 (th (@ (class "js-sort-number")) "ID")
207 (th "Date submitted")
210 ,@(priority-bugs)))))))
215 `(,(header #:search-bar?
#f
)
217 (@ (class "container"))
219 (a (@ (href "search")))
220 (p "You can improve the search results by making use of the
221 simple query language. Here is a list of supported query terms with
227 (th (@ (class "col-md-3")) "Filter")
228 (th (@ (class "col-md-9")) "Description")))
231 (td (span (@ (class "filter")) "is:open") ", "
232 (span (@ (class "filter")) "is:pending"))
235 (td (span (@ (class "filter")) "is:closed") ", "
236 (span (@ (class "filter")) "is:done"))
237 (td "Issues marked as done."))
239 (td (span (@ (class "filter")) "submitter:<who>"))
240 (td "Issues submitted by a person named " (strong "who")
242 (span (@ (class "filter")) "submitter:ludo")
243 " for all issues submitted by ludo. "
244 "The filter matches both the email address and the name."))
246 (td (span (@ (class "filter")) "author:<who>"))
247 (td "Issues where a person named " (strong "who")
248 " has commented, e.g. "
249 (span (@ (class "filter")) "author:rekado")
250 " for all messages where rekado has commented. "
251 "The filter matches both the email address and the name."))
253 (td (span (@ (class "filter")) "date:<start>..<end>"))
254 (td "Issues submitted within the provided range. "
255 (strong "start") " and " (strong "end") " can be one of "
256 (strong "now") ", " (strong "today")
257 ", a date in the formats "
258 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
259 ", or an amount and a unit for a point in the past, such as "
260 (strong "12d..") " for 12 days ago. "
261 "Supported units are: "
262 (strong "h") " (hours), "
263 (strong "d") " (days), "
264 (strong "w") " (weeks), "
265 (strong "m") " (months), and "
266 (strong "y") " (years)."))
268 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
269 (td "This is just like " (span (@ (class "filter")) "date")
270 " except that it also includes comments."))))))))
276 (div (@ (class "container"))
277 (h1 "Issue not found")
278 (p "There is no submission with id " (strong ,id
) ", or we
279 failed to process associated messages.")
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
#:optional flash-message
)
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-11 offset-1 text-center"))
353 (div (@ (class "badge badge-primary closed")) "Closed"))))
355 (if (null? messages
) #f
357 #:title
(bug-subject* bug
)
361 (@ (class "container"))
362 ,@(match flash-message
364 `((div (@ (class "alert alert-danger")
368 `((div (@ (class "alert alert-info")
373 (@ (class "title col-12"))
374 (h1 ,(bug-subject* bug
))
375 (span (@ (class "details"))
377 ,(string-append "Submitted by "
378 ;; We don't use bug-originator here
379 ;; because it includes the email address.
380 ;; We cannot use extract-name on the
381 ;; return value, because it swallows
382 ;; non-ASCII characters.
383 (sender-name (first messages
))
385 ,@(if (bug-mergedwith bug
)
386 `((ul (@ (class "merged"))
389 `(li (a (@ (href ,(string-append "/issue/" id
)))
391 ;; XXX: This field can either hold a
392 ;; string of multiple ids, or a single
393 ;; number. Deal with this mess.
394 (match (bug-mergedwith bug
)
396 (string-split str
#\space
))
398 (list (number->string n
)))))))
400 ,@(if (bug-blocks bug
)
401 `((ul (@ (class "blocks"))
404 `(li (a (@ (href ,(string-append "/issue/" id
)))
406 ;; XXX: This field can either hold a
407 ;; string of multiple ids, or a single
408 ;; number. Deal with this mess.
409 (match (bug-blocks bug
)
411 (string-split str
#\space
))
413 (list (number->string n
)))))))
415 ,@(if (bug-blockedby bug
)
416 `((ul (@ (class "blockedby"))
419 `(li (a (@ (href ,(string-append "/issue/" id
)))
421 ;; XXX: This field can either hold a
422 ;; string of multiple ids, or a single
423 ;; number. Deal with this mess.
424 (match (bug-blockedby bug
)
426 (string-split str
#\space
))
428 (list (number->string n
)))))))
430 (div (@ (class "row"))
432 (@ (class "conversation col-lg-9"))
433 ,(let ((msgs (filter (lambda (msg)
436 ;; internal messages.
439 (not (internal-message? msg
))))
441 (map (lambda (message-number msg previous-subject
)
442 (show-message message-number msg previous-subject
))
445 (cons (bug-subject* bug
)
446 (map subject msgs
))))
448 (@ (class "comment-box"))
449 (a (@ (id "comment")))
452 (style "background-color:#bc80bd")) "?")
454 (@ (class "message"))
457 ,@(if (mailer-enabled?
)
459 (@ (action ,(format #f
"/issue/~a/comment"
460 (number->string id
)))
461 (enctype "multipart/form-data")
463 (input (@ (style "display:none")
465 (placeholder "Please leave this empty.")) "")
466 (input (@ (type "hidden")
468 (value ,(timestamp!))) "")
470 (@ (class "card-header"))
471 (div (@ (class "from"))
472 (input (@ (class "address form-control")
474 (required "required")
475 (placeholder "Your name")) "")))
477 (@ (class "body card-body"))
478 (textarea (@ (name "text")
479 (required "required")
480 (class "form-control")
481 (placeholder "Please input your comment..."))
484 (@ (class "card-footer"))
485 (button (@ (class "btn btn-primary")
489 (@ (class "card-header"))
490 (div (@ (class "from"))
491 (span (@ (class "address")) "Your comment")))
493 (@ (class "body card-body"))
494 (p "Comments via the web interface are not currently
495 supported. To comment on this conversation "
496 (a (@ (href ,(string-append "mailto:"
497 (number->string id
) "@" (%config
'debbugs-domain
)
498 "?subject=" (bug-subject* bug
))))
499 ,(string-append "send email to "
500 (number->string id
) "@" (%config
'debbugs-domain
)))))))))))
503 (@ (class "info col-lg-3"))
506 ,@(let ((num (length parties
)))
509 (string-append (number->string num
)
512 (ul ,(map (lambda (name)
513 `(li (span (@ (class "name")))
515 (map extract-name parties
)))))))
520 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
524 (dd ,(bug-severity bug
)))
528 (dd ,(status-tag bug
))))))))))
530 (define (list-of-bugs bugs
)
531 "Return table rows for all BUGS."
533 (let ((id (number->string
(bug-num bug
))))
534 `(tr (@ (class ,(bug-severity bug
)))
537 ,@(if (member (bug-severity bug
) '("serious" "important"))
538 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
539 (xmlns:xlink
"http://www.w3.org/1999/xlink")
540 (viewBox "0 0 14 16")
544 (aria-hidden "true"))
545 (title ,(bug-severity bug
))
546 (path (@ (fill-rule "evenodd")
548 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
549 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
550 c0-3.14 2.56-5.7 5.7-5.7z\
551 M7 1C3.14 1 0 4.14 0 8\
552 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
553 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
556 `(a (@ (href ,(string-append "/issue/" id
)))
559 (td ,(date->string
(bug-date bug
)))
560 (td ,(status-tag bug
)))))
563 (define (priority-bugs)
566 (bugs-by-severity "serious" "open")
567 (bugs-by-severity "important" "open"))
568 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
570 (define* (list-of-recent-issues #:optional
(max 100))
573 `(,(header #:search-bar?
#f
)
575 (@ (class "container"))
578 (@ (class "table table-borderless table-hover js-sort-table"))
580 (tr (@ (class "heading"))
581 (th (@ (class "js-sort-number")) "ID")
583 (th "Date submitted")
586 ,@(list-of-bugs (recent-bugs max
))))))))
588 (define (list-of-matching-bugs query bugs
)
591 `(,(header #:search-bar?
#f
)
593 (@ (class "container"))
594 (h1 "Your search for " (code ,query
))
595 ,(search-widget #:text query
)
598 (@ (class "alert alert-warning")
601 (@ (class "alert-heading"))
603 (p "We could not find any issues matching your query "
606 "Try searching for something else?")))
608 (@ (class "table table-borderless table-hover js-sort-table"))
610 (tr (@ (class "heading"))
611 (th (@ (class "js-sort-number")) "ID")
613 (th "Date submitted")
616 ,@(list-of-bugs bugs
))))))))