aboutsummaryrefslogtreecommitdiff
path: root/src/client/View/Page.elm
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-07-20 21:55:52 +0200
committerJoris Guyonvarch2015-07-20 21:55:52 +0200
commita271d6034bc4cc631a64476d25d21c83a701fa39 (patch)
tree89ffa3df69999c5c9ed3cda9f4e4ec04f7a6ae1d /src/client/View/Page.elm
parenta40c4825996c90d107901b0d71162f9356f1395a (diff)
downloadbudget-a271d6034bc4cc631a64476d25d21c83a701fa39.tar.gz
budget-a271d6034bc4cc631a64476d25d21c83a701fa39.tar.bz2
budget-a271d6034bc4cc631a64476d25d21c83a701fa39.zip
Add a payment from the UI, it needs polishing however
Diffstat (limited to 'src/client/View/Page.elm')
-rw-r--r--src/client/View/Page.elm136
1 files changed, 9 insertions, 127 deletions
diff --git a/src/client/View/Page.elm b/src/client/View/Page.elm
index bf61dc1..59c21a2 100644
--- a/src/client/View/Page.elm
+++ b/src/client/View/Page.elm
@@ -3,30 +3,14 @@ module View.Page
) where
import Html exposing (..)
-import Html as H
-import Html.Attributes exposing (..)
-import Html.Attributes as A
-import Html.Events exposing (..)
-
-import Date
-import Date exposing (Date)
-
-import String exposing (append)
-
-import Json.Decode as Json
import Model exposing (Model)
-import Model.Payment exposing (Payments, Payment)
import Model.View exposing (..)
-import Model.View.SignIn exposing (..)
-import Update exposing (..)
-import Update.SignIn exposing (..)
-
-import ServerCommunication as SC
-import ServerCommunication exposing (serverCommunications)
-
-import View.Icon exposing (renderIcon)
+import View.Header exposing (renderHeader)
+import View.Loading exposing (renderLoading)
+import View.SignIn exposing (renderSignIn)
+import View.Payments exposing (renderPayments)
renderPage : Model -> Html
renderPage model =
@@ -36,114 +20,12 @@ renderPage model =
, renderMain model
]
-renderHeader : Model -> Html
-renderHeader model =
- header
- []
- [ h1
- []
- [ text "Shared Cost" ]
- , case model.view of
- LoadingView ->
- text ""
- SignInView _ ->
- text ""
- PaymentView _ ->
- button
- [ class "signOut"
- , onClick serverCommunications.address SC.SignOut
- ]
- [ renderIcon "power-off" ]
- ]
-
renderMain : Model -> Html
renderMain model =
case model.view of
LoadingView ->
- loadingView
- SignInView signIn ->
- signInView signIn
- PaymentView payments ->
- paymentsView payments
-
-loadingView : Html
-loadingView = text ""
-
-signInView : SignIn -> Html
-signInView signIn =
- div
- [ class "signIn" ]
- [ div
- [ class "form" ]
- [ input
- [ value signIn.login
- , on "input" targetValue (Signal.message actions.address << UpdateSignIn << UpdateLogin)
- , onEnter serverCommunications.address (SC.SignIn signIn.login)
- ]
- []
- , button
- [ onClick serverCommunications.address (SC.SignIn signIn.login) ]
- [ text "Sign in" ]
- ]
- , div
- [ class "result" ]
- [ signInResult signIn ]
- ]
-
-onEnter : Signal.Address a -> a -> Attribute
-onEnter address value =
- on "keydown"
- (Json.customDecoder keyCode (\code -> if code == 13 then Ok () else Err ""))
- (\_ -> Signal.message address value)
-
-signInResult : SignIn -> Html
-signInResult signIn =
- case signIn.result of
- Just result ->
- case result of
- Ok login ->
- div
- [ class "success" ]
- [ text ("We send you an email, please click to the provided link in order to sign in.") ]
- Err error ->
- div
- [ class "error" ]
- [ text error ]
- Nothing ->
- text ""
-
-paymentsView : Payments -> Html
-paymentsView payments =
- table
- []
- ([ tr
- []
- [ th [] [ renderIcon "user" ]
- , th [] [ renderIcon "shopping-cart" ]
- , th [] [ renderIcon "euro" ]
- , th [] [ renderIcon "calendar" ]
- ]
- ] ++ (paymentLines payments))
-
-paymentLines : Payments -> List Html
-paymentLines payments =
- payments
- |> List.sortBy (Date.toTime << .creation)
- |> List.reverse
- |> List.map paymentLine
-
-paymentLine : Payment -> Html
-paymentLine payment =
- tr
- []
- [ td [] [ text payment.userName ]
- , td [] [ text payment.name ]
- , td [] [ text ((toString payment.cost) ++ " €") ]
- , td [] [ text (renderDate payment.creation) ]
- ]
-
-renderDate : Date -> String
-renderDate date =
- toString (Date.day date)
- |> flip append (" " ++ (toString (Date.month date)) ++ ".")
- |> flip append (" " ++ (toString (Date.year date)))
+ renderLoading
+ SignInView signInView ->
+ renderSignIn signInView
+ PaymentView paymentsView ->
+ renderPayments paymentsView