aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2015-11-01 11:58:42 +0100
committerJoris2015-11-01 11:58:42 +0100
commitc015db01e2acee9d1fc83cd6a762d0a3e629b353 (patch)
tree9e6b8f5fa04a3ce6cca51f5cae4cc8fbf6a0f5ed /src
parentd3e045e8034c5473964c0529ffc1e181311842c2 (diff)
downloadbudget-c015db01e2acee9d1fc83cd6a762d0a3e629b353.tar.gz
budget-c015db01e2acee9d1fc83cd6a762d0a3e629b353.tar.bz2
budget-c015db01e2acee9d1fc83cd6a762d0a3e629b353.zip
Use in client the real currency set in config.txt
Diffstat (limited to 'src')
-rw-r--r--src/client/Main.elm7
-rw-r--r--src/client/Model.elm13
-rw-r--r--src/client/Model/Conf.elm7
-rw-r--r--src/client/Model/Config.elm18
-rw-r--r--src/client/View/LoggedIn/Add.elm2
-rw-r--r--src/client/View/LoggedIn/Table.elm2
-rw-r--r--src/client/View/Price.elm2
-rw-r--r--src/server/Controller/Index.hs7
-rw-r--r--src/server/Main.hs10
-rw-r--r--src/server/Model/Json/Config.hs17
-rw-r--r--src/server/View/Page.hs6
11 files changed, 66 insertions, 25 deletions
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"