web: Post -> AddForm; drop/comment more old stuff

This commit is contained in:
Simon Michael 2015-02-16 16:21:07 +00:00
parent a1aff10225
commit 55967e9192
7 changed files with 84 additions and 117 deletions

View File

@ -1,6 +1,6 @@
-- | POST helpers.
module Handler.Post where
module Handler.AddForm where
import Import
@ -10,6 +10,7 @@ import Data.List (sort)
import qualified Data.List as L (head) -- qualified keeps dev & prod builds warning-free
import Data.Text (unpack)
import qualified Data.Text as T
import Data.Time.Calendar
import Text.Parsec (digit, eof, many1, string, runParser)
import Hledger.Utils
@ -18,20 +19,11 @@ import Hledger.Read
import Hledger.Cli hiding (num)
-- | Handle a post from any of the edit forms.
handlePost :: Handler Html
handlePost = do
action <- lookupPostParam "action"
case action of Just "add" -> handleAdd
-- Just "edit" -> handleEdit
-- Just "import" -> handleImport
_ -> invalidArgs ["invalid action"]
-- | Handle a post from the transaction add form.
handleAdd :: Handler Html
handleAdd = do
postAddForm :: Handler Html
postAddForm = do
VD{..} <- getViewData
-- XXX gruesome form handling, port to yesod-form later
-- XXX gruesome form handling, port to yesod-form. cf #234
mjournalpath <- lookupPostParam "journal"
mdate <- lookupPostParam "date"
mdesc <- lookupPostParam "description"
@ -46,7 +38,9 @@ handleAdd = do
)
mjournalpath
estrs = [edate, edesc, ejournalpath]
(errs1, [date,desc,journalpath]) = (lefts estrs, rights estrs)
(errs1, [date, desc, journalpath]) = case (lefts estrs, rights estrs) of
([], [_,_,_]) -> ([], rights estrs)
_ -> (lefts estrs, [error "",error "",error ""]) -- RHS won't be used
(params,_) <- runRequestBody
-- mtrace params
let paramnamep s = do {string s; n <- many1 digit; eof; return (read n :: Int)}
@ -97,37 +91,32 @@ handleAdd = do
redirect (JournalR) -- , [("add","1")])
-- personForm :: Html -> MForm Handler (FormResult Person, Widget)
-- personForm extra = do
-- (nameRes, nameView) <- mreq textField "this is not used" Nothing
-- (ageRes, ageView) <- mreq intField "neither is this" Nothing
-- let personRes = Person <$> nameRes <*> ageRes
-- let widget = do
-- toWidget
-- [lucius|
-- ##{fvId ageView} {
-- width: 3em;
-- }
-- |]
-- [whamlet|
-- #{extra}
-- <p>
-- Hello, my name is #
-- ^{fvInput nameView}
-- \ and I am #
-- ^{fvInput ageView}
-- \ years old. #
-- <input type=submit value="Introduce myself">
-- |]
-- return (personRes, widget)
--
-- ((res, widget), enctype) <- runFormGet personForm
-- defaultLayout
-- [whamlet|
-- <p>Result: #{show res}
-- <form enctype=#{enctype}>
-- ^{widget}
-- |]
-- -- | Handle a post from the journal edit form.
-- handleEdit :: Handler Html
-- handleEdit = do
-- VD{..} <- getViewData
-- -- get form input values, or validation errors.
-- -- getRequest >>= liftIO (reqRequestBody req) >>= mtrace
-- mtext <- lookupPostParam "text"
-- mtrace "--------------------------"
-- mtrace (journalFilePaths j)
-- mjournalpath <- lookupPostParam "journal"
-- let etext = maybe (Left "No value provided") (Right . unpack) mtext
-- ejournalpath = maybe
-- (Right $ journalFilePath j)
-- (\f -> let f' = unpack f in
-- if f' `elem` dbg0 "paths2" (journalFilePaths j)
-- then Right f'
-- else Left ("unrecognised journal file path"::String))
-- mjournalpath
-- estrs = [etext, ejournalpath]
-- errs = lefts estrs
-- [text,journalpath] = rights estrs
-- -- display errors or perform edit
-- if not $ null errs
-- then do
-- setMessage $ toHtml (intercalate "; " errs :: String)
-- redirect JournalR
-- -- | Handle a post from the journal edit form.
-- handleEdit :: Handler Html

View File

