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")
120 "This is a web frontend to the Guix patch tracker. Send email to "
121 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
122 ,(%config
'submission-email-address
))
123 " to submit your patches.")
124 ,(search-form #:standalone?
#t
)
128 (@ (class "panel panel-default"))
129 (p (@ (class "panel-body"))
131 "Refine your search with filters like "
132 (span (@ (class "filter"))
135 (span (@ (class "filter"))
138 (span (@ (class "filter"))
141 (span (@ (class "filter"))
142 "date:yesterday..now")
144 (span (@ (class "filter"))
145 "date:2018-04-01..2018-04-02")
147 (span (@ (class "filter"))
150 (span (@ (class "filter"))
153 (a (@ (href "help#search"))
155 ;; TODO: do this via JS?
156 ,@(let ((bugs (recent-bugs 5)))
159 `((h2 "Recent activity")
160 ,(list-of-bugs bugs
))))))))
165 ;; Cache for 24 hours.
166 '((cache-control .
((max-age .
86400))))
168 `(,(header #:search-bar?
#f
)
170 (@ (class "container"))
172 (a (@ (href "search")))
173 (p "You can improve the search results by making use of the
174 simple query language. Here is a list of supported query terms with
180 (th (@ (class "col-md-3")) "Filter")
181 (th (@ (class "col-md-9")) "Description")))
184 (td (span (@ (class "filter")) "is:open") ", "
185 (span (@ (class "filter")) "is:pending"))
188 (td (span (@ (class "filter")) "is:closed") ", "
189 (span (@ (class "filter")) "is:done"))
190 (td "Issues marked as done."))
192 (td (span (@ (class "filter")) "submitter:<who>"))
193 (td "Issues submitted by a person named " (strong "who")
195 (span (@ (class "filter")) "author:ludo")
196 " for all issues submitted by ludo. "
197 "The filter matches both the email address and the name."))
199 (td (span (@ (class "filter")) "author:<who>"))
200 (td "Issues where a person named " (strong "who")
201 " has commented, e.g. "
202 (span (@ (class "filter")) "author:rekado")
203 " for all messages where rekado has commented. "
204 "The filter matches both the email address and the name."))
206 (td (span (@ (class "filter")) "date:<start>..<end>"))
207 (td "Issues submitted within the provided range. "
208 (strong "start") " and " (strong "end") " can be one of "
209 (strong "now") ", " (strong "today") ", " (strong "yesterday")
210 ", a date in the formats "
211 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
212 ", or an amount and a unit for a point in the past, such as "
213 (strong "12d") " for 12 days ago. "
214 "Supported units are: "
215 (strong "h") " (hours), "
216 (strong "d") " (days), "
217 (strong "w") " (weeks), "
218 (strong "m") " (months), and "
219 (strong "y") " (years)."))
221 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
222 (td "Issues with comments submitted within the provided
223 range. The supported arguments are the same as for "
224 (span (@ (class "filter")) "date:") "."))))))))
230 (div (@ (class "container"))
231 (h1 "Patch not found")
232 (p "There is no submission with id " (strong ,id
))
233 (p (a (@ (href "/")) "Try another one?"))))))
235 (define (error-page message
)
239 (div (@ (class "container"))
241 (p "An error occurred. Sorry about that!")
243 (p (a (@ (href "/")) "Try something else?"))))))
245 (define (issue-page bug
)
246 "Render the conversation for the given BUG."
247 (define id
(bug-num bug
))
248 (define messages
(patch-messages id
))
249 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
250 (participants messages
))
252 (string< (extract-email a
)
253 (extract-email b
)))))
254 (define (show-message message
)
257 (a (@ (id ,(number->string
(email-msg-num message
)))))
259 (@ (class "avatar col-md-1")
260 (style ,(string-append "background-color:"
261 (avatar-color (sender-email message
)
262 (map extract-email parties
)))))
263 ,(string-upcase (string-take (sender-name message
) 1)))
265 (@ (class "message col-md-11"))
267 (@ (class "panel panel-default"))
269 (@ (class "panel-heading"))
272 (span (@ (class "address")) ,(sender-name message
))
274 (span (@ (class "date"))
275 (a (@ (href ,(string-append "#" (number->string
276 (email-msg-num message
)))))
279 (@ (class "details"))
281 (@ (class "recipients"))
282 (label "Recipients:")
283 ,(map (lambda (address)
284 `(span (@ (class "address")) ,address
))
285 (recipients message
)))
287 (@ (class "message-id"))
288 (label "Message-ID:")
289 ,(message-id message
))))
291 (@ (class "body panel-body"))
292 ,(display-message-body id message
)))))
293 ,@(if (closing? message id
)
295 (@ (class "row event"))
297 (@ (class "col-md-offset-1 col-md-11 text-center"))
298 (div (@ (class "label label-primary closed")) "Closed"))))
301 #:title
(bug-subject bug
)
305 ;; Tell browser to cache this for 12 hours.
306 '((cache-control .
((max-age .
43200)))))
308 ;; Tell browser to cache this for 1 hour.
309 '((cache-control .
((max-age .
3600)))))
314 (@ (class "container"))
316 (@ (class "row title col-md-12"))
317 (h1 ,(bug-subject bug
))
318 (span (@ (class "details"))
320 ,(string-append "Submitted by "
321 ;; We don't use bug-originator here
322 ;; because it includes the email address.
323 ;; We cannot use extract-name on the
324 ;; return value, because it swallows
325 ;; non-ASCII characters.
326 (sender-name (first messages
))
331 (@ (class "conversation col-md-9"))
332 ,(map show-message
(filter (lambda (msg)
335 ;; internal messages.
336 (and (email-body msg
)
337 (not (internal-message? msg
))))
340 (@ (class "row comment-box"))
341 (a (@ (id "comment")))
343 (@ (class "avatar col-md-1")
344 (style "background-color:#bc80bd")) "?")
346 (@ (class "message col-md-11"))
348 (@ (class "panel panel-default"))
350 (@ (class "panel-heading"))
351 (div (@ (class "from"))
352 (span (@ (class "address")) "Your comment")))
354 (@ (class "body panel-body"))
355 (p "Comments via the web interface are not currently
356 supported. To comment on this conversation "
357 (a (@ (href ,(string-append "mailto:"
358 (number->string id
) "@" (%config
'debbugs-domain
)
359 "?subject=" (bug-subject bug
))))
360 ,(string-append "send email to "
361 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
364 (@ (class "info col-md-3"))
367 ,@(let ((num (length parties
)))
368 `((label ,(if (= num
1)
370 (string-append (number->string num
)
372 (ul ,(map (lambda (name)
373 `(li (span (@ (class "name")))
375 (map extract-name parties
))))))
379 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
387 ,(status-tag bug
))))))))
389 (define (list-of-bugs bugs
)
390 "Return a table of BUGS."
392 `(p "Nothing to see here. "
394 "Look for something else?"))
395 `(table (@ (class "table-condensed"))
399 (th "Date submitted")
403 (let ((id (number->string
(bug-num bug
))))
407 `(a (@ (href ,(string-append "/issue/" id
)))
410 (td ,(date->string
(bug-date bug
)))
411 (td ,(status-tag bug
)))))
414 (define (list-of-matching-bugs query bugs
)
418 (div (@ (class "container"))
420 `((h1 "No issues found")
421 (p "We could not find any issues matching your query "
424 "Try searching for something else?")))
425 `((h1 "Submissions matching " (code ,query
))
426 ,(list-of-bugs bugs
)))))))