view/html: Remove help for obsolete mdate keyword.
[software/mumi.git] / mumi / web / view / html.scm
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>
4 ;;;
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.
9 ;;;
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.
14 ;;;
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/>.
18
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)
28 #:export (index
29 help
30 unknown
31 error-page
32 issue-page
33 list-of-matching-bugs
34 list-of-bugs
35 priority-bugs))
36
37 (define (bug-subject* bug)
38 (or (bug-subject bug) "(no subject)"))
39
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))))
45 ,status)))
46
47 (define* (layout #:key
48 (head '())
49 (body '())
50 (title "Guix issue tracker")
51 (extra-headers '()))
52 `(#:sxml ((doctype "html")
53 (html
54 (head
55 (title ,title)
56 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
57 (meta (@ (http-equiv "Content-Language") (content "en")))
58 (meta (@ (name "author") (content "Ricardo Wurmus")))
59 (meta (@ (name "viewport")
60 (content "width=device-width, initial-scale=1")))
61 (link
62 (@ (rel "stylesheet")
63 (media "screen")
64 (type "text/css")
65 (href "/css/reset.css")))
66 (link
67 (@ (rel "stylesheet")
68 (media "screen")
69 (type "text/css")
70 (href "/css/bootstrap.css")))
71 ,@head
72 (link
73 (@ (rel "stylesheet")
74 (media "screen")
75 (type "text/css")
76 (href "/css/screen.css")))
77 (link
78 (@ (rel "stylesheet")
79 (media "screen")
80 (type "text/css")
81 (href "/css/code.css"))))
82 (body ,@body
83 (footer (@ (class "text-center"))
84 (p "Copyright © 2016—2020 by the GNU Guix community."
85 (br)
86 "Now with even more " (span (@ (class "lambda")) "λ") "! ")
87 (p "This is free software. Download the "
88 (a (@ (href "https://git.elephly.net/software/mumi.git"))
89 "source code here") ".")))))
90 #:extra-headers ,extra-headers))
91
92 (define* (search-form #:key (standalone? #f))
93 `(form (@ (id "search")
94 ,(if standalone?
95 '(class "")
96 '(class "form-inline"))
97 (action "/search"))
98 (div
99 (@ (class ,(if standalone?
100 "input-group input-group-lg"
101 "input-group")))
102 (input (@ (type "text")
103 (class "form-control")
104 (id "query")
105 (name "query")
106 (placeholder "input search query")))
107 (span (@ (class "input-group-append"))
108 (button
109 (@ (type "submit")
110 (class ,(string-append (if standalone? "btn-lg " "")
111 "btn btn-primary")))
112 "Search")))))
113
114 (define* (header #:key (search-bar? #t))
115 `(nav
116 (@ (class "navbar navbar-expand navbar-light bg-light"))
117 (a (@ (href "/") (class "navbar-brand pt-0 logo navbar-collapse"))
118 (img (@ (src "/img/logo.png") (alt "logo") (height "25"))))
119 ,@(if search-bar?
120 `(,(search-form))
121 '())))
122
123 (define (index)
124 (layout
125 #:extra-headers
126 '((cache-control . ((max-age . 60))))
127 #:body
128 `(,(header #:search-bar? #f)
129 (main
130 (@ (class "container"))
131 (h1 "Guix patch tracker")
132 (p (@ (class "lead"))
133 "This is a web frontend to the Guix issue trackers. Send email to "
134 (a (@ (href ,(string-append "mailto:" (%config 'submission-email-address))))
135 ,(%config 'submission-email-address))
136 " to submit your patches or email "
137 (a (@ (href ,(string-append "mailto:" (%config 'submission-bug-email-address))))
138 ,(%config 'submission-bug-email-address))
139 " to open a new issue.")
140 (div
141 (@ (class "card mb-5"))
142 (div (@ (class "card-body bg-light"))
143 ,(search-form #:standalone? #t)
144 (p (@ (class "card-text"))
145 (strong "Hint: ")
146 "Refine your search with filters like "
147 (span (@ (class "filter"))
148 "is:open")
149 ", "
150 (span (@ (class "filter"))
151 "author:me")
152 ", "
153 (span (@ (class "filter"))
154 "submitter:me")
155 ", "
156 (span (@ (class "filter"))
157 "date:yesterday..now")
158 ", "
159 (span (@ (class "filter"))
160 "date:2018-04-01..2018-04-02")
161 ", "
162 (span (@ (class "filter"))
163 "date:1m..today")
164 ", and "
165 (a (@ (href "help#search"))
166 "many more!"))))
167 (h1 "Issues of interest")
168 (table (@ (class "table table-condensed table-sm table-hover"))
169 (thead
170 (tr (th "ID")
171 (th "Subject")
172 (th "Date submitted")
173 (th "Status")))
174 (tbody
175 (tr (@ (class "bg-light")) (th (@ (colspan 4)) "Recent activity"))
176 (tr (@ (id "snippet-recent"))
177 (td (@ (colspan 4)) (img (@ (src "/img/spin.gif")))))
178 (tr (@ (class "bg-light")) (th (@ (colspan 4)) "Priority bugs"))
179 (tr (@ (id "snippet-priority"))
180 (td (@ (colspan 4)) (img (@ (src "/img/spin.gif")))))))
181 (script
182 (@ (type "text/javascript")
183 (src "/js/mumi.js")))))))
184
185 (define (help)
186 (layout
187 #:extra-headers
188 ;; Cache for 24 hours.
189 '((cache-control . ((max-age . 86400))))
190 #:body
191 `(,(header #:search-bar? #f)
192 (div
193 (@ (class "container"))
194 (h1 "Help")
195 (a (@ (href "search")))
196 (p "You can improve the search results by making use of the
197 simple query language. Here is a list of supported query terms with
198 some examples.")
199 (table
200 (@ (class "table"))
201 (thead
202 (tr
203 (th (@ (class "col-md-3")) "Filter")
204 (th (@ (class "col-md-9")) "Description")))
205 (tbody
206 (tr
207 (td (span (@ (class "filter")) "is:open") ", "
208 (span (@ (class "filter")) "is:pending"))
209 (td "Open issues."))
210 (tr
211 (td (span (@ (class "filter")) "is:closed") ", "
212 (span (@ (class "filter")) "is:done"))
213 (td "Issues marked as done."))
214 (tr
215 (td (span (@ (class "filter")) "submitter:<who>"))
216 (td "Issues submitted by a person named " (strong "who")
217 ", e.g. "
218 (span (@ (class "filter")) "submitter:ludo")
219 " for all issues submitted by ludo. "
220 "The filter matches both the email address and the name."))
221 (tr
222 (td (span (@ (class "filter")) "author:<who>"))
223 (td "Issues where a person named " (strong "who")
224 " has commented, e.g. "
225 (span (@ (class "filter")) "author:rekado")
226 " for all messages where rekado has commented. "
227 "The filter matches both the email address and the name."))
228 (tr
229 (td (span (@ (class "filter")) "date:<start>..<end>"))
230 (td "Issues or comments submitted within the provided range. "
231 (strong "start") " and " (strong "end") " can be one of "
232 (strong "now") ", " (strong "today") ", " (strong "yesterday")
233 ", a date in the formats "
234 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
235 ", or an amount and a unit for a point in the past, such as "
236 (strong "12d") " for 12 days ago. "
237 "Supported units are: "
238 (strong "h") " (hours), "
239 (strong "d") " (days), "
240 (strong "w") " (weeks), "
241 (strong "m") " (months), and "
242 (strong "y") " (years)."))))))))
243
244 (define (unknown id)
245 (layout
246 #:body
247 `(,(header)
248 (div (@ (class "container"))
249 (h1 "Patch not found")
250 (p "There is no submission with id " (strong ,id))
251 (p (a (@ (href "/")) "Try another one?"))))))
252
253 (define (error-page message)
254 (layout
255 #:body
256 `(,(header)
257 (div (@ (class "container"))
258 (h1 "Error")
259 (p "An error occurred. Sorry about that!")
260 ,message
261 (p (a (@ (href "/")) "Try something else?"))))))
262
263 (define (issue-page bug)
264 "Render the conversation for the given BUG."
265 (define id (bug-num bug))
266 (define messages (patch-messages id))
267 (define parties (sort (filter (compose (negate bot?) extract-email)
268 (participants messages))
269 (lambda (a b)
270 (string< (extract-email a)
271 (extract-email b)))))
272 (define (show-message message-number message previous-subject)
273 `((div (@ (class "row mb-5"))
274 (a (@ (id ,(number->string message-number))))
275 (div
276 (@ (class "avatar col-md-1")
277 (style ,(string-append "background-color:"
278 (avatar-color (sender-email message)
279 (map extract-email parties)))))
280 ,(string-upcase (string-take (sender-name message) 1)))
281 (div
282 (@ (class "message col-md-11"))
283 (div
284 (@ (class "card"))
285 (div
286 (@ (class "card-header"))
287 (div
288 (@ (class "from"))
289 (span (@ (class "address")) ,(sender-name message))
290 " wrote on "
291 (span (@ (class "date"))
292 (a (@ (href ,(string-append "#" (number->string
293 message-number))))
294 ,(date->string (date message)))))
295 ,@(if (string-suffix? previous-subject (subject message))
296 '()
297 `((div (@ (class "subject")) ,(subject message))))
298 (div
299 (@ (class "details"))
300 (div
301 (@ (class "recipients"))
302 (label "Recipients:")
303 ,(map (lambda (address)
304 `(span (@ (class "address")) ,address))
305 (recipients message)))
306 (div
307 (@ (class "message-id"))
308 (label "Message-ID:")
309 ,(message-id message))))
310 (div
311 (@ (class "body card-body"))
312 ,(display-message-body id message-number message)))))
313 ,@(if (closing? message id)
314 '((div
315 (@ (class "row event"))
316 (div
317 (@ (class "col-md-11 offset-md-1 text-center"))
318 (div (@ (class "badge badge-primary closed")) "Closed"))))
319 '())))
320 (layout
321 #:title (bug-subject* bug)
322 #:extra-headers
323 (cond
324 ((bug-archived bug)
325 ;; Tell browser to cache this for 12 hours.
326 '((cache-control . ((max-age . 43200)))))
327 ((bug-done bug)
328 ;; Tell browser to cache this for 1 hour.
329 '((cache-control . ((max-age . 3600)))))
330 (else '()))
331 #:body
332 `(,(header)
333 (div
334 (@ (class "container"))
335 (div
336 (@ (class "title col-md-12"))
337 (h1 ,(bug-subject* bug))
338 (span (@ (class "details"))
339 ,(status-tag bug)
340 ,(string-append "Submitted by "
341 ;; We don't use bug-originator here
342 ;; because it includes the email address.
343 ;; We cannot use extract-name on the
344 ;; return value, because it swallows
345 ;; non-ASCII characters.
346 (sender-name (first messages))
347 ".")
348 ,@(if (bug-mergedwith bug)
349 `((ul (@ (class "merged"))
350 "Merged with: "
351 ,(map (lambda (id)
352 `(li (a (@ (href ,(string-append "/issue/" id)))
353 ,id)))
354 ;; XXX: This field can either hold a
355 ;; string of multiple ids, or a single
356 ;; number. Deal with this mess.
357 (match (bug-mergedwith bug)
358 ((? string? str)
359 (string-split str #\space))
360 ((? number? n)
361 (list (number->string n)))))))
362 '())
363 ,@(if (bug-blocks bug)
364 `((ul (@ (class "blocks"))
365 "Blocks: "
366 ,(map (lambda (id)
367 `(li (a (@ (href ,(string-append "/issue/" id)))
368 ,id)))
369 ;; XXX: This field can either hold a
370 ;; string of multiple ids, or a single
371 ;; number. Deal with this mess.
372 (match (bug-blocks bug)
373 ((? string? str)
374 (string-split str #\space))
375 ((? number? n)
376 (list (number->string n)))))))
377 '())
378 ,@(if (bug-blockedby bug)
379 `((ul (@ (class "blockedby"))
380 "Blocked by: "
381 ,(map (lambda (id)
382 `(li (a (@ (href ,(string-append "/issue/" id)))
383 ,id)))
384 ;; XXX: This field can either hold a
385 ;; string of multiple ids, or a single
386 ;; number. Deal with this mess.
387 (match (bug-blockedby bug)
388 ((? string? str)
389 (string-split str #\space))
390 ((? number? n)
391 (list (number->string n)))))))
392 '())))
393 (div (@ (class "row"))
394 (div
395 (@ (class "conversation col-md-9"))
396 ,(let ((msgs (filter (lambda (msg)
397 ;; Ignore messages
398 ;; without body, and
399 ;; internal messages.
400 (and (email-body msg)
401 (not (internal-message? msg))))
402 messages)))
403 (map (lambda (message-number msg previous-subject)
404 (show-message message-number msg previous-subject))
405 (iota (length msgs))
406 msgs
407 (cons (bug-subject* bug)
408 (map subject msgs))))
409 (div
410 (@ (class "row comment-box"))
411 (a (@ (id "comment")))
412 (div
413 (@ (class "avatar col-md-1")
414 (style "background-color:#bc80bd")) "?")
415 (div
416 (@ (class "message col-md-11"))
417 (div
418 (@ (class "card"))
419 (div
420 (@ (class "card-header"))
421 (div (@ (class "from"))
422 (span (@ (class "address")) "Your comment")))
423 (div
424 (@ (class "body card-body"))
425 (p "Comments via the web interface are not currently
426 supported. To comment on this conversation "
427 (a (@ (href ,(string-append "mailto:"
428 (number->string id) "@" (%config 'debbugs-domain)
429 "?subject=" (bug-subject* bug))))
430 ,(string-append "send email to "
431 (number->string id) "@" (%config 'debbugs-domain)))))))))
432
433 (div
434 (@ (class "info col-md-3"))
435 (dl
436 (@ (class "stat"))
437 ,@(let ((num (length parties)))
438 `((dt ,(if (= num 1)
439 "One participant"
440 (string-append (number->string num)
441 " participants")))
442 (dd
443 (ul ,(map (lambda (name)
444 `(li (span (@ (class "name")))
445 ,name))
446 (map extract-name parties)))))))
447 (dl
448 (@ (class "stat"))
449 (dt "Owner")
450 (dd
451 ,(or (and=> (bug-owner bug) extract-name) "unassigned")))
452 (dl
453 (@ (class "stat"))
454 (dt "Severity")
455 (dd ,(bug-severity bug)))
456 (dl
457 (@ (class "stat"))
458 (dt "Status")
459 (dd ,(status-tag bug)))))))))
460
461 (define (list-of-bugs bugs)
462 "Return table rows for all BUGS."
463 (map (lambda (bug)
464 (let ((id (number->string (bug-num bug))))
465 `(tr (@ (class ,(bug-severity bug)))
466 (td ,(or id "-"))
467 (td ,(if id
468 `(a (@ (href ,(string-append "/issue/" id)))
469 ,(bug-subject* bug))
470 (bug-subject* bug)))
471 (td ,(date->string (bug-date bug)))
472 (td ,(status-tag bug)))))
473 bugs))
474
475 (define (priority-bugs)
476 (list-of-bugs (sort
477 (append
478 (bugs-by-severity "serious" "open")
479 (bugs-by-severity "important" "open"))
480 (lambda (a b) (< (bug-num a) (bug-num b))))))
481
482 (define (list-of-matching-bugs query bugs)
483 (layout
484 #:body
485 `(,(header)
486 (div (@ (class "container"))
487 ,@(if (null? bugs)
488 `((h1 "No issues found")
489 (p "We could not find any issues matching your query "
490 (code ,query) ". "
491 (a (@ (href "/"))
492 "Try searching for something else?")))
493 `((h1 "Submissions matching " (code ,query))
494 (table (@ (class "table table-condensed table-sm table-hover"))
495 (thead
496 (tr (th "ID")
497 (th "Subject")
498 (th "Date submitted")
499 (th "Status")))
500 (tbody
501 ,@(list-of-bugs bugs)))))))))