web: begin adapting to new search form, starting with /register
This commit is contained in:
parent
5f9a3aba52
commit
f6ec3a7803
@ -1,4 +1,4 @@
|
|||||||
|
<a#editformlink href onclick="return editformToggle(event)">edit
|
||||||
|
\ | #
|
||||||
<a#addformlink href onclick="return addformToggle(event)">add
|
<a#addformlink href onclick="return addformToggle(event)">add
|
||||||
<a#importformlink href onclick="return importformToggle(event)" style="display:none;">import transactions
|
<a#importformlink href onclick="return importformToggle(event)" style="display:none;">import transactions
|
||||||
\ | #
|
|
||||||
<a#editformlink href onclick="return editformToggle(event)">edit
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
Search:
|
Search:
|
||||||
\ #
|
\ #
|
||||||
<td
|
<td
|
||||||
<input name=a size=100 value=#{a}
|
<input name=q size=100 value=#{q}
|
||||||
\#
|
\#
|
||||||
<td align=right
|
<td align=right
|
||||||
^{stopfiltering}
|
^{stopfiltering}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import Data.Time.Calendar
|
|||||||
import System.FilePath (takeFileName, (</>))
|
import System.FilePath (takeFileName, (</>))
|
||||||
import System.IO.Storage (putValue, getValue)
|
import System.IO.Storage (putValue, getValue)
|
||||||
import Text.Hamlet hiding (hamletFile)
|
import Text.Hamlet hiding (hamletFile)
|
||||||
import Text.ParserCombinators.Parsec hiding (string)
|
import Text.ParserCombinators.Parsec -- hiding (string)
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import Text.RegexPR
|
import Text.RegexPR
|
||||||
import Yesod.Form
|
import Yesod.Form
|
||||||
@ -67,9 +67,9 @@ postJournalR = handlePost
|
|||||||
-- | The main register view, with accounts sidebar.
|
-- | The main register view, with accounts sidebar.
|
||||||
getRegisterR :: Handler RepHtml
|
getRegisterR :: Handler RepHtml
|
||||||
getRegisterR = do
|
getRegisterR = do
|
||||||
vd@VD{opts=opts,fspec=fspec,j=j} <- getViewData
|
vd@VD{opts=opts,fspec=fspec,m=m,j=j} <- getViewData
|
||||||
let sidecontent = balanceReportAsHtml opts vd $ balanceReport opts fspec j
|
let sidecontent = balanceReportAsHtml opts vd $ balanceReport opts fspec $ filterJournalPostings2 m j
|
||||||
maincontent = registerReportAsHtml opts vd $ registerReport opts fspec j
|
maincontent = registerReportAsHtml opts vd $ registerReport opts fspec $ filterJournalPostings2 m j
|
||||||
editform' = editform vd
|
editform' = editform vd
|
||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
setTitle "hledger-web register"
|
setTitle "hledger-web register"
|
||||||
@ -342,19 +342,16 @@ helplink topic label = $(Settings.hamletFile "helplink")
|
|||||||
|
|
||||||
-- | Form controlling journal filtering parameters.
|
-- | Form controlling journal filtering parameters.
|
||||||
filterform :: ViewData -> Hamlet AppRoute
|
filterform :: ViewData -> Hamlet AppRoute
|
||||||
filterform VD{here=here,a=a,p=p} = $(Settings.hamletFile "filterform")
|
filterform VD{here=here,a=a,p=p,q=q} = $(Settings.hamletFile "filterform")
|
||||||
where
|
where
|
||||||
ahelp = helplink "filter-patterns" "?"
|
ahelp = helplink "filter-patterns" "?"
|
||||||
phelp = helplink "period-expressions" "?"
|
phelp = helplink "period-expressions" "?"
|
||||||
filtering = not $ null a
|
filtering = not $ null q
|
||||||
filteringperiod = not $ null p
|
|
||||||
visible = "block" :: String
|
visible = "block" :: String
|
||||||
filteringclass = if filtering then "filtering" else "" :: String
|
filteringclass = if filtering then "filtering" else "" :: String
|
||||||
filteringperiodclass = if filteringperiod then "filtering" else "" :: String
|
filteringperiodclass = "" :: String
|
||||||
stopfiltering = if filtering then $(Settings.hamletFile "filterformclear") else nulltemplate
|
stopfiltering = if filtering then $(Settings.hamletFile "filterformclear") else nulltemplate
|
||||||
where u = (here, if filteringperiod then [("p", pack p)] else [])
|
where u = (here, [])
|
||||||
stopfilteringperiod = if filteringperiod then $(Settings.hamletFile "filterformclear") else nulltemplate
|
|
||||||
where u = (here, if filtering then [("a", pack a)] else [])
|
|
||||||
|
|
||||||
-- | Add transaction form.
|
-- | Add transaction form.
|
||||||
addform :: ViewData -> Hamlet AppRoute
|
addform :: ViewData -> Hamlet AppRoute
|
||||||
@ -401,14 +398,16 @@ journalselect journalfiles = $(Settings.hamletFile "journalselect")
|
|||||||
-- utilities
|
-- utilities
|
||||||
|
|
||||||
nulltemplate :: Hamlet AppRoute
|
nulltemplate :: Hamlet AppRoute
|
||||||
nulltemplate = [hamlet||]
|
nulltemplate = [$hamlet||]
|
||||||
|
|
||||||
-- | A bundle of data useful for handlers and their templates.
|
-- | A bundle of data useful for handlers and their templates.
|
||||||
data ViewData = VD {
|
data ViewData = VD {
|
||||||
opts :: [Opt] -- ^ command-line options at startup
|
opts :: [Opt] -- ^ command-line options at startup
|
||||||
,a :: String -- ^ current a parameter (a hledger account/description filter pattern)
|
,a :: String -- ^ current a (query) parameter
|
||||||
,p :: String -- ^ current p parameter (a hledger period expression)
|
,p :: String -- ^ current p (query) parameter
|
||||||
|
,q :: String -- ^ current q (query) parameter
|
||||||
,fspec :: FilterSpec -- ^ a journal filter specification based on the above
|
,fspec :: FilterSpec -- ^ a journal filter specification based on the above
|
||||||
|
,m :: Matcher -- ^ a search/filter expression based on the above
|
||||||
,j :: Journal -- ^ an up-to-date parsed journal
|
,j :: Journal -- ^ an up-to-date parsed journal
|
||||||
,today :: Day -- ^ the current day
|
,today :: Day -- ^ the current day
|
||||||
,here :: AppRoute -- ^ the current route
|
,here :: AppRoute -- ^ the current route
|
||||||
@ -420,7 +419,9 @@ mkvd = VD {
|
|||||||
opts = []
|
opts = []
|
||||||
,a = ""
|
,a = ""
|
||||||
,p = ""
|
,p = ""
|
||||||
|
,q = ""
|
||||||
,fspec = nullfilterspec
|
,fspec = nullfilterspec
|
||||||
|
,m = MatchOr []
|
||||||
,j = nulljournal
|
,j = nulljournal
|
||||||
,today = ModifiedJulianDay 0
|
,today = ModifiedJulianDay 0
|
||||||
,here = RootR
|
,here = RootR
|
||||||
@ -431,24 +432,23 @@ mkvd = VD {
|
|||||||
getViewData :: Handler ViewData
|
getViewData :: Handler ViewData
|
||||||
getViewData = do
|
getViewData = do
|
||||||
Just here' <- getCurrentRoute
|
Just here' <- getCurrentRoute
|
||||||
(a, p, opts, fspec) <- getCurrentParameters
|
(q, opts, fspec, m) <- getCurrentParameters
|
||||||
(j, err) <- getCurrentJournal opts
|
(j, err) <- getCurrentJournal opts
|
||||||
msg <- getMessageOr err
|
msg <- getMessageOr err
|
||||||
today <- liftIO getCurrentDay
|
today <- liftIO getCurrentDay
|
||||||
return mkvd{opts=opts, a=a, p=p, fspec=fspec, j=j, today=today, here=here', msg=msg}
|
return mkvd{opts=opts, q=q, fspec=fspec, m=m, j=j, today=today, here=here', msg=msg}
|
||||||
where
|
where
|
||||||
-- | Get current report parameters for this request.
|
-- | Get current report parameters for this request.
|
||||||
getCurrentParameters :: Handler (String, String, [Opt], FilterSpec)
|
getCurrentParameters :: Handler (String, [Opt], FilterSpec, Matcher)
|
||||||
getCurrentParameters = do
|
getCurrentParameters = do
|
||||||
app <- getYesod
|
app <- getYesod
|
||||||
t <- liftIO $ getCurrentLocalTime
|
t <- liftIO $ getCurrentLocalTime
|
||||||
a <- fromMaybe "" <$> lookupGetParam "a"
|
q <- unpack `fmap` fromMaybe "" <$> lookupGetParam "q"
|
||||||
p <- fromMaybe "" <$> lookupGetParam "p"
|
let opts = appOpts app -- ++ [Period p']
|
||||||
let (a',p') = (unpack a, unpack p)
|
args = appArgs app -- ++ words' a'
|
||||||
opts = appOpts app ++ [Period p']
|
|
||||||
args = appArgs app ++ words' a'
|
|
||||||
fspec = optsToFilterSpec opts args t
|
fspec = optsToFilterSpec opts args t
|
||||||
return (a', p', opts, fspec)
|
m = parseMatcher q
|
||||||
|
return (q, opts, fspec, m)
|
||||||
|
|
||||||
-- | Update our copy of the journal if the file changed. If there is an
|
-- | Update our copy of the journal if the file changed. If there is an
|
||||||
-- error while reloading, keep the old one and return the error, and set a
|
-- error while reloading, keep the old one and return the error, and set a
|
||||||
@ -465,6 +465,19 @@ getViewData = do
|
|||||||
Left e -> do setMessage $ "error while reading" {- ++ ": " ++ e-}
|
Left e -> do setMessage $ "error while reading" {- ++ ": " ++ e-}
|
||||||
return (j, Just e)
|
return (j, Just e)
|
||||||
|
|
||||||
|
|
||||||
|
parseMatcher :: String -> Matcher
|
||||||
|
parseMatcher s = MatchOr $ map (MatchAcct True) $ words' s
|
||||||
|
|
||||||
|
parseMatcher2 :: String -> Matcher
|
||||||
|
parseMatcher2 s = either (const (MatchOr [])) id $ runParser matcher () "" $ lexmatcher s
|
||||||
|
|
||||||
|
lexmatcher :: String -> [String]
|
||||||
|
lexmatcher s = words' s
|
||||||
|
|
||||||
|
matcher :: GenParser String () Matcher
|
||||||
|
matcher = undefined
|
||||||
|
|
||||||
-- | Get the message set by the last request, or the newer message provided, if any.
|
-- | Get the message set by the last request, or the newer message provided, if any.
|
||||||
getMessageOr :: Maybe String -> Handler (Maybe Html)
|
getMessageOr :: Maybe String -> Handler (Maybe Html)
|
||||||
getMessageOr mnewmsg = do
|
getMessageOr mnewmsg = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user