aboutsummaryrefslogtreecommitdiff
path: root/src/client/View/Payments
diff options
context:
space:
mode:
authorJoris2015-09-06 16:46:59 +0200
committerJoris2015-09-06 16:46:59 +0200
commit3853811450d4fe801da996eb48825049c3541030 (patch)
treeb483c6152f55b6fe87d23108d2d0346a593e51ac /src/client/View/Payments
parent0b6f0fa29075178b45cb17d2932003ab4b342280 (diff)
Renaming PaymentView to LoggedInView
Diffstat (limited to 'src/client/View/Payments')
-rw-r--r--src/client/View/Payments/Add.elm105
-rw-r--r--src/client/View/Payments/ExceedingPayer.elm35
-rw-r--r--src/client/View/Payments/Monthly.elm72
-rw-r--r--src/client/View/Payments/Paging.elm97
-rw-r--r--src/client/View/Payments/Table.elm86
5 files changed, 0 insertions, 395 deletions
diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm
deleted file mode 100644
index f352f1f..0000000
--- a/src/client/View/Payments/Add.elm
+++ /dev/null
@@ -1,105 +0,0 @@
-module View.Payments.Add
- ( addPayment
- ) where
-
-import Html as H exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-import Reads exposing (readInt)
-import Result exposing (..)
-
-import ServerCommunication as SC exposing (serverCommunications)
-
-import Update exposing (..)
-import Update.LoggedView exposing (..)
-import Update.LoggedView.Add exposing (..)
-
-import Model exposing (Model)
-import Model.View.Payment.Add exposing (..)
-import Model.Translations exposing (getMessage)
-import Model.View.LoggedView exposing (LoggedView)
-
-import View.Events exposing (onSubmitPrevDefault)
-import View.Icon exposing (renderIcon)
-
-import Utils.Maybe exposing (isJust)
-import Utils.Either exposing (toMaybeError)
-
-addPayment : Model -> LoggedView -> Html
-addPayment model loggedView =
- H.form
- [ case (validateName loggedView.add.name model.translations, validateCost loggedView.add.cost model.translations) of
- (Ok name, Ok cost) ->
- let action =
- case loggedView.add.frequency of
- Punctual -> SC.AddPayment loggedView.me name cost
- Monthly -> SC.AddMonthlyPayment name cost
- in onSubmitPrevDefault serverCommunications.address action
- (resName, resCost) ->
- onSubmitPrevDefault actions.address (UpdateLoggedView <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost))
- ]
- [ addPaymentName loggedView.add
- , addPaymentCost model loggedView.add
- , paymentFrequency model loggedView.add
- , button
- [ type' "submit"
- , class "add" ]
- [ text (getMessage "Add" model.translations)]
- ]
-
-addPaymentName : AddPayment -> Html
-addPaymentName addPayment =
- div
- [ class ("name " ++ (if isJust addPayment.nameError then "error" else "")) ]
- [ input
- [ id "nameInput"
- , value addPayment.name
- , on "input" targetValue (Signal.message actions.address << UpdateLoggedView << UpdateAdd << UpdateName)
- , maxlength 20
- ]
- []
- , label
- [ for "nameInput" ]
- [ renderIcon "shopping-cart" ]
- , case addPayment.nameError of
- Just error ->
- div [ class "errorMessage" ] [ text error ]
- Nothing ->
- text ""
- ]
-
-addPaymentCost : Model -> AddPayment -> Html
-addPaymentCost model addPayment =
- div
- [ class ("cost " ++ (if isJust addPayment.costError then "error" else "")) ]
- [ input
- [ id "costInput"
- , value addPayment.cost
- , on "input" targetValue (Signal.message actions.address << UpdateLoggedView << UpdateAdd << UpdateCost)
- , maxlength 7
- ]
- []
- , label
- [ for "costInput" ]
- [ text (getMessage "MoneySymbol" model.translations) ]
- , case addPayment.costError of
- Just error ->
- div [ class "errorMessage" ] [ text error ]
- Nothing ->
- text ""
- ]
-
-paymentFrequency : Model -> AddPayment -> Html
-paymentFrequency model addPayment =
- button
- [ type' "button"
- , class "frequency"
- , onClick actions.address (UpdateLoggedView << UpdateAdd <| ToggleFrequency)
- ]
- [ div
- [ class ("punctual" ++ if addPayment.frequency == Punctual then " selected" else "") ]
- [ text (getMessage "Punctual" model.translations) ]
- , div
- [ class ("monthly" ++ if addPayment.frequency == Monthly then " selected" else "") ]
- [ text (getMessage "Monthly" model.translations) ]
- ]
diff --git a/src/client/View/Payments/ExceedingPayer.elm b/src/client/View/Payments/ExceedingPayer.elm
deleted file mode 100644
index 88b3a72..0000000
--- a/src/client/View/Payments/ExceedingPayer.elm
+++ /dev/null
@@ -1,35 +0,0 @@
-module View.Payments.ExceedingPayer
- ( exceedingPayers
- ) where
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import List
-
-import Model exposing (Model)
-import Model.User exposing (getUserName)
-import Model.Payers exposing (..)
-import Model.View.LoggedView exposing (LoggedView)
-import Model.Translations exposing (getMessage)
-
-exceedingPayers : Model -> LoggedView -> Html
-exceedingPayers model loggedView =
- div
- [ class "exceedingPayers" ]
- (List.map (exceedingPayer model loggedView) (getOrderedExceedingPayers loggedView.payers))
-
-exceedingPayer : Model -> LoggedView -> ExceedingPayer -> Html
-exceedingPayer model loggedView payer =
- div
- [ class "exceedingPayer" ]
- [ span
- [ class "userName" ]
- [ payer.userId
- |> getUserName loggedView.users
- |> Maybe.withDefault "−"
- |> text
- ]
- , span
- [ class "amount" ]
- [ text ("+ " ++ (toString payer.amount) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ]
- ]
diff --git a/src/client/View/Payments/Monthly.elm b/src/client/View/Payments/Monthly.elm
deleted file mode 100644
index 944314c..0000000
--- a/src/client/View/Payments/Monthly.elm
+++ /dev/null
@@ -1,72 +0,0 @@
-module View.Payments.Monthly
- ( monthlyPayments
- ) where
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-
-import Update exposing (..)
-import Update.LoggedView exposing (..)
-import Update.LoggedView.Monthly exposing (..)
-
-import Model exposing (Model)
-import Model.View.Payment.Monthly exposing (Monthly)
-import Model.Payment exposing (Payments, Payment)
-import Model.View.LoggedView exposing (LoggedView)
-import Model.Translations exposing (getMessage, getParamMessage)
-
-import ServerCommunication as SC exposing (serverCommunications)
-
-import View.Icon exposing (renderIcon)
-
-monthlyPayments : Model -> LoggedView -> Html
-monthlyPayments model loggedView =
- let monthly = loggedView.monthly
- in if List.isEmpty monthly.payments
- then
- text ""
- else
- div
- [ class ("monthlyPayments" ++ if monthly.visibleDetail then " detail" else "") ]
- [ monthlyCount model monthly
- , if monthly.visibleDetail then paymentsTable model loggedView monthly else text ""
- ]
-
-monthlyCount : Model -> Monthly -> Html
-monthlyCount model monthly =
- let count = List.length monthly.payments
- key = if count > 1 then "PluralMonthlyCount" else "SingularMonthlyCount"
- in button
- [ class "count"
- , onClick actions.address (UpdateLoggedView << UpdateMonthly <| ToggleDetail)
- ]
- [ text (getParamMessage [toString count] key model.translations)
- , div
- [ class "expand" ]
- [ if monthly.visibleDetail
- then renderIcon "chevron-up"
- else renderIcon "chevron-down"
- ]
- ]
-
-paymentsTable : Model -> LoggedView -> Monthly -> Html
-paymentsTable model loggedView monthly =
- div
- [ class "table" ]
- ( List.map (paymentLine model loggedView) monthly.payments )
-
-paymentLine : Model -> LoggedView -> Payment -> Html
-paymentLine model loggedView payment =
- a
- [ class ("row" ++ (if loggedView.paymentEdition == Just payment.id then " edition" else ""))
- , onClick actions.address (UpdateLoggedView (ToggleEdit payment.id))
- ]
- [ div [ class "cell" ] [ text (payment.name) ]
- , div [ class "cell" ] [ text (toString payment.cost ++ " " ++ getMessage "MoneySymbol" model.translations) ]
- , div
- [ class "cell delete"
- , onClick serverCommunications.address (SC.DeleteMonthlyPayment payment.id)
- ]
- [ renderIcon "times" ]
- ]
diff --git a/src/client/View/Payments/Paging.elm b/src/client/View/Payments/Paging.elm
deleted file mode 100644
index b9a0109..0000000
--- a/src/client/View/Payments/Paging.elm
+++ /dev/null
@@ -1,97 +0,0 @@
-module View.Payments.Paging
- ( paymentsPaging
- ) where
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-
-import Model.View.LoggedView exposing (..)
-import Model.Payment exposing (perPage)
-
-import ServerCommunication as SC exposing (serverCommunications)
-
-import Update exposing (..)
-import Update.LoggedView exposing (..)
-
-import View.Icon exposing (renderIcon)
-
-showedPages : Int
-showedPages = 5
-
-paymentsPaging : LoggedView -> Html
-paymentsPaging loggedView =
- let maxPage = ceiling (toFloat loggedView.paymentsCount / toFloat perPage)
- pages = truncatePages loggedView.currentPage [1..maxPage]
- in if maxPage == 1
- then
- text ""
- else
- div
- [ class "pages" ]
- ( ( if loggedView.currentPage > 1
- then [ firstPage, previousPage loggedView ]
- else []
- )
- ++ ( List.map (paymentsPage loggedView) pages)
- ++ ( if loggedView.currentPage < maxPage
- then [ nextPage loggedView, lastPage maxPage ]
- else []
- )
- )
-
-truncatePages : Int -> List Int -> List Int
-truncatePages currentPage pages =
- let totalPages = List.length pages
- showedLeftPages = ceiling ((toFloat showedPages - 1) / 2)
- showedRightPages = floor ((toFloat showedPages - 1) / 2)
- truncatedPages =
- if | currentPage < showedLeftPages ->
- [1..showedPages]
- | currentPage > totalPages - showedRightPages ->
- [(totalPages - showedPages)..totalPages]
- | otherwise ->
- [(currentPage - showedLeftPages)..(currentPage + showedRightPages)]
- in List.filter (flip List.member pages) truncatedPages
-
-firstPage : Html
-firstPage =
- button
- [ class "page"
- , onClick serverCommunications.address (SC.UpdatePage 1)
- ]
- [ renderIcon "fast-backward" ]
-
-previousPage : LoggedView -> Html
-previousPage loggedView =
- button
- [ class "page"
- , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage - 1))
- ]
- [ renderIcon "backward" ]
-
-nextPage : LoggedView -> Html
-nextPage loggedView =
- button
- [ class "page"
- , onClick serverCommunications.address (SC.UpdatePage (loggedView.currentPage + 1))
- ]
- [ renderIcon "forward" ]
-
-lastPage : Int -> Html
-lastPage maxPage =
- button
- [ class "page"
- , onClick serverCommunications.address (SC.UpdatePage maxPage)
- ]
- [ renderIcon "fast-forward" ]
-
-paymentsPage : LoggedView -> Int -> Html
-paymentsPage loggedView page =
- let onCurrentPage = page == loggedView.currentPage
- in button
- [ class ("page" ++ (if onCurrentPage then " current" else ""))
- , onClick serverCommunications.address <|
- if onCurrentPage then SC.NoCommunication else SC.UpdatePage page
- ]
- [ text (toString page) ]
diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm
deleted file mode 100644
index 1646186..0000000
--- a/src/client/View/Payments/Table.elm
+++ /dev/null
@@ -1,86 +0,0 @@
-module View.Payments.Table
- ( paymentsTable
- ) where
-
-import Html exposing (..)
-import Html.Attributes exposing (..)
-import Html.Events exposing (..)
-import Dict exposing (..)
-
-import Date
-import Date exposing (Date)
-
-import String exposing (append)
-
-import Model exposing (Model)
-import Model.User exposing (getUserName)
-import Model.Payment exposing (..)
-import Model.View.LoggedView exposing (LoggedView)
-import Model.Translations exposing (getMessage)
-
-import ServerCommunication as SC exposing (serverCommunications)
-
-import Update exposing (..)
-import Update.LoggedView exposing (..)
-
-import View.Icon exposing (renderIcon)
-import View.Date exposing (..)
-
-paymentsTable : Model -> LoggedView -> Html
-paymentsTable model loggedView =
- div
- [ class "table" ]
- ( headerLine model :: paymentLines model loggedView)
-
-headerLine : Model -> Html
-headerLine model =
- div
- [ class "header" ]
- [ div [ class "cell category" ] [ renderIcon "shopping-cart" ]
- , div [ class "cell cost" ] [ text (getMessage "MoneySymbol" model.translations) ]
- , div [ class "cell user" ] [ renderIcon "user" ]
- , div [ class "cell date" ] [ renderIcon "calendar" ]
- , div [ class "cell" ] []
- ]
-
-paymentLines : Model -> LoggedView -> List Html
-paymentLines model loggedView =
- loggedView.payments
- |> List.sortBy (Date.toTime << .creation)
- |> List.reverse
- |> List.map (paymentLine model loggedView)
-
-paymentLine : Model -> LoggedView -> Payment -> Html
-paymentLine model loggedView payment =
- a
- [ class ("row" ++ (if loggedView.paymentEdition == Just payment.id then " edition" else ""))
- , onClick actions.address (UpdateLoggedView (ToggleEdit payment.id))
- ]
- [ div [ class "cell category" ] [ text payment.name ]
- , div [ class "cell cost" ] [ text ((toString payment.cost) ++ " " ++ (getMessage "MoneySymbol" model.translations)) ]
- , div
- [ class "cell user" ]
- [ payment.userId
- |> getUserName loggedView.users
- |> Maybe.withDefault "−"
- |> text
- ]
- , div
- [ class "cell date" ]
- [ span
- [ class "shortDate" ]
- [ text (renderShortDate payment.creation model.translations) ]
- , span
- [ class "longDate" ]
- [ text (renderLongDate payment.creation model.translations) ]
- ]
- , if loggedView.me == payment.userId
- then
- div
- [ class "cell delete"
- , onClick serverCommunications.address (SC.DeletePayment payment.id payment.userId payment.cost loggedView.currentPage)
- ]
- [ renderIcon "times" ]
- else
- div [ class "cell" ] []
- ]