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"))))
80 #:extra-headers
,extra-headers
))
82 (define* (search-form #:key
(standalone?
#f
))
83 `(form (@ (id "search")
86 '(class "navbar-form navbar-right"))
89 (@ (class ,(if standalone?
90 "input-group input-group-lg"
92 (input (@ (type "text")
93 (class "form-control")
96 (placeholder "input search query")))
97 (span (@ (class "input-group-btn"))
100 (class ,(string-append (if standalone?
"btn-lg " "")
104 (define* (header #:key
(search-bar?
#t
))
106 (@ (id "header") (class "navbar navbar-default"))
108 (@ (class "container-fluid"))
110 (@ (class "navbar-header"))
111 (div (@ (class "navbar-brand"))
112 (a (@ (href "/") (class "logo")))))
120 '((cache-control .
((max-age .
60))))
122 `(,(header #:search-bar?
#f
)
124 (@ (class "container"))
125 (h1 "Guix patch tracker")
127 "This is a web frontend to the Guix patch tracker. Send email to "
128 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
129 ,(%config
'submission-email-address
))
130 " to submit your patches.")
131 ,(search-form #:standalone?
#t
)
135 (@ (class "panel panel-default"))
136 (p (@ (class "panel-body"))
138 "Refine your search with filters like "
139 (span (@ (class "filter"))
142 (span (@ (class "filter"))
145 (span (@ (class "filter"))
148 (span (@ (class "filter"))
149 "date:yesterday..now")
151 (span (@ (class "filter"))
152 "date:2018-04-01..2018-04-02")
154 (span (@ (class "filter"))
157 (span (@ (class "filter"))
160 (a (@ (href "help#search"))
162 (h2 "Recent activity")
163 (div (@ (id "snippet-recent"))
164 (img (@ (src "/img/spin.gif"))))
166 (div (@ (id "snippet-priority"))
167 (img (@ (src "/img/spin.gif"))))
169 (@ (type "text/javascript")
170 (src "/js/mumi.js")))))))
175 ;; Cache for 24 hours.
176 '((cache-control .
((max-age .
86400))))
178 `(,(header #:search-bar?
#f
)
180 (@ (class "container"))
182 (a (@ (href "search")))
183 (p "You can improve the search results by making use of the
184 simple query language. Here is a list of supported query terms with
190 (th (@ (class "col-md-3")) "Filter")
191 (th (@ (class "col-md-9")) "Description")))
194 (td (span (@ (class "filter")) "is:open") ", "
195 (span (@ (class "filter")) "is:pending"))
198 (td (span (@ (class "filter")) "is:closed") ", "
199 (span (@ (class "filter")) "is:done"))
200 (td "Issues marked as done."))
202 (td (span (@ (class "filter")) "submitter:<who>"))
203 (td "Issues submitted by a person named " (strong "who")
205 (span (@ (class "filter")) "submitter:ludo")
206 " for all issues submitted by ludo. "
207 "The filter matches both the email address and the name."))
209 (td (span (@ (class "filter")) "author:<who>"))
210 (td "Issues where a person named " (strong "who")
211 " has commented, e.g. "
212 (span (@ (class "filter")) "author:rekado")
213 " for all messages where rekado has commented. "
214 "The filter matches both the email address and the name."))
216 (td (span (@ (class "filter")) "date:<start>..<end>"))
217 (td "Issues submitted within the provided range. "
218 (strong "start") " and " (strong "end") " can be one of "
219 (strong "now") ", " (strong "today") ", " (strong "yesterday")
220 ", a date in the formats "
221 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
222 ", or an amount and a unit for a point in the past, such as "
223 (strong "12d") " for 12 days ago. "
224 "Supported units are: "
225 (strong "h") " (hours), "
226 (strong "d") " (days), "
227 (strong "w") " (weeks), "
228 (strong "m") " (months), and "
229 (strong "y") " (years)."))
231 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
232 (td "Issues with comments submitted within the provided
233 range. The supported arguments are the same as for "
234 (span (@ (class "filter")) "date:") "."))))))))
240 (div (@ (class "container"))
241 (h1 "Patch not found")
242 (p "There is no submission with id " (strong ,id
))
243 (p (a (@ (href "/")) "Try another one?"))))))
245 (define (error-page message
)
249 (div (@ (class "container"))
251 (p "An error occurred. Sorry about that!")
253 (p (a (@ (href "/")) "Try something else?"))))))
255 (define (issue-page bug
)
256 "Render the conversation for the given BUG."
257 (define id
(bug-num bug
))
258 (define messages
(patch-messages id
))
259 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
260 (participants messages
))
262 (string< (extract-email a
)
263 (extract-email b
)))))
264 (define (show-message message-number message previous-subject
)
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"))
277 (@ (class "panel panel-default"))
279 (@ (class "panel-heading"))
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 (or (string-suffix?
(or previous-subject
"")
289 (or (subject message
) ""))
290 (not (subject message
)))
292 `((div (@ (class "subject")) ,(subject message
))))
294 (@ (class "details"))
296 (@ (class "recipients"))
297 (label "Recipients:")
298 ,(map (lambda (address)
299 `(span (@ (class "address")) ,address
))
300 (recipients message
)))
302 (@ (class "message-id"))
303 (label "Message-ID:")
304 ,(message-id message
))))
306 (@ (class "body panel-body"))
307 ,(display-message-body id message-number message
)))))
308 ,@(if (closing? message id
)
310 (@ (class "row event"))
312 (@ (class "col-md-offset-1 col-md-11 text-center"))
313 (div (@ (class "label label-primary closed")) "Closed"))))
316 #:title
(bug-subject bug
)
320 ;; Tell browser to cache this for 12 hours.
321 '((cache-control .
((max-age .
43200)))))
323 ;; Tell browser to cache this for 1 hour.
324 '((cache-control .
((max-age .
3600)))))
329 (@ (class "container"))
331 (@ (class "row title col-md-12"))
332 (h1 ,(bug-subject bug
))
333 (span (@ (class "details"))
335 ,(string-append "Submitted by "
336 ;; We don't use bug-originator here
337 ;; because it includes the email address.
338 ;; We cannot use extract-name on the
339 ;; return value, because it swallows
340 ;; non-ASCII characters.
341 (sender-name (first messages
))
343 ,@(if (bug-mergedwith bug
)
344 `((ul (@ (class "merged"))
347 `(li (a (@ (href ,(string-append "/issue/" id
)))
349 ;; XXX: This field can either hold a
350 ;; string of multiple ids, or a single
351 ;; number. Deal with this mess.
352 (match (bug-mergedwith bug
)
354 (string-split str
#\space
))
356 (list (number->string n
)))))))
358 ,@(if (bug-blocks bug
)
359 `((ul (@ (class "blocks"))
362 `(li (a (@ (href ,(string-append "/issue/" id
)))
364 ;; XXX: This field can either hold a
365 ;; string of multiple ids, or a single
366 ;; number. Deal with this mess.
367 (match (bug-blocks bug
)
369 (string-split str
#\space
))
371 (list (number->string n
)))))))
373 ,@(if (bug-blockedby bug
)
374 `((ul (@ (class "blockedby"))
377 `(li (a (@ (href ,(string-append "/issue/" id
)))
379 ;; XXX: This field can either hold a
380 ;; string of multiple ids, or a single
381 ;; number. Deal with this mess.
382 (match (bug-blockedby bug
)
384 (string-split str
#\space
))
386 (list (number->string n
)))))))
391 (@ (class "conversation col-md-9"))
392 ,(let ((msgs (filter (lambda (msg)
395 ;; internal messages.
396 (and (email-body msg
)
397 (not (internal-message? msg
))))
399 (map (lambda (message-number msg previous-subject
)
400 (show-message message-number msg previous-subject
))
403 (cons (bug-subject bug
)
404 (map subject msgs
))))
406 (@ (class "row comment-box"))
407 (a (@ (id "comment")))
409 (@ (class "avatar col-md-1")
410 (style "background-color:#bc80bd")) "?")
412 (@ (class "message col-md-11"))
414 (@ (class "panel panel-default"))
416 (@ (class "panel-heading"))
417 (div (@ (class "from"))
418 (span (@ (class "address")) "Your comment")))
420 (@ (class "body panel-body"))
421 (p "Comments via the web interface are not currently
422 supported. To comment on this conversation "
423 (a (@ (href ,(string-append "mailto:"
424 (number->string id
) "@" (%config
'debbugs-domain
)
425 "?subject=" (bug-subject bug
))))
426 ,(string-append "send email to "
427 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
430 (@ (class "info col-md-3"))
433 ,@(let ((num (length parties
)))
434 `((label ,(if (= num
1)
436 (string-append (number->string num
)
438 (ul ,(map (lambda (name)
439 `(li (span (@ (class "name")))
441 (map extract-name parties
))))))
445 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
453 ,(status-tag bug
))))))))
455 (define (list-of-bugs bugs
)
456 "Return a table of BUGS."
458 `(p "Nothing to see here. "
460 "Look for something else?"))
461 `(table (@ (class "table-condensed"))
465 (th "Date submitted")
469 (let ((id (number->string
(bug-num bug
))))
470 `(tr (@ (class ,(bug-severity bug
)))
473 `(a (@ (href ,(string-append "/issue/" id
)))
476 (td ,(date->string
(bug-date bug
)))
477 (td ,(status-tag bug
)))))
480 (define (priority-bugs)
485 (bugs-by-severity "serious" "open")
486 (bugs-by-severity "important" "open"))
487 (lambda (a b
) (< (bug-num a
) (bug-num b
)))))))
489 (define (list-of-matching-bugs query bugs
)
493 (div (@ (class "container"))
495 `((h1 "No issues found")
496 (p "We could not find any issues matching your query "
499 "Try searching for something else?")))
500 `((h1 "Submissions matching " (code ,query
))
501 ,(list-of-bugs bugs
)))))))