1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2016, 2017, 2018, 2019 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
))
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")
104 (placeholder "Input your search query...")))
105 (span (@ (class "input-group-append"))
108 (class ,(string-append (if standalone?
"btn-lg " "")
110 ;; This SVG is part of Bootstrap and is available
111 ;; under the Expat license.
113 (@ (class "bi bi-search")
116 (viewBox "0 0 16 16")
117 (fill "currentColor")
118 (xmlns "http://www.w3.org/2000/svg"))
120 (path (@ (fill-rule "evenodd")
121 (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")
122 (clip-rule "evenodd")) "")
123 (path (@ (fill-rule "evenodd")
124 (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")
125 (clip-rule "evenodd")) "")))))))
127 (define* (header #:key
(search-bar?
#t
))
129 (@ (class "navbar navbar-expand navbar-light bg-light"))
130 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
131 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
139 '((cache-control .
((max-age .
60))))
141 `(,(header #:search-bar?
#f
)
143 (@ (class "container"))
144 (h1 "Guix issue tracker")
145 (p (@ (class "lead"))
146 "This is a web frontend to the Guix patch and bug trackers. Send email to "
147 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
148 ,(%config
'submission-email-address
))
149 " to submit a patch, or email "
150 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
151 ,(%config
'submission-bug-email-address
))
152 " to submit a bug report.")
155 (div (@ (class "card-body bg-light"))
156 ,(search-form #:standalone?
#t
)
158 (summary (strong "Hint"))
160 "Refine your search with filters like "
161 (span (@ (class "filter"))
164 (span (@ (class "filter"))
167 (span (@ (class "filter"))
170 (span (@ (class "filter"))
173 (span (@ (class "filter"))
174 "date:2018-04-01..2018-04-02")
176 (span (@ (class "filter"))
179 (a (@ (href "help#search"))
183 (@ (class "table table-borderless table-hover"))
185 (tr (@ (class "h3")) (th (@ (colspan 4)) "Recent activity")))
187 (tr (@ (class "heading"))
190 (th "Date submitted")
192 ,@(list-of-bugs (recent-bugs 10)))
194 (tr (@ (class "h3")) (th (@ (colspan 4)) "Priority bugs")))
196 (tr (@ (class "heading"))
199 (th "Date submitted")
201 ,@(priority-bugs)))))))
206 ;; Cache for 24 hours.
207 '((cache-control .
((max-age .
86400))))
209 `(,(header #:search-bar?
#f
)
211 (@ (class "container"))
213 (a (@ (href "search")))
214 (p "You can improve the search results by making use of the
215 simple query language. Here is a list of supported query terms with
221 (th (@ (class "col-md-3")) "Filter")
222 (th (@ (class "col-md-9")) "Description")))
225 (td (span (@ (class "filter")) "is:open") ", "
226 (span (@ (class "filter")) "is:pending"))
229 (td (span (@ (class "filter")) "is:closed") ", "
230 (span (@ (class "filter")) "is:done"))
231 (td "Issues marked as done."))
233 (td (span (@ (class "filter")) "submitter:<who>"))
234 (td "Issues submitted by a person named " (strong "who")
236 (span (@ (class "filter")) "submitter:ludo")
237 " for all issues submitted by ludo. "
238 "The filter matches both the email address and the name."))
240 (td (span (@ (class "filter")) "author:<who>"))
241 (td "Issues where a person named " (strong "who")
242 " has commented, e.g. "
243 (span (@ (class "filter")) "author:rekado")
244 " for all messages where rekado has commented. "
245 "The filter matches both the email address and the name."))
247 (td (span (@ (class "filter")) "date:<start>..<end>"))
248 (td "Issues or comments submitted within the provided range. "
249 (strong "start") " and " (strong "end") " can be one of "
250 (strong "now") ", " (strong "today")
251 ", a date in the formats "
252 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
253 ", or an amount and a unit for a point in the past, such as "
254 (strong "12d..") " for 12 days ago. "
255 "Supported units are: "
256 (strong "h") " (hours), "
257 (strong "d") " (days), "
258 (strong "w") " (weeks), "
259 (strong "m") " (months), and "
260 (strong "y") " (years)."))))))))
266 (div (@ (class "container"))
267 (h1 "Patch not found")
268 (p "There is no submission with id " (strong ,id
))
269 (p (a (@ (href "/")) "Try another one?"))))))
271 (define (error-page message
)
275 (div (@ (class "container"))
277 (p "An error occurred. Sorry about that!")
279 (p (a (@ (href "/")) "Try something else?"))))))
281 (define (issue-page bug
)
282 "Render the conversation for the given BUG."
283 (define id
(bug-num bug
))
284 (define messages
(patch-messages id
))
285 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
286 (participants (filter identity messages
)))
288 (string< (extract-email a
)
289 (extract-email b
)))))
290 (define (show-message message-number message previous-subject
)
291 `((div (@ (class "mb-5"))
292 (a (@ (id ,(number->string message-number
))))
295 (style ,(string-append "background-color:"
296 (avatar-color (sender-email message
)
297 (map extract-email parties
)))))
298 ,(string-upcase (string-take (sender-name message
) 1)))
300 (@ (class "message"))
304 (@ (class "card-header"))
309 (style ,(string-append "background-color:"
310 (avatar-color (sender-email message
)
311 (map extract-email parties
)))))
312 ,(string-upcase (string-take (sender-name message
) 1)))
313 (span (@ (class "address")) ,(sender-name message
))
315 (span (@ (class "date"))
316 (a (@ (href ,(string-append "#" (number->string
318 ,(date->string
(date message
)))))
319 ,@(if (string-suffix? previous-subject
(subject message
))
321 `((div (@ (class "subject")) ,(subject message
))))
323 (@ (class "details"))
325 (@ (class "recipients"))
326 (label "Recipients:")
327 ,(map (lambda (address)
328 `(span (@ (class "address")) ,address
))
329 (recipients message
)))
331 (@ (class "message-id"))
332 (label "Message-ID:")
333 ,(message-id message
))))
335 (@ (class "body card-body"))
336 ,(display-message-body id message-number message
)))))
337 ,@(if (closing? message id
)
339 (@ (class "row event"))
341 (@ (class "col-md-11 offset-md-1 text-center"))
342 (div (@ (class "badge badge-primary closed")) "Closed"))))
345 #:title
(bug-subject* bug
)
349 ;; Tell browser to cache this for 12 hours.
350 '((cache-control .
((max-age .
43200)))))
352 ;; Tell browser to cache this for 1 hour.
353 '((cache-control .
((max-age .
3600)))))
358 (@ (class "container"))
360 (@ (class "title col-md-12"))
361 (h1 ,(bug-subject* bug
))
362 (span (@ (class "details"))
364 ,(string-append "Submitted by "
365 ;; We don't use bug-originator here
366 ;; because it includes the email address.
367 ;; We cannot use extract-name on the
368 ;; return value, because it swallows
369 ;; non-ASCII characters.
370 (sender-name (first messages
))
372 ,@(if (bug-mergedwith bug
)
373 `((ul (@ (class "merged"))
376 `(li (a (@ (href ,(string-append "/issue/" id
)))
378 ;; XXX: This field can either hold a
379 ;; string of multiple ids, or a single
380 ;; number. Deal with this mess.
381 (match (bug-mergedwith bug
)
383 (string-split str
#\space
))
385 (list (number->string n
)))))))
387 ,@(if (bug-blocks bug
)
388 `((ul (@ (class "blocks"))
391 `(li (a (@ (href ,(string-append "/issue/" id
)))
393 ;; XXX: This field can either hold a
394 ;; string of multiple ids, or a single
395 ;; number. Deal with this mess.
396 (match (bug-blocks bug
)
398 (string-split str
#\space
))
400 (list (number->string n
)))))))
402 ,@(if (bug-blockedby bug
)
403 `((ul (@ (class "blockedby"))
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-blockedby bug
)
413 (string-split str
#\space
))
415 (list (number->string n
)))))))
417 (div (@ (class "row"))
419 (@ (class "conversation col-md"))
420 ,(let ((msgs (filter (lambda (msg)
423 ;; internal messages.
426 (not (internal-message? msg
))))
428 (map (lambda (message-number msg previous-subject
)
429 (show-message message-number msg previous-subject
))
432 (cons (bug-subject* bug
)
433 (map subject msgs
))))
435 (@ (class "comment-box"))
436 (a (@ (id "comment")))
439 (style "background-color:#bc80bd")) "?")
441 (@ (class "message"))
445 (@ (class "card-header"))
446 (div (@ (class "from"))
447 (span (@ (class "address")) "Your comment")))
449 (@ (class "body card-body"))
450 (p "Comments via the web interface are not currently
451 supported. To comment on this conversation "
452 (a (@ (href ,(string-append "mailto:"
453 (number->string id
) "@" (%config
'debbugs-domain
)
454 "?subject=" (bug-subject* bug
))))
455 ,(string-append "send email to "
456 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
459 (@ (class "info col-md-3"))
462 ,@(let ((num (length parties
)))
465 (string-append (number->string num
)
468 (ul ,(map (lambda (name)
469 `(li (span (@ (class "name")))
471 (map extract-name parties
)))))))
476 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
480 (dd ,(bug-severity bug
)))
484 (dd ,(status-tag bug
)))))))))
486 (define (list-of-bugs bugs
)
487 "Return table rows for all BUGS."
489 (let ((id (number->string
(bug-num bug
))))
490 `(tr (@ (class ,(bug-severity bug
)))
493 ,@(if (member (bug-severity bug
) '("serious" "important"))
494 `((svg (@ (xmlns"http://www.w3.org/2000/svg")
495 (xmlns:xlink
"http://www.w3.org/1999/xlink")
496 (viewBox "0 0 14 16")
500 (aria-hidden "true"))
501 (title ,(bug-severity bug
))
502 (path (@ (fill-rule "evenodd")
504 M7 2.3c3.14 0 5.7 2.56 5.7 5.7\
505 s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8\
506 c0-3.14 2.56-5.7 5.7-5.7z\
507 M7 1C3.14 1 0 4.14 0 8\
508 s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z\
509 m1 3H6v5h2V4zm0 6H6v2h2v-2z")))))
512 `(a (@ (href ,(string-append "/issue/" id
)))
515 (td ,(date->string
(bug-date bug
)))
516 (td ,(status-tag bug
)))))
519 (define (priority-bugs)
522 (bugs-by-severity "serious" "open")
523 (bugs-by-severity "important" "open"))
524 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
526 (define (list-of-matching-bugs query bugs
)
530 (div (@ (class "container"))
532 `((h1 "No issues found")
533 (p "We could not find any issues matching your query "
536 "Try searching for something else?")))
537 `((h1 "Submissions matching " (code ,query
))
538 (table (@ (class "table table-condensed table-sm table-hover"))
542 (th "Date submitted")
545 ,@(list-of-bugs bugs
)))))))))