Using urlparams appropriately.

This commit is contained in:
michael 2010-07-06 03:36:08 +00:00
parent 6f555e02af
commit ea5f7979b2

View File

@ -110,10 +110,11 @@ withLatestJournalRender reportfn = do
app <- getYesod
params <- getParams
t <- liftIO $ getCurrentLocalTime
let as = params "a"
ps = params "p"
opts = appOpts app ++ [Period $ unwords ps]
args = appArgs app ++ as
let head' x = if null x then "" else head x
as = head' $ params "a"
ps = head' $ params "p"
opts = appOpts app ++ [Period ps]
args = appArgs app ++ [as]
fspec = optsToFilterSpec opts args t
-- reload journal if changed
j <- liftIO $ fromJust `fmap` getValue "hledger" "journal"
@ -125,11 +126,13 @@ withLatestJournalRender reportfn = do
req <- getRequest
msg <- getMessage
--return $ RepHtml $ toContent $ renderHamlet id $ template req msg as ps "hledger" s
hamletToRepHtml $ template req msg as ps "hledger" s
Just here <- getRoute
hamletToRepHtml $ template here req msg as ps "hledger" s
template :: Request -> Maybe (Html ()) -> [String] -> [String]
template :: HledgerWebAppRoutes
-> Request -> Maybe (Html ()) -> String -> String
-> String -> String -> Hamlet HledgerWebAppRoutes
template req msg as ps title content = [$hamlet|
template here req msg as ps title content = [$hamlet|
!!!
%html
%head
@ -144,13 +147,13 @@ template req msg as ps title content = [$hamlet|
%pre $string.content$
|]
where m = fromMaybe (string "") msg
navbar' = navbar req as ps
navbar' = navbar here req as ps
addform' = addform req as ps
stylesheet = StyleCss
metacontent = "text/html; charset=utf-8"
navbar :: Request -> [String] -> [String] -> Hamlet HledgerWebAppRoutes
navbar req as ps = [$hamlet|
navbar :: HledgerWebAppRoutes -> Request -> String -> String -> Hamlet HledgerWebAppRoutes
navbar here req as ps = [$hamlet|
#navbar
%a#hledgerorglink!href=$string.hledgerurl$ hledger.org
^navlinks'^
@ -158,9 +161,9 @@ navbar req as ps = [$hamlet|
%a#helplink!href=$string.manualurl$ help
|]
where navlinks' = navlinks req as ps
searchform' = searchform req as ps
searchform' = searchform here req as ps
navlinks :: Request -> [String] -> [String] -> Hamlet HledgerWebAppRoutes
navlinks :: Request -> String -> String -> Hamlet HledgerWebAppRoutes
navlinks _ as ps = [$hamlet|
#navlinks
^transactionslink^ | $
@ -168,14 +171,15 @@ navlinks _ as ps = [$hamlet|
^balancelink^
|]
where
transactionslink = navlink "transactions"
registerlink = navlink "register"
balancelink = navlink "balance"
navlink s = [$hamlet|%a.navlink!href=$string.u$ $string.s$|]
where u = printf "../%s?a=%s&p=%s" s (intercalate "+" as) (intercalate "+" ps) -- FIXME use URL params instead
transactionslink = navlink "transactions" TransactionsPage
registerlink = navlink "register" RegisterPage
balancelink = navlink "balance" BalancePage
navlink s dest = [$hamlet|%a.navlink!href=@?u@ $string.s$|]
where u = (dest, [("a", as), ("p", ps)])
searchform :: Request -> [String] -> [String] -> Hamlet HledgerWebAppRoutes
searchform req as ps = [$hamlet|
searchform :: HledgerWebAppRoutes
-> Request -> String -> String -> Hamlet HledgerWebAppRoutes
searchform here req a p = [$hamlet|
%form#searchform!action=$string.action$
search for: $
%input!name=a!size=20!value=$string.a$
@ -188,20 +192,17 @@ searchform req as ps = [$hamlet|
|]
where
action=""
a = intercalate "+" as
p = intercalate "+" ps
ahelp = helplink "filter-patterns"
phelp = helplink "period-expressions"
resetlink
| null a && null p = [$hamlet||]
| otherwise = [$hamlet|%span#resetlink $
%a!href=$string.u$ reset|]
where u = B.unpack $ Network.Wai.pathInfo $ waiRequest req -- FIXME I'd be worried about this line
%a!href=@here@ reset|]
helplink topic = [$hamlet|%a!href=$string.u$ ?|]
where u = manualurl ++ if null topic then "" else '#':topic
addform :: Request -> [String] -> [String] -> Hamlet HledgerWebAppRoutes
addform :: Request -> String -> String -> Hamlet HledgerWebAppRoutes
addform _ _ _ = [$hamlet|
%form#addform!action=$string.action$!method=POST
%table!border=0