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
)
30 list-of-matching-bugs
))
32 (define (status-tag bug
)
33 "Return a colored tag indicating the BUG status."
34 (let ((status (if (bug-done bug
) "Done" "Open")))
35 `(span (@ (class ,(string-append "status-tag "
36 (string-downcase status
))))
39 (define* (layout #:key
42 (title "Guix issue tracker")
44 `(#:sxml
((doctype "html")
48 (meta (@ (http-equiv "Content-Type") (content "text/html; charset=UTF-8")))
49 (meta (@ (http-equiv "Content-Language") (content "en")))
50 (meta (@ (name "author") (content "Ricardo Wurmus")))
51 (meta (@ (name "viewport")
52 (content "width=device-width, initial-scale=1")))
57 (href "/css/reset.css")))
62 (href "/css/bootstrap.css")))
68 (href "/css/screen.css"))))
70 #:extra-headers
,extra-headers
))
72 (define* (search-form #:key
(standalone?
#f
))
73 `(form (@ (id "search")
76 '(class "navbar-form navbar-right"))
79 (@ (class ,(if standalone?
80 "input-group input-group-lg"
82 (input (@ (type "text")
83 (class "form-control")
86 (placeholder "input search query")))
87 (span (@ (class "input-group-btn"))
90 (class ,(string-append (if standalone?
"btn-lg " "")
94 (define* (header #:key
(search-bar?
#t
))
96 (@ (id "header") (class "navbar navbar-default"))
98 (@ (class "container-fluid"))
100 (@ (class "navbar-header"))
101 (div (@ (class "navbar-brand"))
102 (a (@ (href "/") (class "logo"))
103 (img (@ (src "/img/logo.png")
104 (alt "Guix patch tracker"))))))
112 '((cache-control .
((max-age .
60))))
114 `(,(header #:search-bar?
#f
)
116 (@ (class "container"))
117 (h1 "Guix patch tracker")
121 (p "This is a web frontend to the Guix patch tracker. Send email to "
122 (a (@ (href ,(string-append "mailto:" (%config
'submission-email-address
))))
123 ,(%config
'submission-email-address
))
124 " to submit your patches."))
125 ,(search-form #:standalone?
#t
)
126 ;; TODO: do this via JS?
127 ,@(let ((bugs (recent-bugs 5)))
130 `((h2 "Recent activity")
131 ,(list-of-bugs bugs
))))))))
137 (div (@ (class "container"))
138 (h1 "Patch not found")
139 (p "There is no submission with id " (strong ,id
))
140 (p (a (@ (href "/")) "Try another one?"))))))
142 (define (error-page message
)
146 (div (@ (class "container"))
148 (p "An error occurred. Sorry about that!")
150 (p (a (@ (href "/")) "Try something else?"))))))
152 (define (issue-page bug
)
153 "Render the conversation for the given BUG."
154 (define id
(bug-num bug
))
155 (define messages
(patch-messages id
))
156 (define parties
(filter (compose (negate bot?
) extract-email
)
157 (participants messages
)))
158 (define (show-message message
)
161 (a (@ (id ,(number->string
(email-msg-num message
)))))
163 (@ (class "avatar col-md-1")
164 (style ,(string-append "background-color:"
165 (avatar-color (sender-email message
)
166 (map extract-email parties
)))))
167 ,(string-upcase (string-take (sender-name message
) 1)))
169 (@ (class "message col-md-11"))
171 (@ (class "panel panel-default"))
173 (@ (class "panel-heading"))
176 (span (@ (class "address")) ,(sender-name message
))
178 (span (@ (class "date"))
179 (a (@ (href ,(string-append "#" (number->string
180 (email-msg-num message
)))))
183 (@ (class "details"))
185 (@ (class "recipients"))
186 (label "Recipients:")
187 ,(map (lambda (address)
188 `(span (@ (class "address")) ,address
))
189 (recipients message
)))
191 (@ (class "message-id"))
192 (label "Message-ID:")
193 ,(message-id message
))))
195 (@ (class "body panel-body"))
196 ,(display-message-body message
)))))
197 ,@(if (closing? message id
)
199 (@ (class "row event"))
201 (@ (class "col-md-offset-1 col-md-11 text-center"))
202 (div (@ (class "label label-primary closed")) "Closed"))))
205 #:title
(bug-subject bug
)
209 ;; Tell browser to cache this for 12 hours.
210 '((cache-control .
((max-age .
43200)))))
212 ;; Tell browser to cache this for 1 hour.
213 '((cache-control .
((max-age .
3600)))))
218 (@ (class "container"))
220 (@ (class "row title col-md-12"))
221 (h1 ,(bug-subject bug
))
222 (span (@ (class "details"))
224 ,(string-append "Submitted by "
225 ;; We don't use bug-originator here
226 ;; because it includes the email address.
227 ;; We cannot use extract-name on the
228 ;; return value, because it swallows
229 ;; non-ASCII characters.
230 (sender-name (first messages
))
235 (@ (class "conversation col-md-9"))
236 ,(map show-message
(filter (lambda (msg)
239 ;; internal messages.
240 (and (email-body msg
)
241 (not (internal-message? msg
))))
244 (@ (class "row comment-box"))
245 (a (@ (id "comment")))
247 (@ (class "avatar col-md-1")
248 (style "background-color:#bc80bd")) "?")
250 (@ (class "message col-md-11"))
252 (@ (class "panel panel-default"))
254 (@ (class "panel-heading"))
255 (div (@ (class "from"))
256 (span (@ (class "address")) "Your comment")))
258 (@ (class "body panel-body"))
259 (p "Comments via the web interface are not currently
260 supported. To comment on this conversation "
261 (a (@ (href ,(string-append "mailto:"
262 (number->string id
) "@" (%config
'debbugs-domain
)
263 "?subject=" (bug-subject bug
))))
264 ,(string-append "send email to "
265 (number->string id
) "@" (%config
'debbugs-domain
)))))))))
268 (@ (class "info col-md-3"))
271 ,@(let ((num (length parties
)))
272 `((label ,(if (= num
1)
274 (string-append (number->string num
)
276 (ul ,(map (lambda (name)
277 `(li (span (@ (class "name")))
279 (map extract-name parties
))))))
283 ,(or (and=> (bug-owner bug
) extract-name
) "unassigned"))
291 ,(status-tag bug
))))))))
293 (define (list-of-bugs bugs
)
294 "Return a table of BUGS."
296 `(p "Nothing to see here. "
298 "Look for something else?"))
299 `(table (@ (class "table-condensed"))
303 (th "Date submitted")
307 (let ((id (number->string
(bug-num bug
))))
311 `(a (@ (href ,(string-append "/issue/" id
)))
314 (td ,(date->string
(bug-date bug
)))
315 (td ,(status-tag bug
)))))
318 (define (list-of-matching-bugs query bugs
)
322 (div (@ (class "container"))
324 `((h1 "No issues found")
325 (p "We could not find any issues matching your query "
328 "Try searching for something else?")))
329 `((h1 "Submissions matching " (code ,query
))
330 ,(list-of-bugs bugs
)))))))