web: comment unused handlers
This commit is contained in:
parent
ebe0ee184c
commit
a1aff10225
@ -6,12 +6,11 @@ import Import
|
||||
|
||||
import Control.Applicative
|
||||
import Data.Either (lefts,rights)
|
||||
import Data.List (intercalate, sort)
|
||||
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 Text.Parsec (digit, eof, many1, string, runParser)
|
||||
import Text.Printf (printf)
|
||||
|
||||
import Hledger.Utils
|
||||
import Hledger.Data hiding (num)
|
||||
@ -24,8 +23,8 @@ handlePost :: Handler Html
|
||||
handlePost = do
|
||||
action <- lookupPostParam "action"
|
||||
case action of Just "add" -> handleAdd
|
||||
Just "edit" -> handleEdit
|
||||
Just "import" -> handleImport
|
||||
-- Just "edit" -> handleEdit
|
||||
-- Just "import" -> handleImport
|
||||
_ -> invalidArgs ["invalid action"]
|
||||
|
||||
-- | Handle a post from the transaction add form.
|
||||
@ -130,68 +129,68 @@ handleAdd = do
|
||||
-- ^{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"
|
||||
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` 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
|
||||
-- handleEdit = do
|
||||
-- VD{..} <- getViewData
|
||||
-- -- get form input values, or validation errors.
|
||||
-- -- getRequest >>= liftIO (reqRequestBody req) >>= mtrace
|
||||
-- mtext <- lookupPostParam "text"
|
||||
-- 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` 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
|
||||
|
||||
else do
|
||||
-- try to avoid unnecessary backups or saving invalid data
|
||||
filechanged' <- liftIO $ journalSpecifiedFileIsNewer j journalpath
|
||||
told <- liftIO $ readFileStrictly journalpath
|
||||
let tnew = filter (/= '\r') text
|
||||
changed = tnew /= told || filechanged'
|
||||
if not changed
|
||||
then do
|
||||
setMessage "No change"
|
||||
redirect JournalR
|
||||
else do
|
||||
jE <- liftIO $ readJournal Nothing Nothing True (Just journalpath) tnew
|
||||
either
|
||||
(\e -> do
|
||||
setMessage $ toHtml e
|
||||
redirect JournalR)
|
||||
(const $ do
|
||||
liftIO $ writeFileWithBackup journalpath tnew
|
||||
setMessage $ toHtml (printf "Saved journal %s\n" (show journalpath) :: String)
|
||||
redirect JournalR)
|
||||
jE
|
||||
-- else do
|
||||
-- -- try to avoid unnecessary backups or saving invalid data
|
||||
-- filechanged' <- liftIO $ journalSpecifiedFileIsNewer j journalpath
|
||||
-- told <- liftIO $ readFileStrictly journalpath
|
||||
-- let tnew = filter (/= '\r') text
|
||||
-- changed = tnew /= told || filechanged'
|
||||
-- if not changed
|
||||
-- then do
|
||||
-- setMessage "No change"
|
||||
-- redirect JournalR
|
||||
-- else do
|
||||
-- jE <- liftIO $ readJournal Nothing Nothing True (Just journalpath) tnew
|
||||
-- either
|
||||
-- (\e -> do
|
||||
-- setMessage $ toHtml e
|
||||
-- redirect JournalR)
|
||||
-- (const $ do
|
||||
-- liftIO $ writeFileWithBackup journalpath tnew
|
||||
-- setMessage $ toHtml (printf "Saved journal %s\n" (show journalpath) :: String)
|
||||
-- redirect JournalR)
|
||||
-- jE
|
||||
|
||||
-- | Handle a post from the journal import form.
|
||||
handleImport :: Handler Html
|
||||
handleImport = do
|
||||
setMessage "can't handle file upload yet"
|
||||
redirect JournalR
|
||||
-- -- get form input values, or basic validation errors. E means an Either value.
|
||||
-- fileM <- runFormPost $ maybeFileInput "file"
|
||||
-- let fileE = maybe (Left "No file provided") Right fileM
|
||||
-- -- display errors or import transactions
|
||||
-- case fileE of
|
||||
-- Left errs -> do
|
||||
-- setMessage errs
|
||||
-- redirect JournalR
|
||||
-- -- | Handle a post from the journal import form.
|
||||
-- handleImport :: Handler Html
|
||||
-- handleImport = do
|
||||
-- setMessage "can't handle file upload yet"
|
||||
-- redirect JournalR
|
||||
-- -- -- get form input values, or basic validation errors. E means an Either value.
|
||||
-- -- fileM <- runFormPost $ maybeFileInput "file"
|
||||
-- -- let fileE = maybe (Left "No file provided") Right fileM
|
||||
-- -- -- display errors or import transactions
|
||||
-- -- case fileE of
|
||||
-- -- Left errs -> do
|
||||
-- -- setMessage errs
|
||||
-- -- redirect JournalR
|
||||
|
||||
-- Right s -> do
|
||||
-- setMessage s
|
||||
-- redirect JournalR
|
||||
-- -- Right s -> do
|
||||
-- -- setMessage s
|
||||
-- -- redirect JournalR
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user