From 3c67fcf1d524811a18f0c4db3ef6eed1270b9a12 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 17 Nov 2019 19:55:22 +0100 Subject: Hide date from monthly payments --- client/src/View/Payment/Form.hs | 51 +++++++++++++++++++---------------- client/src/View/Payment/HeaderForm.hs | 20 ++++++++------ client/src/View/Payment/Payment.hs | 3 ++- client/src/View/Payment/Table.hs | 40 ++++++++++++++++----------- 4 files changed, 67 insertions(+), 47 deletions(-) (limited to 'client/src/View/Payment') diff --git a/client/src/View/Payment/Form.hs b/client/src/View/Payment/Form.hs index 6c3c1e8..99dce13 100644 --- a/client/src/View/Payment/Form.hs +++ b/client/src/View/Payment/Form.hs @@ -43,10 +43,11 @@ import qualified Util.Validation as ValidationUtil data In t = In { _in_categories :: [Category] , _in_operation :: Operation t + , _in_frequency :: Frequency } data Operation t - = New (Dynamic t Frequency) + = New | Clone Payment | Edit Payment @@ -92,18 +93,23 @@ view input cancel = do (cost <$ reset) confirm) - d <- date - - date <- Input._out_raw <$> (Input.view - (Input.defaultIn - { Input._in_label = Msg.get Msg.Payment_Date - , Input._in_initialValue = d - , Input._in_inputType = "date" - , Input._in_hasResetButton = False - , Input._in_validation = PaymentValidation.date - }) - (d <$ reset) - confirm) + currentDate <- date + + date <- + case frequency of + Punctual -> do + Input._out_raw <$> (Input.view + (Input.defaultIn + { Input._in_label = Msg.get Msg.Payment_Date + , Input._in_initialValue = currentDate + , Input._in_inputType = "date" + , Input._in_hasResetButton = False + , Input._in_validation = PaymentValidation.date + }) + (currentDate <$ reset) + confirm) + Monthly -> + return . R.constDyn $ currentDate setCategory <- R.debounce (1 :: NominalDiffTime) (R.updated $ Input._out_raw name) @@ -125,13 +131,12 @@ view input cancel = do c <- cost d <- date cat <- category - f <- frequency return (mkPayload <$> ValidationUtil.nelError n <*> V.Success c <*> V.Success d <*> ValidationUtil.nelError cat - <*> V.Success f) + <*> V.Success frequency) frequencies = M.fromList @@ -144,7 +149,7 @@ view input cancel = do category = case op of - New _ -> -1 + New -> -1 Clone p -> _payment_category p Edit p -> _payment_category p @@ -152,13 +157,13 @@ view input cancel = do name = case op of - New _ -> "" + New -> "" Clone p -> _payment_name p Edit p -> _payment_name p cost = case op of - New _ -> "" + New -> "" Clone p -> T.pack . show . _payment_cost $ p Edit p -> T.pack . show . _payment_cost $ p @@ -166,19 +171,19 @@ view input cancel = do currentDay <- liftIO $ Clock.getCurrentTime >>= TimeUtil.timeToDay return . T.pack . Calendar.showGregorian $ case op of - New _ -> currentDay + New -> currentDay Clone p -> currentDay Edit p -> _payment_date p frequency = case op of - New f -> f - Clone p -> R.constDyn $ _payment_frequency p - Edit p -> R.constDyn $ _payment_frequency p + New -> _in_frequency input + Clone p -> _payment_frequency p + Edit p -> _payment_frequency p headerLabel = case op of - New _ -> Msg.get Msg.Payment_Add + New -> Msg.get Msg.Payment_Add Clone _ -> Msg.get Msg.Payment_CloneLong Edit _ -> Msg.get Msg.Payment_EditLong diff --git a/client/src/View/Payment/HeaderForm.hs b/client/src/View/Payment/HeaderForm.hs index c8ca4d9..0ee0cd3 100644 --- a/client/src/View/Payment/HeaderForm.hs +++ b/client/src/View/Payment/HeaderForm.hs @@ -18,6 +18,7 @@ import qualified Component.Button as Button import qualified Component.Input as Input import qualified Component.Modal as Modal import qualified Component.Select as Select +import qualified Util.Reflex as ReflexUtil import qualified View.Payment.Form as Form data In t = In @@ -65,14 +66,17 @@ view input = { Button._in_class = R.constDyn "addPayment" }) - addPayment <- Modal.view $ Modal.In - { Modal._in_show = addPaymentButton - , Modal._in_content = - Form.view $ Form.In - { Form._in_categories = _in_categories input - , Form._in_operation = Form.New frequency - } - } + addPayment <- + (R.dyn . R.ffor frequency $ \frequency -> + Modal.view $ Modal.In + { Modal._in_show = addPaymentButton + , Modal._in_content = + Form.view $ Form.In + { Form._in_categories = _in_categories input + , Form._in_operation = Form.New + , Form._in_frequency = frequency + } + }) >>= ReflexUtil.flatten return $ Out { _out_search = R.updated searchName diff --git a/client/src/View/Payment/Payment.hs b/client/src/View/Payment/Payment.hs index 6bc1614..a34d2f4 100644 --- a/client/src/View/Payment/Payment.hs +++ b/client/src/View/Payment/Payment.hs @@ -70,7 +70,7 @@ view input = do } result <- R.dyn . R.ffor payments $ - Loadable.view $ \(PaymentPage page header payments count) -> do + Loadable.view $ \(PaymentPage page frequency header payments count) -> do HeaderInfos.view $ HeaderInfos.In { HeaderInfos._in_users = _in_users input @@ -85,6 +85,7 @@ view input = do , Table._in_categories = categories , Table._in_currency = _in_currency input , Table._in_payments = payments + , Table._in_frequency = frequency } pages <- Pages.view $ Pages.In diff --git a/client/src/View/Payment/Table.hs b/client/src/View/Payment/Table.hs index 59ac890..f9215bc 100644 --- a/client/src/View/Payment/Table.hs +++ b/client/src/View/Payment/Table.hs @@ -12,7 +12,8 @@ import qualified Data.Text as T import Reflex.Dom (Dynamic, Event, MonadWidget) import qualified Reflex.Dom as R -import Common.Model (Category (..), Currency, Payment (..), +import Common.Model (Category (..), Currency, + Frequency (..), Payment (..), User (..), UserId) import qualified Common.Model as CM import qualified Common.Msg as Msg @@ -30,6 +31,7 @@ data In t = In , _in_categories :: [Category] , _in_currency :: Currency , _in_payments :: [Payment] + , _in_frequency :: Frequency } data Out t = Out @@ -42,22 +44,25 @@ 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_headerLabel = headerLabel (_in_frequency input) , Table._in_rows = reverse . L.sortOn _payment_date $ _in_payments input , Table._in_cell = cell (_in_users input) (_in_categories input) + (_in_frequency input) (_in_currency input) , Table._in_cloneModal = \payment -> Form.view $ Form.In { Form._in_categories = _in_categories input , Form._in_operation = Form.Clone payment + , Form._in_frequency = _in_frequency input } , Table._in_editModal = \payment -> Form.view $ Form.In { Form._in_categories = _in_categories input , Form._in_operation = Form.Edit payment + , Form._in_frequency = _in_frequency input } , Table._in_deleteModal = \payment -> ConfirmDialog.view $ ConfirmDialog.In @@ -85,22 +90,24 @@ data Header | DateHeader deriving (Eq, Show, Bounded, Enum) -headerLabel :: Header -> Text -headerLabel NameHeader = Msg.get Msg.Payment_Name -headerLabel CostHeader = Msg.get Msg.Payment_Cost -headerLabel UserHeader = Msg.get Msg.Payment_User -headerLabel CategoryHeader = Msg.get Msg.Payment_Category -headerLabel DateHeader = Msg.get Msg.Payment_Date +headerLabel :: Frequency -> Header -> Text +headerLabel _ NameHeader = Msg.get Msg.Payment_Name +headerLabel _ CostHeader = Msg.get Msg.Payment_Cost +headerLabel _ UserHeader = Msg.get Msg.Payment_User +headerLabel _ CategoryHeader = Msg.get Msg.Payment_Category +headerLabel Punctual DateHeader = Msg.get Msg.Payment_Date +headerLabel Monthly DateHeader = "" cell :: forall t m. MonadWidget t m => [User] -> [Category] + -> Frequency -> Currency -> Header -> Payment -> m () -cell users categories currency header payment = +cell users categories frequency currency header payment = case header of NameHeader -> R.text $ _payment_name payment @@ -132,9 +139,12 @@ cell users categories currency header payment = Maybe.fromMaybe "" (_category_name <$> category) DateHeader -> - do - R.elClass "span" "shortDate" $ - R.text . Format.shortDay . _payment_date $ payment - - R.elClass "span" "longDate" $ - R.text . Format.longDay . _payment_date $ payment + if frequency == Punctual then + do + R.elClass "span" "shortDate" $ + R.text . Format.shortDay . _payment_date $ payment + + R.elClass "span" "longDate" $ + R.text . Format.longDay . _payment_date $ payment + else + R.blank -- cgit v1.2.3