Coverage report: /home/samppa/personal/opiskelu/ohtuprojekti/pulsu/trunk/ui.lisp
Kind | Covered | All | % |
expression | 102 | 180 | 56.7 |
branch | 10 | 34 | 29.4 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
4
;; these should probably be somewhere else
5
(setf hunchentoot:*show-lisp-errors-p* t)
6
(setf hunchentoot:*show-lisp-backtraces-p* t)
7
(setf hunchentoot:*hunchentoot-default-external-format*
8
(flex:make-external-format :utf-8))
11
(defun paged-list-of-widgets (list widget current-page page-param
12
&optional (n-per-page 1))
13
(with-html-output (*http-stream*)
15
(when (> (length list) n-per-page)
16
(make-pager current-page
18
(/ (length list) n-per-page)))
19
(mapcar widget (subseq list
20
(* current-page n-per-page)
22
(* (+ current-page 1) n-per-page)))))))
26
(defhtml make-pager (current-page
30
(make-generic-pager-widget
31
number-of-pages current-page
32
(lambda (x &optional (label (+ 1 x)))
33
(with-output-to-string (*http-stream*)
36
(link-here* (format nil " ~A " label)
39
(format nil "<strong>~A</strong>" (+ 1 current-page)))
41
:pages-shown-near-current-page 2
42
:next/previous-labels (list ">>" "<<"))))
45
(defhtml render-case (row)
46
(let ((id (unique-id "hide")))
49
(:em (str (getf row :doc_date)))
50
" " (str (getf row :disease_name)) " " (str (getf row :country))
52
(:div :id id (str "MOI"))))))
55
(defun unique-id (&optional (prefix "id"))
56
(multiple-value-bind (counter present) (aux-request-value :counter)
58
(setf (aux-request-value :counter) 1)
59
(incf (aux-request-value :counter)))
60
(format nil "~A~A" prefix (aux-request-value :counter))))
62
(defun pulsu-make-highlight-pair (name start-index end-index)
63
(make-highlight-pair (format nil "<span class='~A'>" name) "</span>"
68
(defun make-trigger-link (row)
69
(let ((offsets (puls.controller:get-trigger-offsets row))
70
(a (with-output-to-string (*http-stream*)
74
'c (getf row :event_id)))))
76
;;FIXME: this removes indent, but will break if link indent is changed
77
;; yep, be careful with the sequence limits
78
(make-highlight-pair (subseq a 1 (- (length a) 5))
84
(defun make-strong(row)
85
(let ((offsets (puls.controller:get-trigger-offsets row)))
87
(make-highlight-pair "<strong>"
93
(defun highlight-document (text row rows)
95
;; Remove the "current" row
96
(let ((rows (remove (getf row :event_id) rows
101
(list (loop :for a :in (puls.controller::get-attrs)
104
(listp (attr-offsets a))
105
(puls.controller:start-index a row)
106
(puls.controller:end-index a row)
107
(> (puls.controller:start-index a row) -1)
108
(> (puls.controller:end-index a row) -1))
110
(pulsu-make-highlight-pair
111
(puls.controller:attr-id a)
112
(puls.controller:start-index a row)
113
(puls.controller:end-index a row)))
117
;; Current case is "strong"
118
(let ((strong (make-strong row)))
122
;; Other cases are links
124
(let ((link (make-trigger-link r)))
129
(highlight-text list text)))
134
(defhtml render-attrs (row)
135
(dolist (attr (puls.controller:get-attrs))
136
(render-attr attr row)))
138
(defhtml render-attr (attr row)
139
(:tr :id (format nil "~A_tr" (attr-id attr))
140
(if (not (equalp (attr-type attr) :plain))
141
(switch-input (attr-id attr))
143
(:td :id (format nil "~A_id_text" (string-downcase(attr-id attr))) (str (attr-desc attr)))
145
(case (puls.controller:attr-type attr)
146
(:plain (str (attr-value attr row)))
149
(:select :name (attr-id attr)
150
:id (format nil "~A_id" (attr-id attr))
151
:onChange "checkAttributes()"
152
(dolist (i (attr-options attr row))
156
(if (string= i (attr-value attr row))
164
:id (format nil "~A_id" (attr-id attr))
166
:value (attr-value attr row))))))))
170
(deftest test-paged ()
171
(check (equal (with-html-output-to-string (*http-stream*)
172
(paged-list-of-widgets (list 1 2 3 4 5 6 7 8 9)
173
(html (x) (:p (str x)))
177
"<span class='pager'>
179
<a href=\"/foo?moicca=1&c=3&b=2&a=1\"> <<
182
<a href=\"/foo?moicca=0&c=3&b=2&a=1\"> 1
185
<a href=\"/foo?moicca=1&c=3&b=2&a=1\"> 2
189
<a href=\"/foo?moicca=3&c=3&b=2&a=1\"> 4
192
<a href=\"/foo?moicca=4&c=3&b=2&a=1\"> 5
195
<a href=\"/foo?moicca=3&c=3&b=2&a=1\"> >>
202
(deftest test-pager ()
203
(check (equal (with-html-output-to-string (*http-stream*)
204
(make-pager 2 'moicca 50))
205
"<span class='pager'>
207
<a href=\"/foo?moicca=1&c=3&b=2&a=1\"> <<
210
<a href=\"/foo?moicca=0&c=3&b=2&a=1\"> 1
213
<a href=\"/foo?moicca=1&c=3&b=2&a=1\"> 2
217
<a href=\"/foo?moicca=3&c=3&b=2&a=1\"> 4
220
<a href=\"/foo?moicca=4&c=3&b=2&a=1\"> 5
224
<a href=\"/foo?moicca=47&c=3&b=2&a=1\"> 48
227
<a href=\"/foo?moicca=48&c=3&b=2&a=1\"> 49
230
<a href=\"/foo?moicca=49&c=3&b=2&a=1\"> 50
233
<a href=\"/foo?moicca=3&c=3&b=2&a=1\"> >>
236
(deftest test-pulsu-make-highlight-pair ()
238
(let* ((row (puls.controller:get-event "20050101_bbc_b118e8867977ba4feae312bb5ea17ef4" 1)))
239
(check (equal (write-to-string(pulsu-make-highlight-pair "testi" 0 10))
240
"(#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"<span class='testi'>\" PULS.WEB::INDEX
241
NIL PULS.WEB::BEGIN-OR-END :BEGIN PULS.WEB::OTHER-HALF
242
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</span>\" PULS.WEB::INDEX NIL
243
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))
244
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</span>\" PULS.WEB::INDEX NIL
245
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))"))))
247
(deftest test-make-trigger-link ()
249
(let* ((row (puls.controller:get-event "20050101_bbc_b118e8867977ba4feae312bb5ea17ef4" 1)))
250
(check (equal (write-to-string (make-trigger-link row))
251
"(#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME
252
\"<a href=\\\"/dv?n=20050101_bbc_b118e8867977ba4feae312bb5ea17ef4&c=1\\\">\"
253
PULS.WEB::INDEX 1039 PULS.WEB::BEGIN-OR-END :BEGIN PULS.WEB::OTHER-HALF
254
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</a>\" PULS.WEB::INDEX 1063
255
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))
256
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</a>\" PULS.WEB::INDEX 1063
257
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))"))))
259
(deftest test-make-strong ()
261
(let* ((row (puls.controller:get-event "20050101_bbc_b118e8867977ba4feae312bb5ea17ef4" 1)))
263
(check (equal (write-to-string (make-strong row))
264
"(#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"<strong>\" PULS.WEB::INDEX 1039
265
PULS.WEB::BEGIN-OR-END :BEGIN PULS.WEB::OTHER-HALF
266
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</strong>\" PULS.WEB::INDEX 1063
267
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))
268
#I(PULS.WEB::HIGHLIGHT PULS.WEB::NAME \"</strong>\" PULS.WEB::INDEX 1063
269
PULS.WEB::BEGIN-OR-END :END PULS.WEB::MAGIC-NUMBER NIL))"))))
275
(test-pulsu-make-highlight-pair)
276
(test-make-trigger-link)