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 "
189 (small (a (@ (href "recent")) "(More)")))
191 (@ (class "table table-borderless table-hover js-sort-table"))
193 (tr (@ (class "heading"))
194 (th (@ (class "js-sort-number")) "ID")
196 (th "Date submitted")
199 ,@(list-of-bugs (recent-bugs 10))))
201 (div (@ (class "mt-4 h4")) "Priority bugs")
203 (@ (class "table table-borderless table-hover js-sort-table"))
205 (tr (@ (class "heading"))
206 (th (@ (class "js-sort-number")) "ID")
208 (th "Date submitted")
211 ,@(priority-bugs)))))))
216 `(,(header #:search-bar?
#f
)
218 (@ (class "container"))
220 (a (@ (href "search")))
221 (p "You can improve the search results by making use of the
222 simple query language. Here is a list of supported query terms with
228 (th (@ (class "col-md-3")) "Filter")
229 (th (@ (class "col-md-9")) "Description")))
232 (td (span (@ (class "filter")) "is:open") ", "
233 (span (@ (class "filter")) "is:pending"))
236 (td (span (@ (class "filter")) "is:closed") ", "
237 (span (@ (class "filter")) "is:done"))
238 (td "Issues marked as done."))
240 (td (span (@ (class "filter")) "submitter:<who>"))
241 (td "Issues submitted by a person named " (strong "who")
243 (span (@ (class "filter")) "submitter:ludo")
244 " for all issues submitted by ludo. "
245 "The filter matches both the email address and the name."))
247 (td (span (@ (class "filter")) "author:<who>"))
248 (td "Issues where a person named " (strong "who")
249 " has commented, e.g. "
250 (span (@ (class "filter")) "author:rekado")
251 " for all messages where rekado has commented. "
252 "The filter matches both the email address and the name."))
254 (td (span (@ (class "filter")) "date:<start>..<end>"))
255 (td "Issues submitted within the provided range. "
256 (strong "start") " and " (strong "end") " can be one of "
257 (strong "now") ", " (strong "today")
258 ", a date in the formats "
259 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
260 ", or an amount and a unit for a point in the past, such as "
261 (strong "12d..") " for 12 days ago. "
262 "Supported units are: "
263 (strong "h") " (hours), "
264 (strong "d") " (days), "
265 (strong "w") " (weeks), "
266 (strong "m") " (months), and "
267 (strong "y") " (years)."))
269 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
270 (td "This is just like " (span (@ (class "filter")) "date")
271 " except that it also includes comments."))))))))
277 (div (@ (class "container"))
278 (h1 "Issue not found")
279 (p "There is no submission with id " (strong ,id
) ", or we
280 failed to process associated messages.")
281 (p (a (@ (href "/")) "Try another one?"))))))
283 (define (error-page message
)
287 (div (@ (class "container"))
289 (p "An error occurred. Sorry about that!")
291 (p (a (@ (href "/")) "Try something else?"))))))
293 (define* (issue-page bug
#:optional flash-message
)
294 "Render the conversation for the given BUG."
295 (define id
(bug-num bug
))
296 (define messages
(patch-messages id
))
297 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
298 (participants (filter identity messages
)))
300 (string< (extract-email a
)
301 (extract-email b
)))))
302 (define (show-message message-number message previous-subject
)
303 `((div (@ (class "mb-5"))
304 (a (@ (id ,(number->string message-number
))))
307 (style ,(string-append "background-color:"
308 (avatar-color (sender-email message
)
309 (map extract-email parties
)))))
310 ,(string-upcase (string-take (sender-name message
) 1)))
312 (@ (class "message"))
316 (@ (class "card-header"))
321 (style ,(string-append "background-color:"
322 (avatar-color (sender-email message
)
323 (map extract-email parties
)))))
324 ,(string-upcase (string-take (sender-name message
) 1)))
325 (span (@ (class "address")) ,(sender-name message
))
327 (span (@ (class "date"))
328 (a (@ (href ,(string-append "#" (number->string
330 ,(date->string
(date message
)))))
331 ,@(if (string-suffix? previous-subject
(subject message
))
333 `((div (@ (class "subject")) ,(subject message
))))
335 (@ (class "details"))
337 (@ (class "recipients"))
338 (label "Recipients:")
339 ,(map (lambda (address)
340 `(span (@ (class "address")) ,address
))
341 (recipients message
)))
343 (@ (class "message-id"))
344 (label "Message-ID:")
345 ,(message-id message
))))
347 (@ (class "body card-body"))
348 ,(display-message-body id message-number message
)))))
349 ,@(if (closing? message id
)
351 (@ (class "row event"))
353 (@ (class "col-11 offset-1 text-center"))
354 (div (@ (class "badge badge-primary closed")) "Closed"))))
356 (if (null? messages
) #f
358 #:title
(bug-subject* bug
)
362 (@ (class "container"))
363 ,@(match flash-message
365 `((div (@ (class "alert alert-danger")
369 `((div (@ (class "alert alert-info")
374 (@ (class "title col-12"))
375 (h1 ,(bug-subject* bug
))
376 (span (@ (class "details"))
378 ,(string-append "Submitted by "
379 ;; We don't use bug-originator here
380 ;; because it includes the email address.
381 ;; We cannot use extract-name on the
382 ;; return value, because it swallows
383 ;; non-ASCII characters.
384 (sender-name (first messages
))
386 ,@(if (bug-mergedwith bug
)
387 `((ul (@ (class "merged"))
390 `(li (a (@ (href ,(string-append "/issue/" id
)))
392 ;; XXX: This field can either hold a
393 ;; string of multiple ids, or a single
394 ;; number. Deal with this mess.
395 (match (bug-mergedwith bug
)
397 (string-split str
#\space
))
399 (list (number->string n
)))))))
401 ,@(if (bug-blocks bug
)
402 `((ul (@ (class "blocks"))
405 `(li (a (@ (href ,(string-append "/issue/" id
)))
407 ;; XXX: This field can either hold a
408 ;; string of multiple ids, or a single
409 ;; number. Deal with this mess.
410 (match (bug-blocks bug
)
412 (string-split str
#\space
))
414 (list (number->string n
)))))))
416 ,@(if (bug-blockedby bug
)
417 `((ul (@ (class "blockedby"))
420 `(li (a (@ (href ,(string-append "/issue/" id
)))
422 ;; XXX: This field can either hold a
423 ;; string of multiple ids, or a single
424 ;; number. Deal with this mess.
425 (match (bug-blockedby bug
)
427 (string-split str
#\space
))
429 (list (number->string n
)))))))
431 (div (@ (class "row"))
433 (@ (class "conversation col-lg-9"))
434 ,(let ((msgs (filter (lambda (msg)
437 ;; internal messages.
440 (not (internal-message? msg
))))
442 (map (lambda (message-number msg previous-subject
)
443 (show-message message-number msg previous-subject
))
446 (cons (bug-subject* bug
)
447 (map subject msgs
))))
449 (@ (class "comment-box"))
450 (a (@ (id "comment")))
453 (style "background-color:#bc80bd")) "?")
455 (@ (class "message"))
458 ,@(if (mailer-enabled?
)
460 (@ (action ,(format #f
"/issue/~a/comment"
461 (number->string id
)))
462 (enctype "multipart/form-data")
464 (input (@ (style "display:none")
466 (placeholder "Please leave this empty.")) "")
467 (input (@ (type "hidden")
469 (value ,(timestamp!))) "")
471 (@ (class "card-header"))
472 (div (@ (class "from"))
473 (input (@ (class "address form-control")
475 (required "required")
476 (placeholder "Your name")) "")))
478 (@ (class "body card-body"))
479 (textarea (@ (name "text")
480 (required "required")
481 (class "form-control")
482 (placeholder "Please input your comment..."))
485 (@ (class "card-footer"))
486 (button (@ (class "btn btn-primary")
490 (@ (class "card-header"))
491 (div (@ (class "from"))
492 (span (@ (class "address")) "Your comment")))
494 (@ (class "body card-body"))
495 (p "Comments via the web interface are not currently
496 supported. To comment on this conversation "
497 (a (@ (href ,(string-append "mailto:"
498 (number->string id
) "@" (%config
'debbugs-domain
)
499 "?subject=" (bug-subject* bug
))))
500 ,(string-append "send email to "
501 (number->string id
) "@" (%config
'debbugs-domain
)))))))))))
504 (@ (class "info col-lg-3"))
507 ,@(let ((num (length parties
)))
510 (string-append (number->string num
)
513 (ul ,(map (lambda (name)
514 `(li (span (@ (class "name")))
516 (map extract-name parties
)))))))
521 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
525 (dd ,(bug-severity bug
)))
529 (dd ,(status-tag bug
))))))))))
531 (define (list-of-bugs bugs
)
532 "Return table rows for all BUGS."
534 (let ((id (number->string
(bug-num bug
))))
535 `(tr (@ (class ,(bug-severity bug
)))
538 ,@(if (member (bug-severity bug
) '("serious" "important"))
539 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
540 (xmlns:xlink
"http://www.w3.org/1999/xlink")
541 (viewBox "0 0 14 16")
545 (aria-hidden "true"))
546 (title ,(bug-severity bug
))
547 (path (@ (fill-rule "evenodd")
549 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
550 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
551 c0-3.14 2.56-5.7 5.7-5.7z\
552 M7 1C3.14 1 0 4.14 0 8\
553 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
554 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
557 `(a (@ (href ,(string-append "/issue/" id
)))
560 (td ,(date->string
(bug-date bug
)))
561 (td ,(status-tag bug
)))))
564 (define (priority-bugs)
567 (bugs-by-severity "serious" "open")
568 (bugs-by-severity "important" "open"))
569 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
571 (define* (list-of-recent-issues #:optional
(max 100))
574 `(,(header #:search-bar?
#f
)
576 (@ (class "container"))
579 (@ (class "table table-borderless table-hover js-sort-table"))
581 (tr (@ (class "heading"))
582 (th (@ (class "js-sort-number")) "ID")
584 (th "Date submitted")
587 ,@(list-of-bugs (recent-bugs max
))))))))
589 (define (list-of-matching-bugs query bugs
)
592 `(,(header #:search-bar?
#f
)
594 (@ (class "container"))
595 (h1 "Your search for " (code ,query
))
596 ,(search-widget #:text query
)
599 (@ (class "alert alert-warning")
602 (@ (class "alert-heading"))
604 (p "We could not find any issues matching your query "
607 "Try searching for something else?")))
609 (@ (class "table table-borderless table-hover js-sort-table"))
611 (tr (@ (class "heading"))
612 (th (@ (class "js-sort-number")) "ID")
614 (th "Date submitted")
617 ,@(list-of-bugs bugs
))))))))