@ -120,51 +120,51 @@ searchform VD{..} = [hamlet|
where
filtering = not $ null q
-- | Edit journal form.
editform :: ViewData -> HtmlUrl AppRoute
editform VD{..} = [hamlet|
<form#editform method=POST style=display:none;>
<h2#contenttitle>#{title}>
<table.form>
$if manyfiles
<tr>
<td colspan=2>
Editing ^{journalselect $ files j}
<tr>
<td colspan=2>
<!-- XXX textarea ids are unquoted journal file paths here, not valid html -->
$forall f <- files j
<textarea id=#{fst f}_textarea name=text rows=25 cols=80 style=display:none; disabled=disabled>
\#{snd f}
<tr#addbuttonrow>
<td>
<span.help>^{formathelp}
<td align=right>
<span.help>
Are you sure ? This will overwrite the journal. #
<input type=hidden name=action value=edit>
<input type=submit name=submit value="save journal">
\ or #
<a href="#" onclick="return editformToggle(event)">cancel
|]
where
title = "Edit journal" :: String
manyfiles = length (files j) > 1
formathelp = helplink "file-format" "file format help"
-- -- | Edit journal form.
-- editform :: ViewData -> HtmlUrl AppRoute
-- editform VD{..} = [hamlet|
-- <form#editform method=POST style=display:none;>
-- <h2#contenttitle>#{title}>
-- <table.form>
-- $if manyfiles
-- <tr>
-- <td colspan=2>
-- Editing ^{journalselect $ files j}
-- <tr>
-- <td colspan=2>
-- <!-- XXX textarea ids are unquoted journal file paths here, not valid html -->
-- $forall f <- files j
-- <textarea id=#{fst f}_textarea name=text rows=25 cols=80 style=display:none; disabled=disabled>
-- \#{snd f}
-- <tr#addbuttonrow>
-- <td>
-- <span.help>^{formathelp}
-- <td align=right>
-- <span.help>
-- Are you sure ? This will overwrite the journal. #
-- <input type=hidden name=action value=edit>
-- <input type=submit name=submit value="save journal">
-- \ or #
-- <a href="#" onclick="return editformToggle(event)">cancel
-- |]
-- where
-- title = "Edit journal" :: String
-- manyfiles = length (files j) > 1
-- formathelp = helplink "file-format" "file format help"
-- | Import journal form.
importform :: HtmlUrl AppRoute
importform = [hamlet|
<form#importform method=POST style=display:none;>
<table.form>
<tr>
<td>
<input type=file name=file>
<input type=hidden name=action value=import>
<input type=submit name=submit value="import from file">
\ or #
<a href="#" onclick="return importformToggle(event)">cancel
|]
-- -- | Import journal form.
-- importform :: HtmlUrl AppRoute
-- importform = [hamlet|
-- <form#importform method=POST style=display:none;>
-- <table.form>
-- <tr>
-- <td>
-- <input type=file name=file>
-- <input type=hidden name=action value=import>
-- <input type=submit name=submit value="import from file">
-- \ or #
-- <a href="#" onclick="return importformToggle(event)">cancel
-- |]
-- | Link to a topic in the manual.
helplink :: String -> String -> HtmlUrl AppRoute

View File

@ -1,20 +0,0 @@
-- | /journal/edit handlers.
module Handler.JournalEditR where
import Import
import Handler.Common
import Handler.Post
-- | The journal editform, no sidebar.
getJournalEditR :: Handler Html
getJournalEditR = do
vd <- getViewData
defaultLayout $ do
setTitle "hledger-web journal edit form"
toWidget $ editform vd
postJournalEditR :: Handler Html
postJournalEditR = handlePost

View File

@ -4,8 +4,8 @@ module Handler.JournalR where
import Import
import Handler.AddForm
import Handler.Common
import Handler.Post
import Hledger.Data
import Hledger.Query
@ -38,7 +38,7 @@ getJournalR = do
|]
postJournalR :: Handler Html
postJournalR = handlePost
postJournalR = postAddForm
-- | Render a "TransactionsReport" as html for the formatted journal view.
journalTransactionsReportAsHtml :: WebOpts -> ViewData -> TransactionsReport -> HtmlUrl AppRoute

View File

@ -8,8 +8,8 @@ import Data.List
import Data.Maybe
import Safe
import Handler.AddForm
import Handler.Common
import Handler.Post
import Handler.Utils
import Hledger.Data
@ -40,7 +40,7 @@ getRegisterR = do
|]
postRegisterR :: Handler Html
postRegisterR = handlePost
postRegisterR = postAddForm
-- Generate html for an account register, including a balance chart and transaction list.
registerReportHtml :: WebOpts -> ViewData -> TransactionsReport -> HtmlUrl AppRoute

View File

@ -5,7 +5,6 @@
/journal JournalR GET POST
/register RegisterR GET POST
/sidebar SidebarR GET
-- /journal/edit JournalEditR GET POST
--
-- /accounts AccountsR GET
-- /api/accounts AccountsJsonR GET

View File

@ -141,10 +141,9 @@ library
Settings
Settings.StaticFiles
Settings.Development
Handler.AddForm
Handler.Common
Handler.JournalEditR
Handler.JournalR
Handler.Post
Handler.RegisterR
Handler.RootR
Handler.SidebarR