diff options
Diffstat (limited to 'src/server')
-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 |
4 files changed, 31 insertions, 9 deletions
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" |