add a search form
This commit is contained in:
parent
e5f6952286
commit
08a3d43c39
@ -51,24 +51,30 @@ web opts args l = do
|
|||||||
killThread tid
|
killThread tid
|
||||||
putStrLn "shutdown complete"
|
putStrLn "shutdown complete"
|
||||||
|
|
||||||
template = "<div align=center style=width:100%%>" ++
|
template r = printf (
|
||||||
" <a href=print>ledger</a>" ++
|
"<div style=float:right>" ++
|
||||||
" | <a href=register>register</a>" ++
|
"<form action=%s>search: <input name=a value=%s></form>" ++
|
||||||
" | <a href=balance>balance</a>" ++
|
"</div>" ++
|
||||||
"</div>" ++
|
"<div align=center style=width:100%%%%>" ++
|
||||||
"<pre>%s</pre>"
|
" <a href=print>ledger</a>" ++
|
||||||
|
" | <a href=register>register</a>" ++
|
||||||
|
" | <a href=balance>balance</a>" ++
|
||||||
|
"</div>" ++
|
||||||
|
"<pre>%%s</pre>")
|
||||||
|
(dropWhile (=='/') $ rqUri r)
|
||||||
|
(fromMaybe "" $ queryValue "a" r)
|
||||||
|
|
||||||
type Handler = ServerPart Response
|
type Handler = ServerPart Response
|
||||||
|
|
||||||
handlers :: [Opt] -> [String] -> Ledger -> [Handler]
|
handlers :: [Opt] -> [String] -> Ledger -> [Handler]
|
||||||
handlers opts args l =
|
handlers opts args l =
|
||||||
[
|
[
|
||||||
dir "print" [withRequest $ \r -> respond $ printreport r]
|
dir "print" [withRequest $ \r -> respond r $ printreport r]
|
||||||
, dir "register" [withRequest $ \r -> respond $ registerreport r]
|
, dir "register" [withRequest $ \r -> respond r $ registerreport r]
|
||||||
, dir "balance" [withRequest $ \r -> respond $ balancereport r]
|
, dir "balance" [withRequest $ \r -> respond r $ balancereport r]
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
respond = ok . setContentType "text/html" . toResponse . (printf template :: String -> String)
|
respond r = ok . setContentType "text/html" . toResponse . (printf (template r) :: String -> String)
|
||||||
printreport r = showEntries opts (pats r ++ args) l
|
printreport r = showEntries opts (pats r ++ args) l
|
||||||
registerreport r = showRegisterReport opts (pats r ++ args) l
|
registerreport r = showRegisterReport opts (pats r ++ args) l
|
||||||
balancereport r = showBalanceReport (opts++[SubTotal]) (pats r ++ args) l
|
balancereport r = showBalanceReport (opts++[SubTotal]) (pats r ++ args) l
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user