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 (@ (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 (@ (src "/js/sort-table.js")))))))
91 (define* (search-form #:key
(standalone?
#f
) (text ""))
92 `(form (@ (id "search")
95 '(class "form-inline"))
98 (@ (class ,(if standalone?
99 "input-group input-group-lg"
101 (input (@ (type "text")
102 (class "form-control")
106 (placeholder "Input your search query...")))
107 (span (@ (class "input-group-append"))
110 (class ,(string-append (if standalone?
"btn-lg " "")
112 ;; This SVG is part of Bootstrap and is available
113 ;; under the Expat license.
115 (@ (class "bi bi-search")
118 (viewBox "0 0 16 16")
119 (fill "currentColor")
120 (xmlns "http://www.w3.org/2000/svg"))
122 (path (@ (fill-rule "evenodd")
123 (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")
124 (clip-rule "evenodd")) "")
125 (path (@ (fill-rule "evenodd")
126 (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")
127 (clip-rule "evenodd")) ""))))
129 (@ (id "search-hints"))
130 (p "You can improve the search results by making use of the
131 simple query language. Here is a list of supported query terms:")
133 (@ (class "table table-sm table-borderless"))
137 `(tr (td (span (@ (class "filter")) ,term
))
139 '(("is:open" "open issues")
140 ("is:done" "closed issues")
141 ("submitter:<who>" "search issue submitter")
142 ("author:<who>" "search by message author")
143 ("date:yesterday..now" "search by issue date")
144 ("mdate:3m..2d" "search by message date")))))))))
146 (define* (search-widget #:key
(text ""))
148 (@ (class "card mb-3"))
149 (div (@ (class "card-body bg-light"))
150 ,(search-form #:standalone?
#t
#:text text
)
152 (summary (strong "Hint"))
154 "Refine your search with filters like "
155 (span (@ (class "filter"))
158 (span (@ (class "filter"))
161 (span (@ (class "filter"))
164 (span (@ (class "filter"))
167 (span (@ (class "filter"))
168 "date:2018-04-01..2018-04-02")
170 (span (@ (class "filter"))
173 (a (@ (href "help#search"))
176 (define* (header #:key
(search-bar?
#t
) title
)
178 (@ (class "sticky-top navbar navbar-expand navbar-light bg-light"))
179 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
180 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
182 `((span (@ (class "navbar-text")) ,title
))
191 `(,(header #:search-bar?
#f
)
193 (@ (class "container"))
194 (h1 "Guix issue tracker")
195 (p (@ (class "lead"))
196 "This is a web frontend to the Guix patch and bug trackers. Send email to "
197 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
198 ,(%config
'submission-email-address
))
199 " to submit a patch, or email "
200 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
201 ,(%config
'submission-bug-email-address
))
202 " to submit a bug report.")
205 (div (@ (class "mt-4 h4")) "Recent activity "
206 (small (a (@ (href "recent")) "(More)")))
208 (@ (class "table table-borderless table-hover js-sort-table"))
210 (tr (@ (class "heading"))
211 (th (@ (class "js-sort-number")) "ID")
213 (th "Date submitted")
216 ,@(list-of-bugs (recent-bugs 10))))
218 (div (@ (class "mt-4 h4")) "Priority bugs")
220 (@ (class "table table-borderless table-hover js-sort-table"))
222 (tr (@ (class "heading"))
223 (th (@ (class "js-sort-number")) "ID")
225 (th "Date submitted")
228 ,@(priority-bugs)))))))
233 `(,(header #:search-bar?
#f
)
235 (@ (class "container"))
237 (a (@ (href "search")))
238 (p "You can improve the search results by making use of the
239 simple query language. Here is a list of supported query terms with
245 (th (@ (class "col-md-3")) "Filter")
246 (th (@ (class "col-md-9")) "Description")))
249 (td (span (@ (class "filter")) "is:open") ", "
250 (span (@ (class "filter")) "is:pending"))
253 (td (span (@ (class "filter")) "is:closed") ", "
254 (span (@ (class "filter")) "is:done"))
255 (td "Issues marked as done."))
257 (td (span (@ (class "filter")) "submitter:<who>"))
258 (td "Issues submitted by a person named " (strong "who")
260 (span (@ (class "filter")) "submitter:ludo")
261 " for all issues submitted by ludo. "
262 "The filter matches both the email address and the name."))
264 (td (span (@ (class "filter")) "author:<who>"))
265 (td "Issues where a person named " (strong "who")
266 " has commented, e.g. "
267 (span (@ (class "filter")) "author:rekado")
268 " for all messages where rekado has commented. "
269 "The filter matches both the email address and the name."))
271 (td (span (@ (class "filter")) "date:<start>..<end>"))
272 (td "Issues submitted within the provided range. "
273 (strong "start") " and " (strong "end") " can be one of "
274 (strong "now") ", " (strong "today")
275 ", a date in the formats "
276 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
277 ", or an amount and a unit for a point in the past, such as "
278 (strong "12d..") " for 12 days ago. "
279 "Supported units are: "
280 (strong "h") " (hours), "
281 (strong "d") " (days), "
282 (strong "w") " (weeks), "
283 (strong "m") " (months), and "
284 (strong "y") " (years)."))
286 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
287 (td "This is just like " (span (@ (class "filter")) "date")
288 " except that it also includes comments."))))))))
294 (div (@ (class "container"))
295 (h1 "Issue not found")
296 (p "There is no submission with id " (strong ,id
) ", or we
297 failed to process associated messages.")
298 (p (a (@ (href "/")) "Try another one?"))))))
300 (define (error-page message
)
304 (div (@ (class "container"))
306 (p "An error occurred. Sorry about that!")
308 (p (a (@ (href "/")) "Try something else?"))))))
310 (define* (issue-page bug
#:optional flash-message
)
311 "Render the conversation for the given BUG."
312 (define id
(bug-num bug
))
313 (define messages
(issue-messages id
))
314 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
315 (participants (filter identity messages
)))
317 (string< (extract-email a
)
318 (extract-email b
)))))
319 (define (show-message message-number message previous-subject
)
320 `((div (@ (class "mb-5"))
321 (a (@ (id ,(number->string message-number
))))
324 (style ,(string-append "background-color:"
325 (avatar-color (sender-email message
)
326 (map extract-email parties
)))))
327 ,(string-upcase (string-take (sender-name message
) 1)))
329 (@ (class "message"))
333 (@ (class "card-header"))
338 (style ,(string-append "background-color:"
339 (avatar-color (sender-email message
)
340 (map extract-email parties
)))))
341 ,(string-upcase (string-take (sender-name message
) 1)))
342 (span (@ (class "address")) ,(sender-name message
))
344 (span (@ (class "date"))
345 (a (@ (href ,(string-append "#" (number->string
347 ,(date->string
(date message
)))))
348 ,@(if (string-suffix? previous-subject
(subject message
))
350 `((div (@ (class "subject")) ,(subject message
))))
352 (@ (class "details"))
354 (@ (class "recipients"))
355 (label "Recipients:")
356 ,(map (lambda (address)
357 `(span (@ (class "address")) ,address
))
358 (recipients message
)))
360 (@ (class "message-id"))
361 (label "Message-ID:")
362 ,(message-id message
))))
364 (@ (class "body card-body"))
365 ,(display-message-body id message-number message
)))))
366 ,@(if (closing? message id
)
368 (@ (class "row event"))
370 (@ (class "col-11 offset-1 text-center"))
371 (div (@ (class "badge badge-primary closed")) "Closed"))))
373 (if (null? messages
) #f
375 #:title
(bug-subject* bug
)
377 `(,(header #:title
(bug-subject* bug
))
379 (@ (class "container"))
380 ,@(match flash-message
382 `((div (@ (class "alert alert-danger")
386 `((div (@ (class "alert alert-info")
391 (@ (class "title col-12"))
392 (h1 ,(bug-subject* bug
))
393 (span (@ (class "details"))
395 ,(string-append "Submitted by "
396 ;; We don't use bug-originator here
397 ;; because it includes the email address.
398 ;; We cannot use extract-name on the
399 ;; return value, because it swallows
400 ;; non-ASCII characters.
401 (sender-name (first messages
))
408 ,@(let ((num (length parties
)))
411 (string-append (number->string num
)
414 (ul ,(map (lambda (name)
415 `(li (span (@ (class "name")))
417 (map extract-name parties
)))))))
422 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
426 (dd ,(bug-severity bug
)))
427 ,@(if (bug-mergedwith bug
)
431 (dd (ul ,(map (lambda (id)
432 `(li (a (@ (href ,(string-append "/" id
)))
434 ;; XXX: This field can either hold a
435 ;; string of multiple ids, or a single
436 ;; number. Deal with this mess.
437 (match (bug-mergedwith bug
)
439 (string-split str
#\space
))
441 (list (number->string n
)))))))))
443 ,@(if (bug-blocks bug
)
447 (dd (ul ,(map (lambda (id)
448 `(li (a (@ (href ,(string-append "/" id
)))
450 ;; XXX: This field can either hold a
451 ;; string of multiple ids, or a single
452 ;; number. Deal with this mess.
453 (match (bug-blocks bug
)
455 (string-split str
#\space
))
457 (list (number->string n
)))))))))
459 ,@(if (bug-blockedby bug
)
463 (dd (ul ,(map (lambda (id)
464 `(li (a (@ (href ,(string-append "/" id
)))
466 ;; XXX: This field can either hold a
467 ;; string of multiple ids, or a single
468 ;; number. Deal with this mess.
469 (match (bug-blockedby bug
)
471 (string-split str
#\space
))
473 (list (number->string n
)))))))))
475 (div (@ (class "row"))
477 (@ (class "conversation col-12"))
478 ,(let ((msgs (filter (lambda (msg)
481 ;; internal messages.
484 (not (internal-message? msg
))))
486 (map (lambda (message-number msg previous-subject
)
487 (show-message message-number msg previous-subject
))
490 (cons (bug-subject* bug
)
491 (map subject msgs
))))
493 (@ (class "comment-box"))
494 (a (@ (id "comment")))
497 (style "background-color:#bc80bd")) "?")
499 (@ (class "message"))
502 ,@(if (mailer-enabled?
)
504 (@ (action ,(format #f
"/issue/~a/comment"
505 (number->string id
)))
506 (enctype "multipart/form-data")
508 (input (@ (style "display:none")
510 (placeholder "Please leave this empty.")) "")
511 (input (@ (type "hidden")
513 (value ,(timestamp!))) "")
515 (@ (class "card-header"))
516 (div (@ (class "from"))
517 (input (@ (class "address form-control")
519 (required "required")
520 (placeholder "Your name")) "")))
522 (@ (class "body card-body"))
523 (textarea (@ (name "text")
524 (required "required")
525 (class "form-control")
526 (placeholder "Please input your comment..."))
529 (@ (class "card-footer"))
530 (button (@ (class "btn btn-primary")
534 (@ (class "card-header"))
535 (div (@ (class "from"))
536 (span (@ (class "address")) "Your comment")))
538 (@ (class "body card-body"))
539 (p "Comments via the web interface are not currently
540 supported. To comment on this conversation "
541 (a (@ (href ,(string-append "mailto:"
542 (number->string id
) "@" (%config
'debbugs-domain
)
543 "?subject=" (bug-subject* bug
))))
544 ,(string-append "send email to "
545 (number->string id
) "@" (%config
'debbugs-domain
)))))))))))))))))
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 "/" 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
))))))))