1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2016, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
4 ;;; This program is free software: you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Affero General Public License
6 ;;; as published by the Free Software Foundation, either version 3 of
7 ;;; the License, or (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Affero General Public License for more details.
14 ;;; You should have received a copy of the GNU Affero General Public
15 ;;; License along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
18 (define-module (mumi web view html
)
19 #:use-module
(debbugs email
)
20 #:use-module
(debbugs bug
)
21 #:use-module
(mumi config
)
22 #:use-module
(mumi messages
)
23 #:use-module
(mumi web view utils
)
24 #:use-module
(srfi srfi-1
)
25 #:use-module
(srfi srfi-19
)
31 list-of-matching-bugs
))
33 (define (status-tag bug
)
34 "Return a colored tag indicating the BUG status."
35 (let ((status (if (bug-done bug
) "Done" "Open")))
36 `(span (@ (class ,(string-append "status-tag "
37 (string-downcase status
))))
40 (define* (layout #:key
43 (title "Guix issue tracker")
45 `(#:sxml
((doctype "html")
49 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
50 (meta (@ (http-equiv "Content-Language") (content "en")))
51 (meta (@ (name "author") (content "Ricardo Wurmus")))
52 (meta (@ (name "viewport")
53 (content "width=device-width, initial-scale=1")))
58 (href "/css/reset.css")))
63 (href "/css/bootstrap.css")))
69 (href "/css/screen.css")))
74 (href "/css/code.css"))))
76 #:extra-headers
,extra-headers
))
78 (define* (search-form #:key
(standalone?
#f
))
79 `(form (@ (id "search")
82 '(class "navbar-form navbar-right"))
85 (@ (class ,(if standalone?
86 "input-group input-group-lg"
88 (input (@ (type "text")
89 (class "form-control")
92 (placeholder "input search query")))
93 (span (@ (class "input-group-btn"))
96 (class ,(string-append (if standalone?
"btn-lg " "")
100 (define* (header #:key
(search-bar?
#t
))
102 (@ (id "header") (class "navbar navbar-default"))
104 (@ (class "container-fluid"))
106 (@ (class "navbar-header"))
107 (div (@ (class "navbar-brand"))
108 (a (@ (href "/") (class "logo"))
109 (img (@ (src "/img/logo.png")
110 (alt "Guix patch tracker"))))))
118 '((cache-control .
((max-age .
60))))
120 `(,(header #:search-bar?
#f
)
122 (@ (class "container"))
123 (h1 "Guix patch tracker")
125 "This is a web frontend to the Guix patch tracker. Send email to "
126 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
127 ,(%config
'submission-email-address
))
128 " to submit your patches.")
129 ,(search-form #:standalone?
#t
)
133 (@ (class "panel panel-default"))
134 (p (@ (class "panel-body"))
136 "Refine your search with filters like "
137 (span (@ (class "filter"))
140 (span (@ (class "filter"))
143 (span (@ (class "filter"))
146 (span (@ (class "filter"))
147 "date:yesterday..now")
149 (span (@ (class "filter"))
150 "date:2018-04-01..2018-04-02")
152 (span (@ (class "filter"))
155 (span (@ (class "filter"))
158 (a (@ (href "help#search"))
160 ;; TODO: do this via JS?
161 ,@(let ((bugs (recent-bugs 5)))
164 `((h2 "Recent activity")
165 ,(list-of-bugs bugs
))))))))
170 ;; Cache for 24 hours.
171 '((cache-control .
((max-age .
86400))))
173 `(,(header #:search-bar?
#f
)
175 (@ (class "container"))
177 (a (@ (href "search")))
178 (p "You can improve the search results by making use of the
179 simple query language. Here is a list of supported query terms with
185 (th (@ (class "col-md-3")) "Filter")
186 (th (@ (class "col-md-9")) "Description")))
189 (td (span (@ (class "filter")) "is:open") ", "
190 (span (@ (class "filter")) "is:pending"))
193 (td (span (@ (class "filter")) "is:closed") ", "
194 (span (@ (class "filter")) "is:done"))
195 (td "Issues marked as done."))
197 (td (span (@ (class "filter")) "submitter:<who>"))
198 (td "Issues submitted by a person named " (strong "who")
200 (span (@ (class "filter")) "submitter:ludo")
201 " for all issues submitted by ludo. "
202 "The filter matches both the email address and the name."))
204 (td (span (@ (class "filter")) "author:<who>"))
205 (td "Issues where a person named " (strong "who")
206 " has commented, e.g. "
207 (span (@ (class "filter")) "author:rekado")
208 " for all messages where rekado has commented. "
209 "The filter matches both the email address and the name."))
211 (td (span (@ (class "filter")) "date:<start>..<end>"))
212 (td "Issues submitted within the provided range. "
213 (strong "start") " and " (strong "end") " can be one of "
214 (strong "now") ", " (strong "today") ", " (strong "yesterday")
215 ", a date in the formats "
216 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
217 ", or an amount and a unit for a point in the past, such as "
218 (strong "12d") " for 12 days ago. "
219 "Supported units are: "
220 (strong "h") " (hours), "
221 (strong "d") " (days), "
222 (strong "w") " (weeks), "
223 (strong "m") " (months), and "
224 (strong "y") " (years)."))
226 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
227 (td "Issues with comments submitted within the provided
228 range. The supported arguments are the same as for "
229 (span (@ (class "filter")) "date:") "."))))))))
235 (div (@ (class "container"))
236 (h1 "Patch not found")
237 (p "There is no submission with id " (strong ,id
))
238 (p (a (@ (href "/")) "Try another one?"))))))
240 (define (error-page message
)
244 (div (@ (class "container"))
246 (p "An error occurred. Sorry about that!")
248 (p (a (@ (href "/")) "Try something else?"))))))
250 (define (issue-page bug
)
251 "Render the conversation for the given BUG."
252 (define id
(bug-num bug
))
253 (define messages
(patch-messages id
))
254 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
255 (participants messages
))
257 (string< (extract-email a
)
258 (extract-email b
)))))
259 (define (show-message message previous-subject
)
262 (a (@ (id ,(number->string
(email-msg-num message
)))))
264 (@ (class "avatar col-md-1")
265 (style ,(string-append "background-color:"
266 (avatar-color (sender-email message
)
267 (map extract-email parties
)))))
268 ,(string-upcase (string-take (sender-name message
) 1)))
270 (@ (class "message col-md-11"))
272 (@ (class "panel panel-default"))
274 (@ (class "panel-heading"))
277 (span (@ (class "address")) ,(sender-name message
))
279 (span (@ (class "date"))
280 (a (@ (href ,(string-append "#" (number->string
281 (email-msg-num message
)))))
283 ,@(if (string-suffix? previous-subject
(subject message
))
285 `((div (@ (class "subject")) ,(subject message
))))
287 (@ (class "details"))
289 (@ (class "recipients"))
290 (label "Recipients:")
291 ,(map (lambda (address)
292 `(span (@ (class "address")) ,address
))
293 (recipients message
)))
295 (@ (class "message-id"))
296 (label "Message-ID:")
297 ,(message-id message
))))
299 (@ (class "body panel-body"))
300 ,(display-message-body id message
)))))
301 ,@(if (closing? message id
)
303 (@ (class "row event"))
305 (@ (class "col-md-offset-1 col-md-11 text-center"))
306 (div (@ (class "label label-primary closed")) "Closed"))))
309 #:title
(bug-subject bug
)
313 ;; Tell browser to cache this for 12 hours.
314 '((cache-control .
((max-age .
43200)))))
316 ;; Tell browser to cache this for 1 hour.
317 '((cache-control .
((max-age .
3600)))))
322 (@ (class "container"))
324 (@ (class "row title col-md-12"))
325 (h1 ,(bug-subject bug
))
326 (span (@ (class "details"))
328 ,(string-append "Submitted by "
329 ;; We don't use bug-originator here
330 ;; because it includes the email address.
331 ;; We cannot use extract-name on the
332 ;; return value, because it swallows
333 ;; non-ASCII characters.
334 (sender-name (first messages
))
339 (@ (class "conversation col-md-9"))
340 ,(let ((msgs (filter (lambda (msg)
343 ;; internal messages.
344 (and (email-body msg
)
345 (not (internal-message? msg
))))
347 (map (lambda (msg previous-subject
)
348 (show-message msg previous-subject
))
350 (cons (bug-subject bug
)
351 (map subject msgs
))))
353 (@ (class "row comment-box"))
354 (a (@ (id "comment")))
356 (@ (class "avatar col-md-1")
357 (style "background-color:#bc80bd")) "?")
359 (@ (class "message col-md-11"))
361 (@ (class "panel panel-default"))
363 (@ (class "panel-heading"))
364 (div (@ (class "from"))
365 (span (@ (class "address")) "Your comment")))
367 (@ (class "body panel-body"))
368 (p "Comments via the web interface are not currently
369 supported. To comment on this conversation "
370 (a (@ (href ,(string-append "mailto:"
371 (number->string id
) "@" (%config
'debbugs-domain
)
372 "?subject=" (bug-subject bug
))))
373 ,(string-append "send email to "
374 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
377 (@ (class "info col-md-3"))
380 ,@(let ((num (length parties
)))
381 `((label ,(if (= num
1)
383 (string-append (number->string num
)
385 (ul ,(map (lambda (name)
386 `(li (span (@ (class "name")))
388 (map extract-name parties
))))))
392 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
400 ,(status-tag bug
))))))))
402 (define (list-of-bugs bugs
)
403 "Return a table of BUGS."
405 `(p "Nothing to see here. "
407 "Look for something else?"))
408 `(table (@ (class "table-condensed"))
412 (th "Date submitted")
416 (let ((id (number->string
(bug-num bug
))))
420 `(a (@ (href ,(string-append "/issue/" id
)))
423 (td ,(date->string
(bug-date bug
)))
424 (td ,(status-tag bug
)))))
427 (define (list-of-matching-bugs query bugs
)
431 (div (@ (class "container"))
433 `((h1 "No issues found")
434 (p "We could not find any issues matching your query "
437 "Try searching for something else?")))
438 `((h1 "Submissions matching " (code ,query
))
439 ,(list-of-bugs bugs
)))))))