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") ".")))))
88 #:extra-headers
,extra-headers
))
90 (define* (search-form #:key
(standalone?
#f
) (text ""))
91 `(form (@ (id "search")
94 '(class "form-inline"))
97 (@ (class ,(if standalone?
98 "input-group input-group-lg"
100 (input (@ (type "text")
101 (class "form-control")
105 (placeholder "Input your search query...")))
106 (span (@ (class "input-group-append"))
109 (class ,(string-append (if standalone?
"btn-lg " "")
111 ;; This SVG is part of Bootstrap and is available
112 ;; under the Expat license.
114 (@ (class "bi bi-search")
117 (viewBox "0 0 16 16")
118 (fill "currentColor")
119 (xmlns "http://www.w3.org/2000/svg"))
121 (path (@ (fill-rule "evenodd")
122 (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")
123 (clip-rule "evenodd")) "")
124 (path (@ (fill-rule "evenodd")
125 (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")
126 (clip-rule "evenodd")) "")))))))
129 (define* (search-widget #:key
(text ""))
131 (@ (class "card mb-3"))
132 (div (@ (class "card-body bg-light"))
133 ,(search-form #:standalone?
#t
#:text text
)
135 (summary (strong "Hint"))
137 "Refine your search with filters like "
138 (span (@ (class "filter"))
141 (span (@ (class "filter"))
144 (span (@ (class "filter"))
147 (span (@ (class "filter"))
150 (span (@ (class "filter"))
151 "date:2018-04-01..2018-04-02")
153 (span (@ (class "filter"))
156 (a (@ (href "help#search"))
159 (define* (header #:key
(search-bar?
#t
))
161 (@ (class "navbar navbar-expand navbar-light bg-light"))
162 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
163 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
171 '((cache-control .
((max-age .
60))))
173 `(,(header #:search-bar?
#f
)
175 (@ (class "container"))
176 (h1 "Guix issue tracker")
177 (p (@ (class "lead"))
178 "This is a web frontend to the Guix patch and bug trackers. Send email to "
179 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
180 ,(%config
'submission-email-address
))
181 " to submit a patch, or email "
182 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
183 ,(%config
'submission-bug-email-address
))
184 " to submit a bug report.")
188 (@ (class "table table-borderless table-hover"))
190 (tr (@ (class "h3")) (th (@ (colspan 4)) "Recent activity")))
192 (tr (@ (class "heading"))
195 (th "Date submitted")
197 ,@(list-of-bugs (recent-bugs 10)))
199 (tr (@ (class "h3")) (th (@ (colspan 4)) "Priority bugs")))
201 (tr (@ (class "heading"))
204 (th "Date submitted")
206 ,@(priority-bugs)))))))
211 ;; Cache for 24 hours.
212 '((cache-control .
((max-age .
86400))))
214 `(,(header #:search-bar?
#f
)
216 (@ (class "container"))
218 (a (@ (href "search")))
219 (p "You can improve the search results by making use of the
220 simple query language. Here is a list of supported query terms with
226 (th (@ (class "col-md-3")) "Filter")
227 (th (@ (class "col-md-9")) "Description")))
230 (td (span (@ (class "filter")) "is:open") ", "
231 (span (@ (class "filter")) "is:pending"))
234 (td (span (@ (class "filter")) "is:closed") ", "
235 (span (@ (class "filter")) "is:done"))
236 (td "Issues marked as done."))
238 (td (span (@ (class "filter")) "submitter:<who>"))
239 (td "Issues submitted by a person named " (strong "who")
241 (span (@ (class "filter")) "submitter:ludo")
242 " for all issues submitted by ludo. "
243 "The filter matches both the email address and the name."))
245 (td (span (@ (class "filter")) "author:<who>"))
246 (td "Issues where a person named " (strong "who")
247 " has commented, e.g. "
248 (span (@ (class "filter")) "author:rekado")
249 " for all messages where rekado has commented. "
250 "The filter matches both the email address and the name."))
252 (td (span (@ (class "filter")) "date:<start>..<end>"))
253 (td "Issues or comments submitted within the provided range. "
254 (strong "start") " and " (strong "end") " can be one of "
255 (strong "now") ", " (strong "today")
256 ", a date in the formats "
257 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
258 ", or an amount and a unit for a point in the past, such as "
259 (strong "12d..") " for 12 days ago. "
260 "Supported units are: "
261 (strong "h") " (hours), "
262 (strong "d") " (days), "
263 (strong "w") " (weeks), "
264 (strong "m") " (months), and "
265 (strong "y") " (years)."))))))))
271 (div (@ (class "container"))
272 (h1 "Patch not found")
273 (p "There is no submission with id " (strong ,id
))
274 (p (a (@ (href "/")) "Try another one?"))))))
276 (define (error-page message
)
280 (div (@ (class "container"))
282 (p "An error occurred. Sorry about that!")
284 (p (a (@ (href "/")) "Try something else?"))))))
286 (define (issue-page bug
)
287 "Render the conversation for the given BUG."
288 (define id
(bug-num bug
))
289 (define messages
(patch-messages id
))
290 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
291 (participants (filter identity messages
)))
293 (string< (extract-email a
)
294 (extract-email b
)))))
295 (define (show-message message-number message previous-subject
)
296 `((div (@ (class "mb-5"))
297 (a (@ (id ,(number->string message-number
))))
300 (style ,(string-append "background-color:"
301 (avatar-color (sender-email message
)
302 (map extract-email parties
)))))
303 ,(string-upcase (string-take (sender-name message
) 1)))
305 (@ (class "message"))
309 (@ (class "card-header"))
314 (style ,(string-append "background-color:"
315 (avatar-color (sender-email message
)
316 (map extract-email parties
)))))
317 ,(string-upcase (string-take (sender-name message
) 1)))
318 (span (@ (class "address")) ,(sender-name message
))
320 (span (@ (class "date"))
321 (a (@ (href ,(string-append "#" (number->string
323 ,(date->string
(date message
)))))
324 ,@(if (string-suffix? previous-subject
(subject message
))
326 `((div (@ (class "subject")) ,(subject message
))))
328 (@ (class "details"))
330 (@ (class "recipients"))
331 (label "Recipients:")
332 ,(map (lambda (address)
333 `(span (@ (class "address")) ,address
))
334 (recipients message
)))
336 (@ (class "message-id"))
337 (label "Message-ID:")
338 ,(message-id message
))))
340 (@ (class "body card-body"))
341 ,(display-message-body id message-number message
)))))
342 ,@(if (closing? message id
)
344 (@ (class "row event"))
346 (@ (class "col-md-11 offset-md-1 text-center"))
347 (div (@ (class "badge badge-primary closed")) "Closed"))))
350 #:title
(bug-subject* bug
)
354 ;; Tell browser to cache this for 12 hours.
355 '((cache-control .
((max-age .
43200)))))
357 ;; Tell browser to cache this for 1 hour.
358 '((cache-control .
((max-age .
3600)))))
363 (@ (class "container"))
365 (@ (class "title col-md-12"))
366 (h1 ,(bug-subject* bug
))
367 (span (@ (class "details"))
369 ,(string-append "Submitted by "
370 ;; We don't use bug-originator here
371 ;; because it includes the email address.
372 ;; We cannot use extract-name on the
373 ;; return value, because it swallows
374 ;; non-ASCII characters.
375 (sender-name (first messages
))
377 ,@(if (bug-mergedwith bug
)
378 `((ul (@ (class "merged"))
381 `(li (a (@ (href ,(string-append "/issue/" id
)))
383 ;; XXX: This field can either hold a
384 ;; string of multiple ids, or a single
385 ;; number. Deal with this mess.
386 (match (bug-mergedwith bug
)
388 (string-split str
#\space
))
390 (list (number->string n
)))))))
392 ,@(if (bug-blocks bug
)
393 `((ul (@ (class "blocks"))
396 `(li (a (@ (href ,(string-append "/issue/" id
)))
398 ;; XXX: This field can either hold a
399 ;; string of multiple ids, or a single
400 ;; number. Deal with this mess.
401 (match (bug-blocks bug
)
403 (string-split str
#\space
))
405 (list (number->string n
)))))))
407 ,@(if (bug-blockedby bug
)
408 `((ul (@ (class "blockedby"))
411 `(li (a (@ (href ,(string-append "/issue/" id
)))
413 ;; XXX: This field can either hold a
414 ;; string of multiple ids, or a single
415 ;; number. Deal with this mess.
416 (match (bug-blockedby bug
)
418 (string-split str
#\space
))
420 (list (number->string n
)))))))
422 (div (@ (class "row"))
424 (@ (class "conversation col-md"))
425 ,(let ((msgs (filter (lambda (msg)
428 ;; internal messages.
431 (not (internal-message? msg
))))
433 (map (lambda (message-number msg previous-subject
)
434 (show-message message-number msg previous-subject
))
437 (cons (bug-subject* bug
)
438 (map subject msgs
))))
440 (@ (class "comment-box"))
441 (a (@ (id "comment")))
444 (style "background-color:#bc80bd")) "?")
446 (@ (class "message"))
450 (@ (class "card-header"))
451 (div (@ (class "from"))
452 (span (@ (class "address")) "Your comment")))
454 (@ (class "body card-body"))
455 (p "Comments via the web interface are not currently
456 supported. To comment on this conversation "
457 (a (@ (href ,(string-append "mailto:"
458 (number->string id
) "@" (%config
'debbugs-domain
)
459 "?subject=" (bug-subject* bug
))))
460 ,(string-append "send email to "
461 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
464 (@ (class "info col-md-3"))
467 ,@(let ((num (length parties
)))
470 (string-append (number->string num
)
473 (ul ,(map (lambda (name)
474 `(li (span (@ (class "name")))
476 (map extract-name parties
)))))))
481 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
485 (dd ,(bug-severity bug
)))
489 (dd ,(status-tag bug
)))))))))
491 (define (list-of-bugs bugs
)
492 "Return table rows for all BUGS."
494 (let ((id (number->string
(bug-num bug
))))
495 `(tr (@ (class ,(bug-severity bug
)))
498 ,@(if (member (bug-severity bug
) '("serious" "important"))
499 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
500 (xmlns:xlink
"http://www.w3.org/1999/xlink")
501 (viewBox "0 0 14 16")
505 (aria-hidden "true"))
506 (title ,(bug-severity bug
))
507 (path (@ (fill-rule "evenodd")
509 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
510 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
511 c0-3.14 2.56-5.7 5.7-5.7z\
512 M7 1C3.14 1 0 4.14 0 8\
513 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
514 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
517 `(a (@ (href ,(string-append "/issue/" id
)))
520 (td ,(date->string
(bug-date bug
)))
521 (td ,(status-tag bug
)))))
524 (define (priority-bugs)
527 (bugs-by-severity "serious" "open")
528 (bugs-by-severity "important" "open"))
529 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
531 (define (list-of-matching-bugs query bugs
)
535 (div (@ (class "container"))
537 `((h1 "No issues found")
538 (p "We could not find any issues matching your query "
541 "Try searching for something else?")))
542 `((h1 "Submissions matching " (code ,query
))
543 (table (@ (class "table table-condensed table-sm table-hover"))
547 (th "Date submitted")
550 ,@(list-of-bugs bugs
)))))))))