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
(srfi srfi-1
)
26 #:use-module
(srfi srfi-19
)
36 (define (status-tag bug
)
37 "Return a colored tag indicating the BUG status."
38 (let ((status (if (bug-done bug
) "Done" "Open")))
39 `(span (@ (class ,(string-append "status-tag "
40 (string-downcase status
))))
43 (define* (layout #:key
46 (title "Guix issue tracker")
48 `(#:sxml
((doctype "html")
52 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
53 (meta (@ (http-equiv "Content-Language") (content "en")))
54 (meta (@ (name "author") (content "Ricardo Wurmus")))
55 (meta (@ (name "viewport")
56 (content "width=device-width, initial-scale=1")))
61 (href "/css/reset.css")))
66 (href "/css/bootstrap.css")))
72 (href "/css/screen.css")))
77 (href "/css/code.css"))))
79 #:extra-headers
,extra-headers
))
81 (define* (search-form #:key
(standalone?
#f
))
82 `(form (@ (id "search")
85 '(class "navbar-form navbar-right"))
88 (@ (class ,(if standalone?
89 "input-group input-group-lg"
91 (input (@ (type "text")
92 (class "form-control")
95 (placeholder "input search query")))
96 (span (@ (class "input-group-btn"))
99 (class ,(string-append (if standalone?
"btn-lg " "")
103 (define* (header #:key
(search-bar?
#t
))
105 (@ (id "header") (class "navbar navbar-default"))
107 (@ (class "container-fluid"))
109 (@ (class "navbar-header"))
110 (div (@ (class "navbar-brand"))
111 (a (@ (href "/") (class "logo")))))
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 (h2 "Recent activity")
162 (div (@ (id "snippet-recent"))
163 (img (@ (src "/img/spin.gif"))))
165 (div (@ (id "snippet-priority"))
166 (img (@ (src "/img/spin.gif"))))
168 (@ (type "text/javascript")
169 (src "/js/mumi.js")))))))
174 ;; Cache for 24 hours.
175 '((cache-control .
((max-age .
86400))))
177 `(,(header #:search-bar?
#f
)
179 (@ (class "container"))
181 (a (@ (href "search")))
182 (p "You can improve the search results by making use of the
183 simple query language. Here is a list of supported query terms with
189 (th (@ (class "col-md-3")) "Filter")
190 (th (@ (class "col-md-9")) "Description")))
193 (td (span (@ (class "filter")) "is:open") ", "
194 (span (@ (class "filter")) "is:pending"))
197 (td (span (@ (class "filter")) "is:closed") ", "
198 (span (@ (class "filter")) "is:done"))
199 (td "Issues marked as done."))
201 (td (span (@ (class "filter")) "submitter:<who>"))
202 (td "Issues submitted by a person named " (strong "who")
204 (span (@ (class "filter")) "submitter:ludo")
205 " for all issues submitted by ludo. "
206 "The filter matches both the email address and the name."))
208 (td (span (@ (class "filter")) "author:<who>"))
209 (td "Issues where a person named " (strong "who")
210 " has commented, e.g. "
211 (span (@ (class "filter")) "author:rekado")
212 " for all messages where rekado has commented. "
213 "The filter matches both the email address and the name."))
215 (td (span (@ (class "filter")) "date:<start>..<end>"))
216 (td "Issues submitted within the provided range. "
217 (strong "start") " and " (strong "end") " can be one of "
218 (strong "now") ", " (strong "today") ", " (strong "yesterday")
219 ", a date in the formats "
220 (strong "YYYY-MM-DD") " or " (strong "YYYYMMDD")
221 ", or an amount and a unit for a point in the past, such as "
222 (strong "12d") " for 12 days ago. "
223 "Supported units are: "
224 (strong "h") " (hours), "
225 (strong "d") " (days), "
226 (strong "w") " (weeks), "
227 (strong "m") " (months), and "
228 (strong "y") " (years)."))
230 (td (span (@ (class "filter")) "mdate:<start>..<end>"))
231 (td "Issues with comments submitted within the provided
232 range. The supported arguments are the same as for "
233 (span (@ (class "filter")) "date:") "."))))))))
239 (div (@ (class "container"))
240 (h1 "Patch not found")
241 (p "There is no submission with id " (strong ,id
))
242 (p (a (@ (href "/")) "Try another one?"))))))
244 (define (error-page message
)
248 (div (@ (class "container"))
250 (p "An error occurred. Sorry about that!")
252 (p (a (@ (href "/")) "Try something else?"))))))
254 (define (issue-page bug
)
255 "Render the conversation for the given BUG."
256 (define id
(bug-num bug
))
257 (define messages
(patch-messages id
))
258 (define parties
(sort (filter (compose (negate bot?
) extract-email
)
259 (participants messages
))
261 (string< (extract-email a
)
262 (extract-email b
)))))
263 (define (show-message message-number message previous-subject
)
266 (a (@ (id ,(number->string message-number
))))
268 (@ (class "avatar col-md-1")
269 (style ,(string-append "background-color:"
270 (avatar-color (sender-email message
)
271 (map extract-email parties
)))))
272 ,(string-upcase (string-take (sender-name message
) 1)))
274 (@ (class "message col-md-11"))
276 (@ (class "panel panel-default"))
278 (@ (class "panel-heading"))
281 (span (@ (class "address")) ,(sender-name message
))
283 (span (@ (class "date"))
284 (a (@ (href ,(string-append "#" (number->string
286 ,(date->string
(date message
)))))
287 ,@(if (or (string-suffix?
(or previous-subject
"")
288 (or (subject message
) ""))
289 (not (subject message
)))
291 `((div (@ (class "subject")) ,(subject message
))))
293 (@ (class "details"))
295 (@ (class "recipients"))
296 (label "Recipients:")
297 ,(map (lambda (address)
298 `(span (@ (class "address")) ,address
))
299 (recipients message
)))
301 (@ (class "message-id"))
302 (label "Message-ID:")
303 ,(message-id message
))))
305 (@ (class "body panel-body"))
306 ,(display-message-body id message-number message
)))))
307 ,@(if (closing? message id
)
309 (@ (class "row event"))
311 (@ (class "col-md-offset-1 col-md-11 text-center"))
312 (div (@ (class "label label-primary closed")) "Closed"))))
315 #:title
(bug-subject bug
)
319 ;; Tell browser to cache this for 12 hours.
320 '((cache-control .
((max-age .
43200)))))
322 ;; Tell browser to cache this for 1 hour.
323 '((cache-control .
((max-age .
3600)))))
328 (@ (class "container"))
330 (@ (class "row title col-md-12"))
331 (h1 ,(bug-subject bug
))
332 (span (@ (class "details"))
334 ,(string-append "Submitted by "
335 ;; We don't use bug-originator here
336 ;; because it includes the email address.
337 ;; We cannot use extract-name on the
338 ;; return value, because it swallows
339 ;; non-ASCII characters.
340 (sender-name (first messages
))
342 ,@(if (bug-mergedwith bug
)
343 `((ul (@ (class "merged"))
346 `(li (a (@ (href ,(string-append "/issue/" id
)))
348 (string-split (bug-mergedwith bug
) #\space
))))
353 (@ (class "conversation col-md-9"))
354 ,(let ((msgs (filter (lambda (msg)
357 ;; internal messages.
358 (and (email-body msg
)
359 (not (internal-message? msg
))))
361 (map (lambda (message-number msg previous-subject
)
362 (show-message message-number msg previous-subject
))
365 (cons (bug-subject bug
)
366 (map subject msgs
))))
368 (@ (class "row comment-box"))
369 (a (@ (id "comment")))
371 (@ (class "avatar col-md-1")
372 (style "background-color:#bc80bd")) "?")
374 (@ (class "message col-md-11"))
376 (@ (class "panel panel-default"))
378 (@ (class "panel-heading"))
379 (div (@ (class "from"))
380 (span (@ (class "address")) "Your comment")))
382 (@ (class "body panel-body"))
383 (p "Comments via the web interface are not currently
384 supported. To comment on this conversation "
385 (a (@ (href ,(string-append "mailto:"
386 (number->string id
) "@" (%config
'debbugs-domain
)
387 "?subject=" (bug-subject bug
))))
388 ,(string-append "send email to "
389 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
392 (@ (class "info col-md-3"))
395 ,@(let ((num (length parties
)))
396 `((label ,(if (= num
1)
398 (string-append (number->string num
)
400 (ul ,(map (lambda (name)
401 `(li (span (@ (class "name")))
403 (map extract-name parties
))))))
407 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
415 ,(status-tag bug
))))))))
417 (define (list-of-bugs bugs
)
418 "Return a table of BUGS."
420 `(p "Nothing to see here. "
422 "Look for something else?"))
423 `(table (@ (class "table-condensed"))
427 (th "Date submitted")
431 (let ((id (number->string
(bug-num bug
))))
432 `(tr (@ (class ,(bug-severity bug
)))
435 `(a (@ (href ,(string-append "/issue/" id
)))
438 (td ,(date->string
(bug-date bug
)))
439 (td ,(status-tag bug
)))))
442 (define (priority-bugs)
447 (bugs-by-severity "serious" "open")
448 (bugs-by-severity "important" "open"))
449 (lambda (a b
) (< (bug-num a
) (bug-num b
)))))))
451 (define (list-of-matching-bugs query bugs
)
455 (div (@ (class "container"))
457 `((h1 "No issues found")
458 (p "We could not find any issues matching your query "
461 "Try searching for something else?")))
462 `((h1 "Submissions matching " (code ,query
))
463 ,(list-of-bugs bugs
)))))))