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 search query")))
105 (span (@ (class "input-group-append"))
108 (class ,(string-append (if standalone?
"btn-lg " "")
112 (define* (header #:key
(search-bar?
#t
))
114 (@ (class "navbar navbar-expand navbar-light bg-light"))
115 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
116 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
124 '((cache-control .
((max-age .
60))))
126 `(,(header #:search-bar?
#f
)
128 (@ (class "container"))
129 (h1 "Guix patch tracker")
130 (p (@ (class "lead"))
131 "This is a web frontend to the Guix issue trackers. Send email to "
132 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
133 ,(%config
'submission-email-address
))
134 " to submit your patches or email "
135 (a (@ (href ,(string-append "mailto:" (%config
'submission-bug-email-address
))))
136 ,(%config
'submission-bug-email-address
))
137 " to open a new issue.")
139 (@ (class "card mb-5"))
140 (div (@ (class "card-body bg-light"))
141 ,(search-form #:standalone?
#t
)
142 (p (@ (class "card-text"))
144 "Refine your search with filters like "
145 (span (@ (class "filter"))
148 (span (@ (class "filter"))
151 (span (@ (class "filter"))
154 (span (@ (class "filter"))
155 "date:yesterday..now")
157 (span (@ (class "filter"))
158 "date:2018-04-01..2018-04-02")
160 (span (@ (class "filter"))
163 (a (@ (href "help#search"))
165 (h1 "Issues of interest")
166 (table (@ (class "table table-condensed table-sm table-hover"))
170 (th "Date submitted")
173 (tr (@ (class "bg-light")) (th (@ (colspan 4)) "Recent activity"))
174 ,@(list-of-bugs (recent-bugs 10))
175 (tr (@ (class "bg-light")) (th (@ (colspan 4)) "Priority bugs"))
176 ,@(priority-bugs)))))))
181 ;; Cache for 24 hours.
182 '((cache-control .
((max-age .
86400))))
184 `(,(header #:search-bar?
#f
)
186 (@ (class "container"))
188 (a (@ (href "search")))
189 (p "You can improve the search results by making use of the
190 simple query language. Here is a list of supported query terms with
196 (th (@ (class "col-md-3")) "Filter")
197 (th (@ (class "col-md-9")) "Description")))
200 (td (span (@ (class "filter")) "is:open") ", "
201 (span (@ (class "filter")) "is:pending"))
204 (td (span (@ (class "filter")) "is:closed") ", "
205 (span (@ (class "filter")) "is:done"))
206 (td "Issues marked as done."))
208 (td (span (@ (class "filter")) "submitter:<who>"))
209 (td "Issues submitted by a person named " (strong "who")
211 (span (@ (class "filter")) "submitter:ludo")
212 " for all issues submitted by ludo. "
213 "The filter matches both the email address and the name."))
215 (td (span (@ (class "filter")) "author:<who>"))
216 (td "Issues where a person named " (strong "who")
217 " has commented, e.g. "
218 (span (@ (class "filter")) "author:rekado")
219 " for all messages where rekado has commented. "
220 "The filter matches both the email address and the name."))
222 (td (span (@ (class "filter")) "date:<start>..<end>"))
223 (td "Issues or comments submitted within the provided range. "
224 (strong "start") " and " (strong "end") " can be one of "
225 (strong "now") ", " (strong "today") ", " (strong "yesterday")
226 ", a date in the formats "
227 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
228 ", or an amount and a unit for a point in the past, such as "
229 (strong "12d") " for 12 days ago. "
230 "Supported units are: "
231 (strong "h") " (hours), "
232 (strong "d") " (days), "
233 (strong "w") " (weeks), "
234 (strong "m") " (months), and "
235 (strong "y") " (years)."))))))))
241 (div (@ (class "container"))
242 (h1 "Patch not found")
243 (p "There is no submission with id " (strong ,id
))
244 (p (a (@ (href "/")) "Try another one?"))))))
246 (define (error-page message
)
250 (div (@ (class "container"))
252 (p "An error occurred. Sorry about that!")
254 (p (a (@ (href "/")) "Try something else?"))))))
256 (define (issue-page bug
)
257 "Render the conversation for the given BUG."
258 (define id
(bug-num bug
))
259 (define messages
(patch-messages id
))
260 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
261 (participants messages
))
263 (string< (extract-email a
)
264 (extract-email b
)))))
265 (define (show-message message-number message previous-subject
)
266 `((div (@ (class "row mb-5"))
267 (a (@ (id ,(number->string message-number
))))
269 (@ (class "avatar col-md-1")
270 (style ,(string-append "background-color:"
271 (avatar-color (sender-email message
)
272 (map extract-email parties
)))))
273 ,(string-upcase (string-take (sender-name message
) 1)))
275 (@ (class "message col-md-11"))
279 (@ (class "card-header"))
282 (span (@ (class "address")) ,(sender-name message
))
284 (span (@ (class "date"))
285 (a (@ (href ,(string-append "#" (number->string
287 ,(date->string
(date message
)))))
288 ,@(if (string-suffix? previous-subject
(subject message
))
290 `((div (@ (class "subject")) ,(subject message
))))
292 (@ (class "details"))
294 (@ (class "recipients"))
295 (label "Recipients:")
296 ,(map (lambda (address)
297 `(span (@ (class "address")) ,address
))
298 (recipients message
)))
300 (@ (class "message-id"))
301 (label "Message-ID:")
302 ,(message-id message
))))
304 (@ (class "body card-body"))
305 ,(display-message-body id message-number message
)))))
306 ,@(if (closing? message id
)
308 (@ (class "row event"))
310 (@ (class "col-md-11 offset-md-1 text-center"))
311 (div (@ (class "badge badge-primary closed")) "Closed"))))
314 #:title
(bug-subject* bug
)
318 ;; Tell browser to cache this for 12 hours.
319 '((cache-control .
((max-age .
43200)))))
321 ;; Tell browser to cache this for 1 hour.
322 '((cache-control .
((max-age .
3600)))))
327 (@ (class "container"))
329 (@ (class "title col-md-12"))
330 (h1 ,(bug-subject* bug
))
331 (span (@ (class "details"))
333 ,(string-append "Submitted by "
334 ;; We don't use bug-originator here
335 ;; because it includes the email address.
336 ;; We cannot use extract-name on the
337 ;; return value, because it swallows
338 ;; non-ASCII characters.
339 (sender-name (first messages
))
341 ,@(if (bug-mergedwith bug
)
342 `((ul (@ (class "merged"))
345 `(li (a (@ (href ,(string-append "/issue/" id
)))
347 ;; XXX: This field can either hold a
348 ;; string of multiple ids, or a single
349 ;; number. Deal with this mess.
350 (match (bug-mergedwith bug
)
352 (string-split str
#\space
))
354 (list (number->string n
)))))))
356 ,@(if (bug-blocks bug
)
357 `((ul (@ (class "blocks"))
360 `(li (a (@ (href ,(string-append "/issue/" id
)))
362 ;; XXX: This field can either hold a
363 ;; string of multiple ids, or a single
364 ;; number. Deal with this mess.
365 (match (bug-blocks bug
)
367 (string-split str
#\space
))
369 (list (number->string n
)))))))
371 ,@(if (bug-blockedby bug
)
372 `((ul (@ (class "blockedby"))
375 `(li (a (@ (href ,(string-append "/issue/" id
)))
377 ;; XXX: This field can either hold a
378 ;; string of multiple ids, or a single
379 ;; number. Deal with this mess.
380 (match (bug-blockedby bug
)
382 (string-split str
#\space
))
384 (list (number->string n
)))))))
386 (div (@ (class "row"))
388 (@ (class "conversation col-md-9"))
389 ,(let ((msgs (filter (lambda (msg)
392 ;; internal messages.
393 (and (email-body msg
)
394 (not (internal-message? msg
))))
396 (map (lambda (message-number msg previous-subject
)
397 (show-message message-number msg previous-subject
))
400 (cons (bug-subject* bug
)
401 (map subject msgs
))))
403 (@ (class "row comment-box"))
404 (a (@ (id "comment")))
406 (@ (class "avatar col-md-1")
407 (style "background-color:#bc80bd")) "?")
409 (@ (class "message col-md-11"))
413 (@ (class "card-header"))
414 (div (@ (class "from"))
415 (span (@ (class "address")) "Your comment")))
417 (@ (class "body card-body"))
418 (p "Comments via the web interface are not currently
419 supported. To comment on this conversation "
420 (a (@ (href ,(string-append "mailto:"
421 (number->string id
) "@" (%config
'debbugs-domain
)
422 "?subject=" (bug-subject* bug
))))
423 ,(string-append "send email to "
424 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
427 (@ (class "info col-md-3"))
430 ,@(let ((num (length parties
)))
433 (string-append (number->string num
)
436 (ul ,(map (lambda (name)
437 `(li (span (@ (class "name")))
439 (map extract-name parties
)))))))
444 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned")))
448 (dd ,(bug-severity bug
)))
452 (dd ,(status-tag bug
)))))))))
454 (define (list-of-bugs bugs
)
455 "Return table rows for all BUGS."
457 (let ((id (number->string
(bug-num bug
))))
458 `(tr (@ (class ,(bug-severity bug
)))
461 `(a (@ (href ,(string-append "/issue/" id
)))
464 (td ,(date->string
(bug-date bug
)))
465 (td ,(status-tag bug
)))))
468 (define (priority-bugs)
471 (bugs-by-severity "serious" "open")
472 (bugs-by-severity "important" "open"))
473 (lambda (a b
) (< (bug-num a
) (bug-num b
))))))
475 (define (list-of-matching-bugs query bugs
)
479 (div (@ (class "container"))
481 `((h1 "No issues found")
482 (p "We could not find any issues matching your query "
485 "Try searching for something else?")))
486 `((h1 "Submissions matching " (code ,query
))
487 (table (@ (class "table table-condensed table-sm table-hover"))
491 (th "Date submitted")
494 ,@(list-of-bugs bugs
)))))))))