diff options
Diffstat (limited to 'src/client/elm')
-rw-r--r-- | src/client/elm/InitViewAction.elm | 25 | ||||
-rw-r--r-- | src/client/elm/Main.elm | 2 | ||||
-rw-r--r-- | src/client/elm/Model/Communication.elm | 3 | ||||
-rw-r--r-- | src/client/elm/ServerCommunication.elm | 25 | ||||
-rw-r--r-- | src/client/elm/Update.elm | 44 | ||||
-rw-r--r-- | src/client/elm/View/Icon.elm | 6 | ||||
-rw-r--r-- | src/client/elm/View/SignIn.elm | 2 |
7 files changed, 45 insertions, 62 deletions
diff --git a/src/client/elm/InitViewAction.elm b/src/client/elm/InitViewAction.elm deleted file mode 100644 index 52ae08d..0000000 --- a/src/client/elm/InitViewAction.elm +++ /dev/null @@ -1,25 +0,0 @@ -module InitViewAction - ( initViewAction - ) where - -import Task exposing (..) -import Http -import Json.Decode as Json exposing ((:=)) - -import Effects exposing (Never) - -import Model.Action exposing (..) -import Model.Payment exposing (Payments, paymentsDecoder) -import Model.Payer exposing (Payers, payersDecoder) -import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder) - -initViewAction = Task.onError loggedInView (always <| Task.succeed GoSignInView) - -loggedInView : Task Http.Error Action -loggedInView = - Task.map GoLoggedInView (Http.get usersDecoder "/users") - `Task.andMap` (Http.get ("id" := userIdDecoder) "/whoAmI") - `Task.andMap` (Http.get paymentsDecoder "/monthlyPayments") - `Task.andMap` (Http.get paymentsDecoder "/payments") - `Task.andMap` (Http.get ("number" := Json.int) "/payments/count") - `Task.andMap` (Http.get payersDecoder "/payers") diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm index 684cd1b..34afa92 100644 --- a/src/client/elm/Main.elm +++ b/src/client/elm/Main.elm @@ -20,7 +20,7 @@ import View exposing (view) import Persona as Persona exposing (operations) -import InitViewAction exposing (initViewAction) +import ServerCommunication exposing (initViewAction) main : Signal Html main = app.html diff --git a/src/client/elm/Model/Communication.elm b/src/client/elm/Model/Communication.elm index dc4d412..a7ec7a5 100644 --- a/src/client/elm/Model/Communication.elm +++ b/src/client/elm/Model/Communication.elm @@ -8,8 +8,7 @@ import Model.User exposing (UserId) import Model.Payment exposing (..) type Communication = - NoCommunication - | SignIn String + SignIn String | AddPayment String Int | AddMonthlyPayment String Int | SetIncome Time Int diff --git a/src/client/elm/ServerCommunication.elm b/src/client/elm/ServerCommunication.elm index ff0937e..bc8d59f 100644 --- a/src/client/elm/ServerCommunication.elm +++ b/src/client/elm/ServerCommunication.elm @@ -1,11 +1,12 @@ module ServerCommunication ( sendRequest + , initViewAction ) where import Signal import Task as Task exposing (Task) import Http -import Json.Decode exposing (..) +import Json.Decode as Json exposing ((:=)) import Date import Time exposing (Time) import Debug @@ -13,24 +14,21 @@ import Debug import SimpleHTTP exposing (..) import Model.Communication exposing (..) -import Model.Action as U +import Model.Action as U exposing (Action) import Model.Action.LoggedInAction as UL import Model.Action.MonthlyAction as UM import Model.Action.AccountAction as UA import Model.View.LoggedIn.AddPayment exposing (Frequency(..)) -import Model.Payment exposing (..) +import Model.Payment exposing (PaymentId, paymentIdDecoder, Payments, paymentsDecoder) +import Model.Payer exposing (Payers, payersDecoder) +import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder) import Update.SignIn exposing (updateSignIn) -import InitViewAction exposing (initViewAction) - sendRequest : Communication -> Task Http.Error U.Action sendRequest communication = case communication of - NoCommunication -> - Task.succeed U.NoOp - SignIn assertion -> post ("/signIn?assertion=" ++ assertion) |> flip Task.andThen (always initViewAction) @@ -68,3 +66,14 @@ addPaymentURL name cost frequency = deletePaymentURL : PaymentId -> String deletePaymentURL id = "payment/delete?id=" ++ (toString id) + +initViewAction = Task.onError loggedInView (always <| Task.succeed U.GoSignInView) + +loggedInView : Task Http.Error Action +loggedInView = + Task.map U.GoLoggedInView (Http.get usersDecoder "/users") + `Task.andMap` (Http.get ("id" := userIdDecoder) "/whoAmI") + `Task.andMap` (Http.get paymentsDecoder "/monthlyPayments") + `Task.andMap` (Http.get paymentsDecoder "/payments") + `Task.andMap` (Http.get ("number" := Json.int) "/payments/count") + `Task.andMap` (Http.get payersDecoder "/payers") diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm index c61e2f5..46c1b01 100644 --- a/src/client/elm/Update.elm +++ b/src/client/elm/Update.elm @@ -11,7 +11,8 @@ import ServerCommunication exposing (sendRequest) import Model exposing (Model) import Model.Translations exposing (getMessage) import Model.Action exposing (..) -import Model.Action.SignInAction as SignInAction +import Model.Action.SignInAction as SignInAction exposing (SignInAction) +import Model.Action.LoggedInAction exposing (LoggedInAction) import Model.View as V import Model.View.SignInView exposing (..) import Model.View.LoggedInView exposing (..) @@ -21,7 +22,6 @@ import Update.LoggedIn exposing (updateLoggedIn) import Update.SignIn exposing (updateSignIn) import SimpleHTTP exposing (post) -import InitViewAction exposing (initViewAction) update : Action -> Model -> (Model, Effects Action) update action model = @@ -31,11 +31,11 @@ update action model = (model, Effects.none) SignIn assertion -> - ( case model.view of - V.SignInView signInView -> { model | view = V.SignInView (updateSignIn SignInAction.Connecting signInView) } - _ -> model + ( applySignIn model (SignInAction.Connecting) , sendRequest (Communication.SignIn assertion) - |> flip Task.onError (always <| Task.succeed (UpdateSignIn (SignInAction.ErrorLogin (getMessage "ErrorSignIn" model.translations)))) + |> flip Task.onError (\_ -> + Task.succeed (UpdateSignIn (SignInAction.ErrorLogin (getMessage "ErrorSignIn" model.translations))) + ) |> Effects.task ) @@ -58,19 +58,19 @@ update action model = ) UpdateSignIn signInAction -> - case model.view of - V.SignInView signInView -> - ( { model | view = V.SignInView (updateSignIn signInAction signInView) } - , Effects.none - ) - _ -> - (model, Effects.none) - - UpdateLoggedIn loggedAction -> - case model.view of - V.LoggedInView loggedInView -> - ( { model | view = V.LoggedInView (updateLoggedIn model loggedAction loggedInView) } - , Effects.none - ) - _ -> - (model, Effects.none) + (applySignIn model signInAction, Effects.none) + + UpdateLoggedIn loggedInAction -> + (applyLoggedIn model loggedInAction, Effects.none) + +applySignIn : Model -> SignInAction -> Model +applySignIn model signInAction = + case model.view of + V.SignInView signInView -> { model | view = V.SignInView (updateSignIn signInAction signInView) } + _ -> model + +applyLoggedIn : Model -> LoggedInAction -> Model +applyLoggedIn model loggedInAction = + case model.view of + V.LoggedInView loggedInView -> { model | view = V.LoggedInView (updateLoggedIn model loggedInAction loggedInView) } + _ -> model diff --git a/src/client/elm/View/Icon.elm b/src/client/elm/View/Icon.elm index 9fa5f8a..bdbe6d5 100644 --- a/src/client/elm/View/Icon.elm +++ b/src/client/elm/View/Icon.elm @@ -12,8 +12,8 @@ renderIcon iconClass = [ class <| "fa fa-fw fa-" ++ iconClass ] [] -renderSpinIcon : String -> Html -renderSpinIcon iconClass = +renderSpinIcon : Html +renderSpinIcon = i - [ class <| "fa fa-fw fa-spin fa-" ++ iconClass ] + [ class <| "fa fa-fw fa-pulse fa-spinner" ] [] diff --git a/src/client/elm/View/SignIn.elm b/src/client/elm/View/SignIn.elm index f662a97..ba16561 100644 --- a/src/client/elm/View/SignIn.elm +++ b/src/client/elm/View/SignIn.elm @@ -28,7 +28,7 @@ renderSignIn address model signInView = [ onClick operations.address Persona.SignIn ] [ span [] [ text (getMessage "SignIn" model.translations) ] , if signInView.connecting - then renderSpinIcon "refresh" + then renderSpinIcon else renderIcon "power-off" ] , signInResult model signInView |