aboutsummaryrefslogtreecommitdiff
path: root/server/src/Controller
diff options
context:
space:
mode:
authorJoris2019-10-20 21:31:57 +0200
committerJoris2019-10-20 21:31:57 +0200
commit602c52acfcfa494b07fec05c20b317b60ea8a6f3 (patch)
tree34fd9c44f82a83569822bc36eb2e0b04518e59f2 /server/src/Controller
parent7aadcc97f9df0e2daccbe8a8726d8bc6c63d67f4 (diff)
Load init data per page with AJAX
Diffstat (limited to 'server/src/Controller')
-rw-r--r--server/src/Controller/Category.hs9
-rw-r--r--server/src/Controller/Income.hs9
-rw-r--r--server/src/Controller/Index.hs11
-rw-r--r--server/src/Controller/Payment.hs7
-rw-r--r--server/src/Controller/User.hs17
5 files changed, 46 insertions, 7 deletions
diff --git a/server/src/Controller/Category.hs b/server/src/Controller/Category.hs
index 37b8357..e536caa 100644
--- a/server/src/Controller/Category.hs
+++ b/server/src/Controller/Category.hs
@@ -1,5 +1,6 @@
module Controller.Category
- ( create
+ ( list
+ , create
, edit
, delete
) where
@@ -19,6 +20,12 @@ import qualified Persistence.Category as CategoryPersistence
import qualified Persistence.PaymentCategory as PaymentCategoryPersistence
import qualified Secure
+list :: ActionM ()
+list =
+ Secure.loggedAction (\_ ->
+ (liftIO . Query.run $ CategoryPersistence.list) >>= json
+ )
+
create :: CreateCategory -> ActionM ()
create (CreateCategory name color) =
Secure.loggedAction (\_ ->
diff --git a/server/src/Controller/Income.hs b/server/src/Controller/Income.hs
index e013849..b40976b 100644
--- a/server/src/Controller/Income.hs
+++ b/server/src/Controller/Income.hs
@@ -1,5 +1,6 @@
module Controller.Income
- ( create
+ ( list
+ , create
, edit
, delete
) where
@@ -20,6 +21,12 @@ import qualified Persistence.Income as IncomePersistence
import qualified Secure
import qualified Validation.Income as IncomeValidation
+list :: ActionM ()
+list =
+ Secure.loggedAction (\_ ->
+ (liftIO . Query.run $ IncomePersistence.list) >>= json
+ )
+
create :: CreateIncomeForm -> ActionM ()
create form =
Secure.loggedAction (\user ->
diff --git a/server/src/Controller/Index.hs b/server/src/Controller/Index.hs
index 5ebe921..3788685 100644
--- a/server/src/Controller/Index.hs
+++ b/server/src/Controller/Index.hs
@@ -16,8 +16,9 @@ import Prelude hiding (error)
import Web.Scotty (ActionM)
import qualified Web.Scotty as S
-import Common.Model (Email (..), InitResult (..),
- SignInForm (..), User (..))
+import Common.Model (Email (..), Init (..),
+ InitResult (..), SignInForm (..),
+ User (..))
import Common.Msg (Key)
import qualified Common.Msg as Msg
import qualified Common.Validation.SignIn as SignInValidation
@@ -26,7 +27,6 @@ import Conf (Conf (..))
import qualified LoginSession
import qualified Model.Query as Query
import qualified Model.SignIn as SignIn
-import qualified Persistence.Init as InitPersistence
import qualified Persistence.User as UserPersistence
import qualified Secure
import qualified SendMail
@@ -40,8 +40,9 @@ get conf = do
case mbLoggedUser of
Nothing ->
return InitEmpty
- Just user ->
- liftIO . Query.run . fmap InitSuccess $ InitPersistence.getInit user conf
+ Just user -> do
+ users <- liftIO . Query.run $ UserPersistence.list
+ return . InitSuccess $ Init users (_user_id user) (Conf.currency conf)
S.html $ page initResult
askSignIn :: Conf -> SignInForm -> ActionM ()
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index ba9d1ba..30b63ff 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -1,5 +1,6 @@
module Controller.Payment
( list
+ , listPaymentCategories
, create
, edit
, delete
@@ -32,6 +33,12 @@ list =
(liftIO . Query.run $ PaymentPersistence.listActive) >>= json
)
+listPaymentCategories :: ActionM ()
+listPaymentCategories =
+ Secure.loggedAction (\_ ->
+ (liftIO . Query.run $ PaymentCategoryPersistence.list) >>= json
+ )
+
create :: CreatePaymentForm -> ActionM ()
create form =
Secure.loggedAction (\user ->
diff --git a/server/src/Controller/User.hs b/server/src/Controller/User.hs
new file mode 100644
index 0000000..a7bb136
--- /dev/null
+++ b/server/src/Controller/User.hs
@@ -0,0 +1,17 @@
+module Controller.User
+ ( list
+ ) where
+
+import Control.Monad.IO.Class (liftIO)
+import Web.Scotty (ActionM)
+import qualified Web.Scotty as S
+
+import qualified Model.Query as Query
+import qualified Persistence.User as UserPersistence
+import qualified Secure
+
+list :: ActionM ()
+list =
+ Secure.loggedAction (\_ ->
+ (liftIO . Query.run $ UserPersistence.list) >>= S.json
+ )