1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2016, 2017, 2018 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2018 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
(srfi srfi-1
)
26 #:use-module
(srfi srfi-19
)
32 list-of-matching-bugs
))
34 (define (status-tag bug
)
35 "Return a colored tag indicating the BUG status."
36 (let ((status (if (bug-done bug
) "Done" "Open")))
37 `(span (@ (class ,(string-append "status-tag "
38 (string-downcase status
))))
41 (define* (layout #:key
44 (title "Guix issue tracker")
46 `(#:sxml
((doctype "html")
50 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
51 (meta (@ (http-equiv "Content-Language") (content "en")))
52 (meta (@ (name "author") (content "Ricardo Wurmus")))
53 (meta (@ (name "viewport")
54 (content "width=device-width, initial-scale=1")))
59 (href "/css/reset.css")))
64 (href "/css/bootstrap.css")))
70 (href "/css/screen.css")))
75 (href "/css/code.css"))))
77 #:extra-headers
,extra-headers
))
79 (define* (search-form #:key
(standalone?
#f
))
80 `(form (@ (id "search")
83 '(class "navbar-form navbar-right"))
86 (@ (class ,(if standalone?
87 "input-group input-group-lg"
89 (input (@ (type "text")
90 (class "form-control")
93 (placeholder "input search query")))
94 (span (@ (class "input-group-btn"))
97 (class ,(string-append (if standalone?
"btn-lg " "")
101 (define* (header #:key
(search-bar?
#t
))
103 (@ (id "header") (class "navbar navbar-default"))
105 (@ (class "container-fluid"))
107 (@ (class "navbar-header"))
108 (div (@ (class "navbar-brand"))
109 (a (@ (href "/") (class "logo"))
110 (img (@ (src "/img/logo.png")
111 (alt "Guix patch tracker"))))))
119 '((cache-control .
((max-age .
60))))
121 `(,(header #:search-bar?
#f
)
123 (@ (class "container"))
124 (h1 "Guix patch tracker")
126 "This is a web frontend to the Guix patch tracker. Send email to "
127 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
128 ,(%config
'submission-email-address
))
129 " to submit your patches.")
130 ,(search-form #:standalone?
#t
)
134 (@ (class "panel panel-default"))
135 (p (@ (class "panel-body"))
137 "Refine your search with filters like "
138 (span (@ (class "filter"))
141 (span (@ (class "filter"))
144 (span (@ (class "filter"))
147 (span (@ (class "filter"))
148 "date:yesterday..now")
150 (span (@ (class "filter"))
151 "date:2018-04-01..2018-04-02")
153 (span (@ (class "filter"))
156 (span (@ (class "filter"))
159 (a (@ (href "help#search"))
161 ;; TODO: do this via JS?
162 ,@(let ((bugs (recent-bugs 5)))
165 `((h2 "Recent activity")
166 ,(list-of-bugs bugs
))))))))
171 ;; Cache for 24 hours.
172 '((cache-control .
((max-age .
86400))))
174 `(,(header #:search-bar?
#f
)
176 (@ (class "container"))
178 (a (@ (href "search")))
179 (p "You can improve the search results by making use of the
180 simple query language. Here is a list of supported query terms with
186 (th (@ (class "col-md-3")) "Filter")
187 (th (@ (class "col-md-9")) "Description")))
190 (td (span (@ (class "filter")) "is:open") ", "
191 (span (@ (class "filter")) "is:pending"))
194 (td (span (@ (class "filter")) "is:closed") ", "
195 (span (@ (class "filter")) "is:done"))
196 (td "Issues marked as done."))
198 (td (span (@ (class "filter")) "submitter:<who>"))
199 (td "Issues submitted by a person named " (strong "who")
201 (span (@ (class "filter")) "submitter:ludo")
202 " for all issues submitted by ludo. "
203 "The filter matches both the email address and the name."))
205 (td (span (@ (class "filter")) "author:<who>"))
206 (td "Issues where a person named " (strong "who")
207 " has commented, e.g. "
208 (span (@ (class "filter")) "author:rekado")
209 " for all messages where rekado has commented. "
210 "The filter matches both the email address and the name."))
212 (td (span (@ (class "filter")) "date:<start>..<end>"))
213 (td "Issues submitted within the provided range. "
214 (strong "start") " and " (strong "end") " can be one of "
215 (strong "now") ", " (strong "today") ", " (strong "yesterday")
216 ", a date in the formats "
217 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
218 ", or an amount and a unit for a point in the past, such as "
219 (strong "12d") " for 12 days ago. "
220 "Supported units are: "
221 (strong "h") " (hours), "
222 (strong "d") " (days), "
223 (strong "w") " (weeks), "
224 (strong "m") " (months), and "
225 (strong "y") " (years)."))
227 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
228 (td "Issues with comments submitted within the provided
229 range. The supported arguments are the same as for "
230 (span (@ (class "filter")) "date:") "."))))))))
236 (div (@ (class "container"))
237 (h1 "Patch not found")
238 (p "There is no submission with id " (strong ,id
))
239 (p (a (@ (href "/")) "Try another one?"))))))
241 (define (error-page message
)
245 (div (@ (class "container"))
247 (p "An error occurred. Sorry about that!")
249 (p (a (@ (href "/")) "Try something else?"))))))
251 (define (issue-page bug
)
252 "Render the conversation for the given BUG."
253 (define id
(bug-num bug
))
254 (define messages
(patch-messages id
))
255 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
256 (participants messages
))
258 (string< (extract-email a
)
259 (extract-email b
)))))
260 (define (show-message message-number message previous-subject
)
263 (a (@ (id ,(number->string message-number
))))
265 (@ (class "avatar col-md-1")
266 (style ,(string-append "background-color:"
267 (avatar-color (sender-email message
)
268 (map extract-email parties
)))))
269 ,(string-upcase (string-take (sender-name message
) 1)))
271 (@ (class "message col-md-11"))
273 (@ (class "panel panel-default"))
275 (@ (class "panel-heading"))
278 (span (@ (class "address")) ,(sender-name message
))
280 (span (@ (class "date"))
281 (a (@ (href ,(string-append "#" (number->string
283 ,(date->string
(date message
)))))
284 ,@(if (string-suffix? previous-subject
(subject message
))
286 `((div (@ (class "subject")) ,(subject message
))))
288 (@ (class "details"))
290 (@ (class "recipients"))
291 (label "Recipients:")
292 ,(map (lambda (address)
293 `(span (@ (class "address")) ,address
))
294 (recipients message
)))
296 (@ (class "message-id"))
297 (label "Message-ID:")
298 ,(message-id message
))))
300 (@ (class "body panel-body"))
301 ,(display-message-body id message-number message
)))))
302 ,@(if (closing? message id
)
304 (@ (class "row event"))
306 (@ (class "col-md-offset-1 col-md-11 text-center"))
307 (div (@ (class "label label-primary closed")) "Closed"))))
310 #:title
(bug-subject bug
)
314 ;; Tell browser to cache this for 12 hours.
315 '((cache-control .
((max-age .
43200)))))
317 ;; Tell browser to cache this for 1 hour.
318 '((cache-control .
((max-age .
3600)))))
323 (@ (class "container"))
325 (@ (class "row title col-md-12"))
326 (h1 ,(bug-subject bug
))
327 (span (@ (class "details"))
329 ,(string-append "Submitted by "
330 ;; We don't use bug-originator here
331 ;; because it includes the email address.
332 ;; We cannot use extract-name on the
333 ;; return value, because it swallows
334 ;; non-ASCII characters.
335 (sender-name (first messages
))
340 (@ (class "conversation col-md-9"))
341 ,(let ((msgs (filter (lambda (msg)
344 ;; internal messages.
345 (and (email-body msg
)
346 (not (internal-message? msg
))))
348 (map (lambda (message-number msg previous-subject
)
349 (show-message message-number msg previous-subject
))
352 (cons (bug-subject bug
)
353 (map subject msgs
))))
355 (@ (class "row comment-box"))
356 (a (@ (id "comment")))
358 (@ (class "avatar col-md-1")
359 (style "background-color:#bc80bd")) "?")
361 (@ (class "message col-md-11"))
363 (@ (class "panel panel-default"))
365 (@ (class "panel-heading"))
366 (div (@ (class "from"))
367 (span (@ (class "address")) "Your comment")))
369 (@ (class "body panel-body"))
370 (p "Comments via the web interface are not currently
371 supported. To comment on this conversation "
372 (a (@ (href ,(string-append "mailto:"
373 (number->string id
) "@" (%config
'debbugs-domain
)
374 "?subject=" (bug-subject bug
))))
375 ,(string-append "send email to "
376 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
379 (@ (class "info col-md-3"))
382 ,@(let ((num (length parties
)))
383 `((label ,(if (= num
1)
385 (string-append (number->string num
)
387 (ul ,(map (lambda (name)
388 `(li (span (@ (class "name")))
390 (map extract-name parties
))))))
394 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
402 ,(status-tag bug
))))))))
404 (define (list-of-bugs bugs
)
405 "Return a table of BUGS."
407 `(p "Nothing to see here. "
409 "Look for something else?"))
410 `(table (@ (class "table-condensed"))
414 (th "Date submitted")
418 (let ((id (number->string
(bug-num bug
))))
422 `(a (@ (href ,(string-append "/issue/" id
)))
425 (td ,(date->string
(bug-date bug
)))
426 (td ,(status-tag bug
)))))
429 (define (list-of-matching-bugs query bugs
)
433 (div (@ (class "container"))
435 `((h1 "No issues found")
436 (p "We could not find any issues matching your query "
439 "Try searching for something else?")))
440 `((h1 "Submissions matching " (code ,query
))
441 ,(list-of-bugs bugs
)))))))