diff options
author | Joris | 2017-03-27 10:18:40 +0200 |
---|---|---|
committer | Joris | 2017-03-27 10:18:40 +0200 |
commit | 64ff4707fdcd81c27c6be9903c3c82bc543ef016 (patch) | |
tree | fa0c3a9112f4f7c8bd383ad3e597041ab7d5a503 /src/client/LoggedIn | |
parent | 40273c30166877b3341125ad5248793b2f2fcc64 (diff) |
Modelize punctual and monthly payment pages
Diffstat (limited to 'src/client/LoggedIn')
-rw-r--r-- | src/client/LoggedIn/Home/Header/View.elm | 3 | ||||
-rw-r--r-- | src/client/LoggedIn/Home/Model.elm | 16 | ||||
-rw-r--r-- | src/client/LoggedIn/Home/Msg.elm | 1 | ||||
-rw-r--r-- | src/client/LoggedIn/Home/Update.elm | 31 | ||||
-rw-r--r-- | src/client/LoggedIn/Home/View.elm | 11 | ||||
-rw-r--r-- | src/client/LoggedIn/Home/View/Table.elm | 7 | ||||
-rw-r--r-- | src/client/LoggedIn/Msg.elm | 3 | ||||
-rw-r--r-- | src/client/LoggedIn/Update.elm | 3 |
8 files changed, 49 insertions, 26 deletions
diff --git a/src/client/LoggedIn/Home/Header/View.elm b/src/client/LoggedIn/Home/Header/View.elm index 3f8a320..14d90d7 100644 --- a/src/client/LoggedIn/Home/Header/View.elm +++ b/src/client/LoggedIn/Home/Header/View.elm @@ -21,7 +21,8 @@ import LoggedData exposing (LoggedData) import LoggedIn.Home.Model as Home import Model.Translations exposing (getParamMessage) import Model.Conf exposing (Conf) -import Model.Payment as Payment exposing (Payments, Frequency(..)) +import Model.Payment as Payment exposing (Payments) +import Model.Frequency exposing (Frequency(..)) import Model.Translations exposing (getMessage) import Dialog.AddPayment.Model as AddPayment diff --git a/src/client/LoggedIn/Home/Model.elm b/src/client/LoggedIn/Home/Model.elm index ace1593..e5381f6 100644 --- a/src/client/LoggedIn/Home/Model.elm +++ b/src/client/LoggedIn/Home/Model.elm @@ -7,15 +7,18 @@ module LoggedIn.Home.Model exposing ) import Form exposing (Form) -import Form.Validate as Validate exposing (Validation) import Form.Field as Field exposing (Field) +import Form.Validate as Validate exposing (Validation) -import Model.User exposing (Users, UserId) -import Model.Payment as Payment exposing (PaymentId, Payments, Frequency(..)) +import Model.Frequency as Frequency import Model.Payer exposing (Payers) +import Model.Payment as Payment exposing (PaymentId, Payments) +import Model.Frequency exposing (Frequency(..)) +import Model.User exposing (Users, UserId) type alias Model = - { currentPage : Int + { punctualPage : Int + , monthlyPage : Int , search : Form String Search } @@ -26,7 +29,8 @@ type alias Search = init : Model init = - { currentPage = 1 + { punctualPage = 1 + , monthlyPage = 1 , search = Form.initial (searchInitial Punctual) validation } @@ -37,4 +41,4 @@ validation : Validation String Search validation = Validate.map2 Search (Validate.field "name" (Validate.maybe Validate.string)) - (Validate.field "frequency" Payment.validateFrequency) + (Validate.field "frequency" Frequency.validate) diff --git a/src/client/LoggedIn/Home/Msg.elm b/src/client/LoggedIn/Home/Msg.elm index b5f2566..69f15ad 100644 --- a/src/client/LoggedIn/Home/Msg.elm +++ b/src/client/LoggedIn/Home/Msg.elm @@ -5,6 +5,7 @@ module LoggedIn.Home.Msg exposing import Form exposing (Form) import Model.Payment exposing (PaymentId) +import Model.Frequency exposing (Frequency) type Msg = NoOp diff --git a/src/client/LoggedIn/Home/Update.elm b/src/client/LoggedIn/Home/Update.elm index b0ce256..06c2c7e 100644 --- a/src/client/LoggedIn/Home/Update.elm +++ b/src/client/LoggedIn/Home/Update.elm @@ -5,9 +5,9 @@ module LoggedIn.Home.Update exposing import Form exposing (Form) import LoggedData exposing (LoggedData) - -import LoggedIn.Home.Msg as Home import LoggedIn.Home.Model as Home +import LoggedIn.Home.Msg as Home +import Model.Frequency as Frequency exposing (Frequency(..)) update : LoggedData -> Home.Msg -> Home.Model -> (Home.Model, Cmd Home.Msg) update loggedData msg model = @@ -19,17 +19,26 @@ update loggedData msg model = ) Home.UpdatePage page -> - ( { model | currentPage = page } + ( updatePage page model , Cmd.none ) Home.SearchMsg formMsg -> - ( { model - | search = Form.update Home.validation formMsg model.search - , currentPage = + let newModel = case formMsg of - Form.Input "name" _ _ -> 1 - _ -> model.currentPage - } - , Cmd.none - ) + Form.Input "name" _ _ -> updatePage 1 model + _ -> model + in ( { model | search = Form.update Home.validation formMsg model.search } + , Cmd.none + ) + +updatePage : Int -> Home.Model -> Home.Model +updatePage page model = + let frequency = + Form.getFieldAsString "frequency" model.search + |> .value + |> Maybe.andThen Frequency.fromString + in case frequency of + Just Punctual -> { model | punctualPage = page } + Just Monthly -> { model | monthlyPage = page } + Nothing -> model diff --git a/src/client/LoggedIn/Home/View.elm b/src/client/LoggedIn/Home/View.elm index 0b90e67..fba3f7c 100644 --- a/src/client/LoggedIn/Home/View.elm +++ b/src/client/LoggedIn/Home/View.elm @@ -16,7 +16,8 @@ import LoggedIn.Home.Msg as HomeMsg import LoggedIn.Home.View.Paging as Paging import LoggedIn.Home.View.Table as Table import LoggedIn.Msg as LoggedInMsg -import Model.Payment as Payment exposing (Frequency(..)) +import Model.Payment as Payment +import Model.Frequency exposing (Frequency(..)) import Msg exposing (Msg) view : LoggedData -> Home.Model -> Html Msg @@ -26,12 +27,16 @@ view loggedData home = Just data -> (Maybe.withDefault "" data.name, data.frequency) Nothing -> ("", Punctual) payments = Payment.search name frequency loggedData.payments + page = + case frequency of + Punctual -> home.punctualPage + Monthly -> home.monthlyPage in div [ class "home" ] [ Header.view loggedData home payments frequency - , Table.view loggedData home payments frequency + , Table.view loggedData home payments frequency page , Paging.view - home.currentPage + page (List.length payments) Msg.NoOp (Msg.UpdateLoggedIn << LoggedInMsg.HomeMsg << HomeMsg.UpdatePage) diff --git a/src/client/LoggedIn/Home/View/Table.elm b/src/client/LoggedIn/Home/View/Table.elm index 8828488..f94bb19 100644 --- a/src/client/LoggedIn/Home/View/Table.elm +++ b/src/client/LoggedIn/Home/View/Table.elm @@ -30,15 +30,16 @@ import LoggedIn.View.Format as Format import View.Date as Date import Model.Payment as Payment exposing (..) +import Model.Frequency exposing (Frequency(..)) import Model.PaymentCategory as PaymentCategory import Model.Translations exposing (getMessage) import Model.User exposing (getUserName) -view : LoggedData -> Home.Model -> Payments -> Frequency -> Html Msg -view loggedData homeModel payments frequency = +view : LoggedData -> Home.Model -> Payments -> Frequency -> Int -> Html Msg +view loggedData homeModel payments frequency page = let visiblePayments = payments - |> List.drop ((homeModel.currentPage - 1) * perPage) + |> List.drop ((page - 1) * perPage) |> List.take perPage in div [ class "table" ] diff --git a/src/client/LoggedIn/Msg.elm b/src/client/LoggedIn/Msg.elm index a128cff..d00e2cb 100644 --- a/src/client/LoggedIn/Msg.elm +++ b/src/client/LoggedIn/Msg.elm @@ -4,7 +4,8 @@ module LoggedIn.Msg exposing import Date exposing (Date) -import Model.Payment exposing (PaymentId, Frequency) +import Model.Payment exposing (PaymentId) +import Model.Frequency exposing (Frequency) import Model.Income exposing (IncomeId) import Model.Category exposing (CategoryId) diff --git a/src/client/LoggedIn/Update.elm b/src/client/LoggedIn/Update.elm index 1359e1a..753b1d3 100644 --- a/src/client/LoggedIn/Update.elm +++ b/src/client/LoggedIn/Update.elm @@ -13,7 +13,8 @@ import Platform.Cmd exposing (Cmd) import Form import Model exposing (Model) -import Model.Payment as Payment exposing (Payment, Frequency(..)) +import Model.Payment as Payment exposing (Payment) +import Model.Frequency exposing (Frequency(..)) import Model.Income as Income exposing (Income) import Model.Category exposing (Category) import Model.PaymentCategory as PaymentCategory |