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
)
37 (define (status-tag bug
)
38 "Return a colored tag indicating the BUG status."
39 (let ((status (if (bug-done bug
) "Done" "Open")))
40 `(span (@ (class ,(string-append "status-tag "
41 (string-downcase status
))))
44 (define* (layout #:key
47 (title "Guix issue tracker")
49 `(#:sxml
((doctype "html")
53 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
54 (meta (@ (http-equiv "Content-Language") (content "en")))
55 (meta (@ (name "author") (content "Ricardo Wurmus")))
56 (meta (@ (name "viewport")
57 (content "width=device-width, initial-scale=1")))
62 (href "/css/reset.css")))
67 (href "/css/bootstrap.css")))
73 (href "/css/screen.css")))
78 (href "/css/code.css"))))
81 (p "Copyright © 2016—2019 by the GNU Guix community."
83 "Now with even more " (span (@ (class "lambda")) "λ") "! ")
84 (p "This is free software. Download the "
85 (a (@ (href "https://git.elephly.net/software/mumi.git"))
86 "source code here") ".")))))
87 #:extra-headers
,extra-headers
))
89 (define* (search-form #:key
(standalone?
#f
))
90 `(form (@ (id "search")
93 '(class "navbar-form navbar-right"))
96 (@ (class ,(if standalone?
97 "input-group input-group-lg"
99 (input (@ (type "text")
100 (class "form-control")
103 (placeholder "input search query")))
104 (span (@ (class "input-group-btn"))
107 (class ,(string-append (if standalone?
"btn-lg " "")
111 (define* (header #:key
(search-bar?
#t
))
113 (@ (id "header") (class "navbar navbar-default"))
115 (@ (class "container-fluid"))
117 (@ (class "navbar-header"))
118 (div (@ (class "navbar-brand"))
119 (a (@ (href "/") (class "logo")))))
127 '((cache-control .
((max-age .
60))))
129 `(,(header #:search-bar?
#f
)
131 (@ (class "container"))
132 (h1 "Guix patch tracker")
134 "This is a web frontend to the Guix patch tracker. Send email to "
135 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
136 ,(%config
'submission-email-address
))
137 " to submit your patches.")
138 ,(search-form #:standalone?
#t
)
142 (@ (class "panel panel-default"))
143 (p (@ (class "panel-body"))
145 "Refine your search with filters like "
146 (span (@ (class "filter"))
149 (span (@ (class "filter"))
152 (span (@ (class "filter"))
155 (span (@ (class "filter"))
156 "date:yesterday..now")
158 (span (@ (class "filter"))
159 "date:2018-04-01..2018-04-02")
161 (span (@ (class "filter"))
164 (span (@ (class "filter"))
167 (a (@ (href "help#search"))
169 (h2 "Recent activity")
170 (div (@ (id "snippet-recent"))
171 (img (@ (src "/img/spin.gif"))))
173 (div (@ (id "snippet-priority"))
174 (img (@ (src "/img/spin.gif"))))
176 (@ (type "text/javascript")
177 (src "/js/mumi.js")))))))
182 ;; Cache for 24 hours.
183 '((cache-control .
((max-age .
86400))))
185 `(,(header #:search-bar?
#f
)
187 (@ (class "container"))
189 (a (@ (href "search")))
190 (p "You can improve the search results by making use of the
191 simple query language. Here is a list of supported query terms with
197 (th (@ (class "col-md-3")) "Filter")
198 (th (@ (class "col-md-9")) "Description")))
201 (td (span (@ (class "filter")) "is:open") ", "
202 (span (@ (class "filter")) "is:pending"))
205 (td (span (@ (class "filter")) "is:closed") ", "
206 (span (@ (class "filter")) "is:done"))
207 (td "Issues marked as done."))
209 (td (span (@ (class "filter")) "submitter:<who>"))
210 (td "Issues submitted by a person named " (strong "who")
212 (span (@ (class "filter")) "submitter:ludo")
213 " for all issues submitted by ludo. "
214 "The filter matches both the email address and the name."))
216 (td (span (@ (class "filter")) "author:<who>"))
217 (td "Issues where a person named " (strong "who")
218 " has commented, e.g. "
219 (span (@ (class "filter")) "author:rekado")
220 " for all messages where rekado has commented. "
221 "The filter matches both the email address and the name."))
223 (td (span (@ (class "filter")) "date:<start>..<end>"))
224 (td "Issues submitted within the provided range. "
225 (strong "start") " and " (strong "end") " can be one of "
226 (strong "now") ", " (strong "today") ", " (strong "yesterday")
227 ", a date in the formats "
228 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
229 ", or an amount and a unit for a point in the past, such as "
230 (strong "12d") " for 12 days ago. "
231 "Supported units are: "
232 (strong "h") " (hours), "
233 (strong "d") " (days), "
234 (strong "w") " (weeks), "
235 (strong "m") " (months), and "
236 (strong "y") " (years)."))
238 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
239 (td "Issues with comments submitted within the provided
240 range. The supported arguments are the same as for "
241 (span (@ (class "filter")) "date:") "."))))))))
247 (div (@ (class "container"))
248 (h1 "Patch not found")
249 (p "There is no submission with id " (strong ,id
))
250 (p (a (@ (href "/")) "Try another one?"))))))
252 (define (error-page message
)
256 (div (@ (class "container"))
258 (p "An error occurred. Sorry about that!")
260 (p (a (@ (href "/")) "Try something else?"))))))
262 (define (issue-page bug
)
263 "Render the conversation for the given BUG."
264 (define id
(bug-num bug
))
265 (define messages
(patch-messages id
))
266 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
267 (participants messages
))
269 (string< (extract-email a
)
270 (extract-email b
)))))
271 (define (show-message message-number message previous-subject
)
274 (a (@ (id ,(number->string message-number
))))
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)))
282 (@ (class "message col-md-11"))
284 (@ (class "panel panel-default"))
286 (@ (class "panel-heading"))
289 (span (@ (class "address")) ,(sender-name message
))
291 (span (@ (class "date"))
292 (a (@ (href ,(string-append "#" (number->string
294 ,(date->string
(date message
)))))
295 ,@(if (or (string-suffix?
(or previous-subject
"")
296 (or (subject message
) ""))
297 (not (subject message
)))
299 `((div (@ (class "subject")) ,(subject message
))))
301 (@ (class "details"))
303 (@ (class "recipients"))
304 (label "Recipients:")
305 ,(map (lambda (address)
306 `(span (@ (class "address")) ,address
))
307 (recipients message
)))
309 (@ (class "message-id"))
310 (label "Message-ID:")
311 ,(message-id message
))))
313 (@ (class "body panel-body"))
314 ,(display-message-body id message-number message
)))))
315 ,@(if (closing? message id
)
317 (@ (class "row event"))
319 (@ (class "col-md-offset-1 col-md-11 text-center"))
320 (div (@ (class "label label-primary closed")) "Closed"))))
323 #:title
(bug-subject bug
)
327 ;; Tell browser to cache this for 12 hours.
328 '((cache-control .
((max-age .
43200)))))
330 ;; Tell browser to cache this for 1 hour.
331 '((cache-control .
((max-age .
3600)))))
336 (@ (class "container"))
338 (@ (class "row title col-md-12"))
339 (h1 ,(bug-subject bug
))
340 (span (@ (class "details"))
342 ,(string-append "Submitted by "
343 ;; We don't use bug-originator here
344 ;; because it includes the email address.
345 ;; We cannot use extract-name on the
346 ;; return value, because it swallows
347 ;; non-ASCII characters.
348 (sender-name (first messages
))
350 ,@(if (bug-mergedwith bug
)
351 `((ul (@ (class "merged"))
354 `(li (a (@ (href ,(string-append "/issue/" id
)))
356 ;; XXX: This field can either hold a
357 ;; string of multiple ids, or a single
358 ;; number. Deal with this mess.
359 (match (bug-mergedwith bug
)
361 (string-split str
#\space
))
363 (list (number->string n
)))))))
365 ,@(if (bug-blocks bug
)
366 `((ul (@ (class "blocks"))
369 `(li (a (@ (href ,(string-append "/issue/" id
)))
371 ;; XXX: This field can either hold a
372 ;; string of multiple ids, or a single
373 ;; number. Deal with this mess.
374 (match (bug-blocks bug
)
376 (string-split str
#\space
))
378 (list (number->string n
)))))))
380 ,@(if (bug-blockedby bug
)
381 `((ul (@ (class "blockedby"))
384 `(li (a (@ (href ,(string-append "/issue/" id
)))
386 ;; XXX: This field can either hold a
387 ;; string of multiple ids, or a single
388 ;; number. Deal with this mess.
389 (match (bug-blockedby bug
)
391 (string-split str
#\space
))
393 (list (number->string n
)))))))
398 (@ (class "conversation col-md-9"))
399 ,(let ((msgs (filter (lambda (msg)
402 ;; internal messages.
403 (and (email-body msg
)
404 (not (internal-message? msg
))))
406 (map (lambda (message-number msg previous-subject
)
407 (show-message message-number msg previous-subject
))
410 (cons (bug-subject bug
)
411 (map subject msgs
))))
413 (@ (class "row comment-box"))
414 (a (@ (id "comment")))
416 (@ (class "avatar col-md-1")
417 (style "background-color:#bc80bd")) "?")
419 (@ (class "message col-md-11"))
421 (@ (class "panel panel-default"))
423 (@ (class "panel-heading"))
424 (div (@ (class "from"))
425 (span (@ (class "address")) "Your comment")))
427 (@ (class "body panel-body"))
428 (p "Comments via the web interface are not currently
429 supported. To comment on this conversation "
430 (a (@ (href ,(string-append "mailto:"
431 (number->string id
) "@" (%config
'debbugs-domain
)
432 "?subject=" (bug-subject bug
))))
433 ,(string-append "send email to "
434 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
437 (@ (class "info col-md-3"))
440 ,@(let ((num (length parties
)))
441 `((label ,(if (= num
1)
443 (string-append (number->string num
)
445 (ul ,(map (lambda (name)
446 `(li (span (@ (class "name")))
448 (map extract-name parties
))))))
452 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
460 ,(status-tag bug
))))))))
462 (define (list-of-bugs bugs
)
463 "Return a table of BUGS."
465 `(p "Nothing to see here. "
467 "Look for something else?"))
468 `(table (@ (class "table-condensed"))
472 (th "Date submitted")
476 (let ((id (number->string
(bug-num bug
))))
477 `(tr (@ (class ,(bug-severity bug
)))
480 `(a (@ (href ,(string-append "/issue/" id
)))
483 (td ,(date->string
(bug-date bug
)))
484 (td ,(status-tag bug
)))))
487 (define (priority-bugs)
492 (bugs-by-severity "serious" "open")
493 (bugs-by-severity "important" "open"))
494 (lambda (a b
) (< (bug-num a
) (bug-num b
)))))))
496 (define (list-of-matching-bugs query bugs
)
500 (div (@ (class "container"))
502 `((h1 "No issues found")
503 (p "We could not find any issues matching your query "
506 "Try searching for something else?")))
507 `((h1 "Submissions matching " (code ,query
))
508 ,(list-of-bugs bugs
)))))))