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")) ""))))
131 (@ (id "search-hints"))
132 (p "You can improve the search results by making use of the
133 simple query language. Here is a list of supported query terms:")
135 (@ (class "table table-sm table-borderless"))
139 `(tr (td (span (@ (class "filter")) ,term
))
141 '(("is:open" "open issues")
142 ("is:done" "closed issues")
143 ("submitter:<who>" "search issue submitter")
144 ("author:<who>" "search by message author")
145 ("date:yesterday..now" "search by issue date")
146 ("mdate:3m..2d" "search by message date")))))))))
148 (define* (search-widget #:key
(text ""))
150 (@ (class "card mb-3"))
151 (div (@ (class "card-body bg-light"))
152 ,(search-form #:standalone?
#t
#:text text
)
154 (summary (strong "Hint"))
156 "Refine your search with filters like "
157 (span (@ (class "filter"))
160 (span (@ (class "filter"))
163 (span (@ (class "filter"))
166 (span (@ (class "filter"))
169 (span (@ (class "filter"))
170 "date:2018-04-01..2018-04-02")
172 (span (@ (class "filter"))
175 (a (@ (href "help#search"))
178 (define* (header #:key
(search-bar?
#t
))
180 (@ (class "navbar navbar-expand navbar-light bg-light"))
181 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
182 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
190 `(,(header #:search-bar?
#f
)
192 (@ (class "container"))
193 (h1 "Guix issue tracker")
194 (p (@ (class "lead"))
195 "This is a web frontend to the Guix patch and bug trackers. Send email to "
196 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
197 ,(%config
'submission-email-address
))
198 " to submit a patch, or email "
199 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
200 ,(%config
'submission-bug-email-address
))
201 " to submit a bug report.")
204 (div (@ (class "mt-4 h4")) "Recent activity "
205 (small (a (@ (href "recent")) "(More)")))
207 (@ (class "table table-borderless table-hover js-sort-table"))
209 (tr (@ (class "heading"))
210 (th (@ (class "js-sort-number")) "ID")
212 (th "Date submitted")
215 ,@(list-of-bugs (recent-bugs 10))))
217 (div (@ (class "mt-4 h4")) "Priority bugs")
219 (@ (class "table table-borderless table-hover js-sort-table"))
221 (tr (@ (class "heading"))
222 (th (@ (class "js-sort-number")) "ID")
224 (th "Date submitted")
227 ,@(priority-bugs)))))))
232 `(,(header #:search-bar?
#f
)
234 (@ (class "container"))
236 (a (@ (href "search")))
237 (p "You can improve the search results by making use of the
238 simple query language. Here is a list of supported query terms with
244 (th (@ (class "col-md-3")) "Filter")
245 (th (@ (class "col-md-9")) "Description")))
248 (td (span (@ (class "filter")) "is:open") ", "
249 (span (@ (class "filter")) "is:pending"))
252 (td (span (@ (class "filter")) "is:closed") ", "
253 (span (@ (class "filter")) "is:done"))
254 (td "Issues marked as done."))
256 (td (span (@ (class "filter")) "submitter:<who>"))
257 (td "Issues submitted by a person named " (strong "who")
259 (span (@ (class "filter")) "submitter:ludo")
260 " for all issues submitted by ludo. "
261 "The filter matches both the email address and the name."))
263 (td (span (@ (class "filter")) "author:<who>"))
264 (td "Issues where a person named " (strong "who")
265 " has commented, e.g. "
266 (span (@ (class "filter")) "author:rekado")
267 " for all messages where rekado has commented. "
268 "The filter matches both the email address and the name."))
270 (td (span (@ (class "filter")) "date:<start>..<end>"))
271 (td "Issues submitted within the provided range. "
272 (strong "start") " and " (strong "end") " can be one of "
273 (strong "now") ", " (strong "today")
274 ", a date in the formats "
275 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
276 ", or an amount and a unit for a point in the past, such as "
277 (strong "12d..") " for 12 days ago. "
278 "Supported units are: "
279 (strong "h") " (hours), "
280 (strong "d") " (days), "
281 (strong "w") " (weeks), "
282 (strong "m") " (months), and "
283 (strong "y") " (years)."))
285 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
286 (td "This is just like " (span (@ (class "filter")) "date")
287 " except that it also includes comments."))))))))
293 (div (@ (class "container"))
294 (h1 "Issue not found")
295 (p "There is no submission with id " (strong ,id
) ", or we
296 failed to process associated messages.")
297 (p (a (@ (href "/")) "Try another one?"))))))
299 (define (error-page message
)
303 (div (@ (class "container"))
305 (p "An error occurred. Sorry about that!")
307 (p (a (@ (href "/")) "Try something else?"))))))
309 (define* (issue-page bug
#:optional flash-message
)
310 "Render the conversation for the given BUG."
311 (define id
(bug-num bug
))
312 (define messages
(issue-messages id
))
313 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
314 (participants (filter identity messages
)))
316 (string< (extract-email a
)
317 (extract-email b
)))))
318 (define (show-message message-number message previous-subject
)
319 `((div (@ (class "mb-5"))
320 (a (@ (id ,(number->string message-number
))))
323 (style ,(string-append "background-color:"
324 (avatar-color (sender-email message
)
325 (map extract-email parties
)))))
326 ,(string-upcase (string-take (sender-name message
) 1)))
328 (@ (class "message"))
332 (@ (class "card-header"))
337 (style ,(string-append "background-color:"
338 (avatar-color (sender-email message
)
339 (map extract-email parties
)))))
340 ,(string-upcase (string-take (sender-name message
) 1)))
341 (span (@ (class "address")) ,(sender-name message
))
343 (span (@ (class "date"))
344 (a (@ (href ,(string-append "#" (number->string
346 ,(date->string
(date message
)))))
347 ,@(if (string-suffix? previous-subject
(subject message
))
349 `((div (@ (class "subject")) ,(subject message
))))
351 (@ (class "details"))
353 (@ (class "recipients"))
354 (label "Recipients:")
355 ,(map (lambda (address)
356 `(span (@ (class "address")) ,address
))
357 (recipients message
)))
359 (@ (class "message-id"))
360 (label "Message-ID:")
361 ,(message-id message
))))
363 (@ (class "body card-body"))
364 ,(display-message-body id message-number message
)))))
365 ,@(if (closing? message id
)
367 (@ (class "row event"))
369 (@ (class "col-11 offset-1 text-center"))
370 (div (@ (class "badge badge-primary closed")) "Closed"))))
372 (if (null? messages
) #f
374 #:title
(bug-subject* bug
)
378 (@ (class "container"))
379 ,@(match flash-message
381 `((div (@ (class "alert alert-danger")
385 `((div (@ (class "alert alert-info")
390 (@ (class "title col-12"))
391 (h1 ,(bug-subject* bug
))
392 (span (@ (class "details"))
394 ,(string-append "Submitted by "
395 ;; We don't use bug-originator here
396 ;; because it includes the email address.
397 ;; We cannot use extract-name on the
398 ;; return value, because it swallows
399 ;; non-ASCII characters.
400 (sender-name (first messages
))
402 ,@(if (bug-mergedwith bug
)
403 `((ul (@ (class "merged"))
406 `(li (a (@ (href ,(string-append "/issue/" id
)))
408 ;; XXX: This field can either hold a
409 ;; string of multiple ids, or a single
410 ;; number. Deal with this mess.
411 (match (bug-mergedwith bug
)
413 (string-split str
#\space
))
415 (list (number->string n
)))))))
417 ,@(if (bug-blocks bug
)
418 `((ul (@ (class "blocks"))
421 `(li (a (@ (href ,(string-append "/issue/" id
)))
423 ;; XXX: This field can either hold a
424 ;; string of multiple ids, or a single
425 ;; number. Deal with this mess.
426 (match (bug-blocks bug
)
428 (string-split str
#\space
))
430 (list (number->string n
)))))))
432 ,@(if (bug-blockedby bug
)
433 `((ul (@ (class "blockedby"))
436 `(li (a (@ (href ,(string-append "/issue/" id
)))
438 ;; XXX: This field can either hold a
439 ;; string of multiple ids, or a single
440 ;; number. Deal with this mess.
441 (match (bug-blockedby bug
)
443 (string-split str
#\space
))
445 (list (number->string n
)))))))
447 (div (@ (class "row"))
449 (@ (class "conversation col-lg-9"))
450 ,(let ((msgs (filter (lambda (msg)
453 ;; internal messages.
456 (not (internal-message? msg
))))
458 (map (lambda (message-number msg previous-subject
)
459 (show-message message-number msg previous-subject
))
462 (cons (bug-subject* bug
)
463 (map subject msgs
))))
465 (@ (class "comment-box"))
466 (a (@ (id "comment")))
469 (style "background-color:#bc80bd")) "?")
471 (@ (class "message"))
474 ,@(if (mailer-enabled?
)
476 (@ (action ,(format #f
"/issue/~a/comment"
477 (number->string id
)))
478 (enctype "multipart/form-data")
480 (input (@ (style "display:none")
482 (placeholder "Please leave this empty.")) "")
483 (input (@ (type "hidden")
485 (value ,(timestamp!))) "")
487 (@ (class "card-header"))
488 (div (@ (class "from"))
489 (input (@ (class "address form-control")
491 (required "required")
492 (placeholder "Your name")) "")))
494 (@ (class "body card-body"))
495 (textarea (@ (name "text")
496 (required "required")
497 (class "form-control")
498 (placeholder "Please input your comment..."))
501 (@ (class "card-footer"))
502 (button (@ (class "btn btn-primary")
506 (@ (class "card-header"))
507 (div (@ (class "from"))
508 (span (@ (class "address")) "Your comment")))
510 (@ (class "body card-body"))
511 (p "Comments via the web interface are not currently
512 supported. To comment on this conversation "
513 (a (@ (href ,(string-append "mailto:"
514 (number->string id
) "@" (%config
'debbugs-domain
)
515 "?subject=" (bug-subject* bug
))))
516 ,(string-append "send email to "
517 (number->string id
) "@" (%config
'debbugs-domain
)))))))))))
520 (@ (class "info col-lg-3"))
523 ,@(let ((num (length parties
)))
526 (string-append (number->string num
)
529 (ul ,(map (lambda (name)
530 `(li (span (@ (class "name")))
532 (map extract-name parties
)))))))
537 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
541 (dd ,(bug-severity bug
)))
545 (dd ,(status-tag bug
))))))))))
547 (define (list-of-bugs bugs
)
548 "Return table rows for all BUGS."
550 (let ((id (number->string
(bug-num bug
))))
551 `(tr (@ (class ,(bug-severity bug
)))
554 ,@(if (member (bug-severity bug
) '("serious" "important"))
555 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
556 (xmlns:xlink
"http://www.w3.org/1999/xlink")
557 (viewBox "0 0 14 16")
561 (aria-hidden "true"))
562 (title ,(bug-severity bug
))
563 (path (@ (fill-rule "evenodd")
565 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
566 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
567 c0-3.14 2.56-5.7 5.7-5.7z\
568 M7 1C3.14 1 0 4.14 0 8\
569 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
570 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
573 `(a (@ (href ,(string-append "/issue/" id
)))
576 (td ,(date->string
(bug-date bug
)))
577 (td ,(status-tag bug
)))))
580 (define (priority-bugs)
583 (bugs-by-severity "serious" "open")
584 (bugs-by-severity "important" "open"))
585 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
587 (define* (list-of-recent-issues #:optional
(max 100))
590 `(,(header #:search-bar?
#f
)
592 (@ (class "container"))
595 (@ (class "table table-borderless table-hover js-sort-table"))
597 (tr (@ (class "heading"))
598 (th (@ (class "js-sort-number")) "ID")
600 (th "Date submitted")
603 ,@(list-of-bugs (recent-bugs max
))))))))
605 (define (list-of-matching-bugs query bugs
)
608 `(,(header #:search-bar?
#f
)
610 (@ (class "container"))
611 (h1 "Your search for " (code ,query
))
612 ,(search-widget #:text query
)
615 (@ (class "alert alert-warning")
618 (@ (class "alert-heading"))
620 (p "We could not find any issues matching your query "
623 "Try searching for something else?")))
625 (@ (class "table table-borderless table-hover js-sort-table"))
627 (tr (@ (class "heading"))
628 (th (@ (class "js-sort-number")) "ID")
630 (th "Date submitted")
633 ,@(list-of-bugs bugs
))))))))