aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Income/Table.hs
diff options
context:
space:
mode:
authorJoris2021-01-03 13:40:40 +0100
committerJoris2021-01-03 13:54:20 +0100
commit11052951b74b9ad4b6a9412ae490086235f9154b (patch)
tree64526ac926c1bf470ea113f6cac8a33158684e8d /client/src/View/Income/Table.hs
parent371449b0e312a03162b78797b83dee9d81706669 (diff)
downloadbudget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.gz
budget-11052951b74b9ad4b6a9412ae490086235f9154b.tar.bz2
budget-11052951b74b9ad4b6a9412ae490086235f9154b.zip
Rewrite in Rust
Diffstat (limited to 'client/src/View/Income/Table.hs')
-rw-r--r--client/src/View/Income/Table.hs93
1 files changed, 0 insertions, 93 deletions
diff --git a/client/src/View/Income/Table.hs b/client/src/View/Income/Table.hs
deleted file mode 100644
index 7b7940d..0000000
--- a/client/src/View/Income/Table.hs
+++ /dev/null
@@ -1,93 +0,0 @@
-module View.Income.Table
- ( view
- , In(..)
- , Out(..)
- ) where
-
-import qualified Data.Maybe as Maybe
-import Data.Text (Text)
-import qualified Data.Text as T
-import Reflex.Dom (Dynamic, Event, MonadWidget)
-import qualified Reflex.Dom as R
-
-import Common.Model (Currency, Income (..), User (..),
- UserId)
-import qualified Common.Model as CM
-import qualified Common.Msg as Msg
-import qualified Common.View.Format as Format
-
-import qualified Component.ConfirmDialog as ConfirmDialog
-import qualified Component.Table as Table
-import qualified Util.Ajax as Ajax
-import qualified Util.Either as EitherUtil
-import qualified View.Income.Form as Form
-
-data In t = In
- { _in_currentUser :: UserId
- , _in_currency :: Currency
- , _in_incomes :: [Income]
- , _in_users :: [User]
- }
-
-data Out t = Out
- { _out_add :: Event t ()
- , _out_edit :: Event t ()
- , _out_delete :: Event t ()
- }
-
-view :: forall t m. MonadWidget t m => In t -> m (Out t)
-view input = do
-
- table <- Table.view $ Table.In
- { Table._in_headerLabel = headerLabel
- , Table._in_rows = _in_incomes input
- , Table._in_cell = cell (_in_users input) (_in_currency input)
- , Table._in_cloneModal = \income ->
- Form.view $ Form.In
- { Form._in_operation = Form.Clone income
- }
- , Table._in_editModal = \income ->
- Form.view $ Form.In
- { Form._in_operation = Form.Edit income
- }
- , Table._in_deleteModal = \income ->
- ConfirmDialog.view $ ConfirmDialog.In
- { ConfirmDialog._in_header = Msg.get Msg.Income_DeleteConfirm
- , ConfirmDialog._in_confirm = \e -> do
- res <- Ajax.delete
- (R.constDyn $ T.concat ["/api/income/", T.pack . show $ _income_id income])
- e
- return $ () <$ R.fmapMaybe EitherUtil.eitherToMaybe res
- }
- , Table._in_canEdit = (== (_in_currentUser input)) . _income_userId
- , Table._in_canDelete = (== (_in_currentUser input)) . _income_userId
- }
-
- return $ Out
- { _out_add = Table._out_add table
- , _out_edit = Table._out_edit table
- , _out_delete = Table._out_delete table
- }
-
-data Header
- = UserHeader
- | AmountHeader
- | DateHeader
- deriving (Eq, Show, Bounded, Enum)
-
-headerLabel :: Header -> Text
-headerLabel UserHeader = Msg.get Msg.Income_Name
-headerLabel DateHeader = Msg.get Msg.Income_Date
-headerLabel AmountHeader = Msg.get Msg.Income_Amount
-
-cell :: forall t m. MonadWidget t m => [User] -> Currency -> Header -> Income -> m ()
-cell users currency header income =
- case header of
- UserHeader ->
- R.text . Maybe.fromMaybe "" . fmap _user_name $ CM.findUser (_income_userId income) users
-
- DateHeader ->
- R.text . Format.longDay . _income_date $ income
-
- AmountHeader ->
- R.text . Format.price currency . _income_amount $ income