3098bc3ed606df51b527e2360dfbbdc4add5d4e4
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"))))
71 #:extra-headers
,extra-headers
))
73 (define* (search-form #:key
(standalone?
#f
))
74 `(form (@ (id "search")
77 '(class "navbar-form navbar-right"))
80 (@ (class ,(if standalone?
81 "input-group input-group-lg"
83 (input (@ (type "text")
84 (class "form-control")
87 (placeholder "input search query")))
88 (span (@ (class "input-group-btn"))
91 (class ,(string-append (if standalone?
"btn-lg " "")
95 (define* (header #:key
(search-bar?
#t
))
97 (@ (id "header") (class "navbar navbar-default"))
99 (@ (class "container-fluid"))
101 (@ (class "navbar-header"))
102 (div (@ (class "navbar-brand"))
103 (a (@ (href "/") (class "logo"))
104 (img (@ (src "/img/logo.png")
105 (alt "Guix patch tracker"))))))
113 '((cache-control .
((max-age .
60))))
115 `(,(header #:search-bar?
#f
)
117 (@ (class "container"))
118 (h1 "Guix patch tracker")
122 (p "This is a web frontend to the Guix patch tracker. Send email to "
123 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
124 ,(%config
'submission-email-address
))
125 " to submit your patches."))
126 ,(search-form #:standalone?
#t
)
127 ;; TODO: do this via JS?
128 ,@(let ((bugs (recent-bugs 5)))
131 `((h2 "Recent activity")
132 ,(list-of-bugs bugs
))))))))
137 ;; Cache for 24 hours.
138 '((cache-control .
((max-age .
86400))))
140 `(,(header #:search-bar?
#f
)
142 (@ (class "container"))
144 (a (@ (href "search")))
145 (p "You can improve the search results by making use of the
146 simple query language. Here is a list of supported query terms with
152 (th (@ (class "col-md-3")) "Filter")
153 (th (@ (class "col-md-9")) "Description")))
156 (td (span (@ (class "filter")) "is:open") ", "
157 (span (@ (class "filter")) "is:pending"))
160 (td (span (@ (class "filter")) "is:closed") ", "
161 (span (@ (class "filter")) "is:done"))
162 (td "Issues marked as done."))
164 (td (span (@ (class "filter")) "submitter:<who>"))
165 (td "Issues submitted by a person named " (strong "who")
167 (span (@ (class "filter")) "author:ludo")
168 " for all issues submitted by ludo. "
169 "The filter matches both the email address and the name."))
171 (td (span (@ (class "filter")) "author:<who>"))
172 (td "Issues where a person named " (strong "who")
173 " has commented, e.g. "
174 (span (@ (class "filter")) "author:rekado")
175 " for all messages where rekado has commented. "
176 "The filter matches both the email address and the name."))
178 (td (span (@ (class "filter")) "date:<start>..<end>"))
179 (td "Issues submitted within the provided range. "
180 (strong "start") " and " (strong "end") " can be one of "
181 (strong "now") ", " (strong "today") ", " (strong "yesterday")
182 ", a date in the formats "
183 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
184 ", or an amount and a unit for a point in the past, such as "
185 (strong "12d") " for 12 days ago. "
186 "Supported units are: "
187 (strong "h") " (hours), "
188 (strong "d") " (days), "
189 (strong "w") " (weeks), "
190 (strong "m") " (months), and "
191 (strong "y") " (years)."))
193 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
194 (td "Issues with comments submitted within the provided
195 range. The supported arguments are the same as for "
196 (span (@ (class "filter")) "date:") "."))))))))
202 (div (@ (class "container"))
203 (h1 "Patch not found")
204 (p "There is no submission with id " (strong ,id
))
205 (p (a (@ (href "/")) "Try another one?"))))))
207 (define (error-page message
)
211 (div (@ (class "container"))
213 (p "An error occurred. Sorry about that!")
215 (p (a (@ (href "/")) "Try something else?"))))))
217 (define (issue-page bug
)
218 "Render the conversation for the given BUG."
219 (define id
(bug-num bug
))
220 (define messages
(patch-messages id
))
221 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
222 (participants messages
))
224 (string< (extract-email a
)
225 (extract-email b
)))))
226 (define (show-message message
)
229 (a (@ (id ,(number->string
(email-msg-num message
)))))
231 (@ (class "avatar col-md-1")
232 (style ,(string-append "background-color:"
233 (avatar-color (sender-email message
)
234 (map extract-email parties
)))))
235 ,(string-upcase (string-take (sender-name message
) 1)))
237 (@ (class "message col-md-11"))
239 (@ (class "panel panel-default"))
241 (@ (class "panel-heading"))
244 (span (@ (class "address")) ,(sender-name message
))
246 (span (@ (class "date"))
247 (a (@ (href ,(string-append "#" (number->string
248 (email-msg-num message
)))))
251 (@ (class "details"))
253 (@ (class "recipients"))
254 (label "Recipients:")
255 ,(map (lambda (address)
256 `(span (@ (class "address")) ,address
))
257 (recipients message
)))
259 (@ (class "message-id"))
260 (label "Message-ID:")
261 ,(message-id message
))))
263 (@ (class "body panel-body"))
264 ,(display-message-body message
)))))
265 ,@(if (closing? message id
)
267 (@ (class "row event"))
269 (@ (class "col-md-offset-1 col-md-11 text-center"))
270 (div (@ (class "label label-primary closed")) "Closed"))))
273 #:title
(bug-subject bug
)
277 ;; Tell browser to cache this for 12 hours.
278 '((cache-control .
((max-age .
43200)))))
280 ;; Tell browser to cache this for 1 hour.
281 '((cache-control .
((max-age .
3600)))))
286 (@ (class "container"))
288 (@ (class "row title col-md-12"))
289 (h1 ,(bug-subject bug
))
290 (span (@ (class "details"))
292 ,(string-append "Submitted by "
293 ;; We don't use bug-originator here
294 ;; because it includes the email address.
295 ;; We cannot use extract-name on the
296 ;; return value, because it swallows
297 ;; non-ASCII characters.
298 (sender-name (first messages
))
303 (@ (class "conversation col-md-9"))
304 ,(map show-message
(filter (lambda (msg)
307 ;; internal messages.
308 (and (email-body msg
)
309 (not (internal-message? msg
))))
312 (@ (class "row comment-box"))
313 (a (@ (id "comment")))
315 (@ (class "avatar col-md-1")
316 (style "background-color:#bc80bd")) "?")
318 (@ (class "message col-md-11"))
320 (@ (class "panel panel-default"))
322 (@ (class "panel-heading"))
323 (div (@ (class "from"))
324 (span (@ (class "address")) "Your comment")))
326 (@ (class "body panel-body"))
327 (p "Comments via the web interface are not currently
328 supported. To comment on this conversation "
329 (a (@ (href ,(string-append "mailto:"
330 (number->string id
) "@" (%config
'debbugs-domain
)
331 "?subject=" (bug-subject bug
))))
332 ,(string-append "send email to "
333 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
336 (@ (class "info col-md-3"))
339 ,@(let ((num (length parties
)))
340 `((label ,(if (= num
1)
342 (string-append (number->string num
)
344 (ul ,(map (lambda (name)
345 `(li (span (@ (class "name")))
347 (map extract-name parties
))))))
351 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
359 ,(status-tag bug
))))))))
361 (define (list-of-bugs bugs
)
362 "Return a table of BUGS."
364 `(p "Nothing to see here. "
366 "Look for something else?"))
367 `(table (@ (class "table-condensed"))
371 (th "Date submitted")
375 (let ((id (number->string
(bug-num bug
))))
379 `(a (@ (href ,(string-append "/issue/" id
)))
382 (td ,(date->string
(bug-date bug
)))
383 (td ,(status-tag bug
)))))
386 (define (list-of-matching-bugs query bugs
)
390 (div (@ (class "container"))
392 `((h1 "No issues found")
393 (p "We could not find any issues matching your query "
396 "Try searching for something else?")))
397 `((h1 "Submissions matching " (code ,query
))
398 ,(list-of-bugs bugs
)))))))