diff options
author | Joris | 2015-11-01 11:58:42 +0100 |
---|---|---|
committer | Joris | 2015-11-01 11:58:42 +0100 |
commit | c015db01e2acee9d1fc83cd6a762d0a3e629b353 (patch) | |
tree | 9e6b8f5fa04a3ce6cca51f5cae4cc8fbf6a0f5ed | |
parent | d3e045e8034c5473964c0529ffc1e181311842c2 (diff) |
Use in client the real currency set in config.txt
-rw-r--r-- | config.txt | 2 | ||||
-rw-r--r-- | public/javascripts/elmLauncher.js | 3 | ||||
-rw-r--r-- | src/client/Main.elm | 7 | ||||
-rw-r--r-- | src/client/Model.elm | 13 | ||||
-rw-r--r-- | src/client/Model/Conf.elm | 7 | ||||
-rw-r--r-- | src/client/Model/Config.elm | 18 | ||||
-rw-r--r-- | src/client/View/LoggedIn/Add.elm | 2 | ||||
-rw-r--r-- | src/client/View/LoggedIn/Table.elm | 2 | ||||
-rw-r--r-- | src/client/View/Price.elm | 2 | ||||
-rw-r--r-- | src/server/Controller/Index.hs | 7 | ||||
-rw-r--r-- | src/server/Main.hs | 10 | ||||
-rw-r--r-- | src/server/Model/Json/Config.hs | 17 | ||||
-rw-r--r-- | src/server/View/Page.hs | 6 |
13 files changed, 69 insertions, 27 deletions
@@ -1,4 +1,4 @@ hostname = localhost:3001 port = 3001 sign-in-expiration-mn = 5 -currency = $ +currency = € diff --git a/public/javascripts/elmLauncher.js b/public/javascripts/elmLauncher.js index ef5d86d..bdcb479 100644 --- a/public/javascripts/elmLauncher.js +++ b/public/javascripts/elmLauncher.js @@ -1,7 +1,8 @@ Elm.fullscreen(Elm.Main, { signInError: getParameterByName('signInError'), initialTime: new Date().getTime(), - translations: document.getElementById('messages').innerHTML + translations: document.getElementById('messages').innerHTML, + config: document.getElementById('config').innerHTML }); function getParameterByName(name) { diff --git a/src/client/Main.elm b/src/client/Main.elm index de98809..4f96675 100644 --- a/src/client/Main.elm +++ b/src/client/Main.elm @@ -17,6 +17,7 @@ import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder) import Model.Payment exposing (Payments, paymentsDecoder, perPage) import Model.Payer exposing (Payers, payersDecoder) import Model.Translations exposing (..) +import Model.Config exposing (..) import Update exposing (Action(..), actions, updateModel) import Update.SignIn exposing (..) @@ -29,7 +30,7 @@ main : Signal Html main = Signal.map renderPage model model : Signal Model -model = Signal.foldp updateModel (initialModel initialTime translations) update +model = Signal.foldp updateModel (initialModel initialTime translations config) update update : Signal Action update = Signal.mergeMany @@ -51,6 +52,10 @@ port translations : String --------------------------------------- +port config : String + +--------------------------------------- + port initView : Task Http.Error () port initView = case signInError of diff --git a/src/client/Model.elm b/src/client/Model.elm index c330d86..43a19c5 100644 --- a/src/client/Model.elm +++ b/src/client/Model.elm @@ -8,22 +8,25 @@ import Json.Decode as Json import Model.View exposing (..) import Model.Translations exposing (..) -import Model.Conf exposing (..) +import Model.Config exposing (..) type alias Model = { view : View , currentTime : Time , translations : Translations - , conf : Conf + , config : Config } -initialModel : Time -> String -> Model -initialModel initialTime translationsValue = +initialModel : Time -> String -> String -> Model +initialModel initialTime translationsValue configValue = { view = LoadingView , currentTime = initialTime , translations = case Json.decodeString translationsDecoder translationsValue of Ok translations -> translations Err err -> [] - , conf = { currency = "€" } + , config = + case Json.decodeString configDecoder configValue of + Ok config -> config + Err err -> { currency = "" } } diff --git a/src/client/Model/Conf.elm b/src/client/Model/Conf.elm deleted file mode 100644 index 183fd68..0000000 --- a/src/client/Model/Conf.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Model.Conf - ( Conf - ) where - -type alias Conf = - { currency : String - } diff --git a/src/client/Model/Config.elm b/src/client/Model/Config.elm new file mode 100644 index 0000000..e47b032 --- /dev/null +++ b/src/client/Model/Config.elm @@ -0,0 +1,18 @@ +module Model.Config + ( Config + , configDecoder + ) where + +import Json.Decode exposing (..) + +type alias Config = + { currency : String + } + +configDecoder : Decoder Config +configDecoder = object1 Config ("currency" := string) + +defaultConfig : Config +defaultConfig = + { currency = "€" + } diff --git a/src/client/View/LoggedIn/Add.elm b/src/client/View/LoggedIn/Add.elm index 4f75822..572bdf6 100644 --- a/src/client/View/LoggedIn/Add.elm +++ b/src/client/View/LoggedIn/Add.elm @@ -90,7 +90,7 @@ addPaymentCost model addPayment = [] , label [ for "costInput" ] - [ text model.conf.currency ] + [ text model.config.currency ] , case addPayment.costError of Just error -> div [ class "errorMessage" ] [ text error ] diff --git a/src/client/View/LoggedIn/Table.elm b/src/client/View/LoggedIn/Table.elm index 2cfc6d6..f5a08b5 100644 --- a/src/client/View/LoggedIn/Table.elm +++ b/src/client/View/LoggedIn/Table.elm @@ -38,7 +38,7 @@ headerLine model = div [ class "header" ] [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] - , div [ class "cell cost" ] [ text model.conf.currency ] + , div [ class "cell cost" ] [ text model.config.currency ] , div [ class "cell user" ] [ renderIcon "user" ] , div [ class "cell date" ] [ renderIcon "calendar" ] , div [ class "cell" ] [] diff --git a/src/client/View/Price.elm b/src/client/View/Price.elm index be665a8..286bcaa 100644 --- a/src/client/View/Price.elm +++ b/src/client/View/Price.elm @@ -11,7 +11,7 @@ price : Model -> Int -> String price model amount = ( formatInt amount ++ " " - ++ model.conf.currency + ++ model.config.currency ) formatInt : Int -> String diff --git a/src/server/Controller/Index.hs b/src/server/Controller/Index.hs index da67051..e4ec729 100644 --- a/src/server/Controller/Index.hs +++ b/src/server/Controller/Index.hs @@ -7,12 +7,15 @@ import Web.Scotty import Network.HTTP.Types.Status (ok200) +import Config (Config(..)) import qualified LoginSession +import qualified Model.Json.Config as M + import View.Page (page) -getIndex :: ActionM () -getIndex = html page +getIndex :: Config -> ActionM () +getIndex config = html . page $ M.Config { M.currency = currency config } signOut :: ActionM () signOut = do diff --git a/src/server/Main.hs b/src/server/Main.hs index 6a120d6..3d61481 100644 --- a/src/server/Main.hs +++ b/src/server/Main.hs @@ -19,23 +19,23 @@ import Controller.Payer import Model.Database (runMigrations) import Model.Frequency -import Config +import qualified Config main :: IO () main = do runMigrations _ <- forkIO monthlyPaymentJobListener - eitherConfig <- getConfig "config.txt" + eitherConfig <- Config.getConfig "config.txt" case eitherConfig of Left errorMessage -> TIO.putStrLn errorMessage Right config -> do - scotty (port config) $ do + scotty (Config.port config) $ do middleware $ staticPolicy (noDots >-> addBase "public") - get "/" getIndex - post "/signOut" signOut + get "/" (getIndex config) + post "/signOut" signOut -- SignIn diff --git a/src/server/Model/Json/Config.hs b/src/server/Model/Json/Config.hs new file mode 100644 index 0000000..422ecee --- /dev/null +++ b/src/server/Model/Json/Config.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE DeriveGeneric #-} + +module Model.Json.Config + ( Config(..) + ) where + +import GHC.Generics + +import Data.Aeson +import Data.Text + +data Config = Config + { currency :: Text + } deriving (Show, Generic) + +instance FromJSON Config +instance ToJSON Config diff --git a/src/server/View/Page.hs b/src/server/View/Page.hs index 41c9b73..2865337 100644 --- a/src/server/View/Page.hs +++ b/src/server/View/Page.hs @@ -18,16 +18,18 @@ import Text.Blaze.Html.Renderer.Text (renderHtml) import Design.Global (globalDesign) import Model.Message +import Model.Json.Config import Model.Message.Key (Key(SharedCost)) -page :: Text -page = +page :: Config -> Text +page config = renderHtml . docTypeHtml $ do H.head $ do meta ! charset "UTF-8" H.title (toHtml $ getMessage SharedCost) script ! src "javascripts/client.js" $ "" script ! A.id "messages" ! type_ "application/json" $ toHtml . decodeUtf8 . encode $ getTranslations + script ! A.id "config" ! type_ "application/json" $ toHtml . decodeUtf8 . encode $ config link ! rel "stylesheet" ! type_ "text/css" ! href "css/reset.css" link ! rel "stylesheet" ! href "css/font-awesome/css/font-awesome.min.css" link ! rel "icon" ! type_ "image/png" ! href "images/icon.png" |