aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app')
-rw-r--r--frontend/app/Page/ListCollection.hs8
-rw-r--r--frontend/app/Schema.hs24
2 files changed, 25 insertions, 7 deletions
diff --git a/frontend/app/Page/ListCollection.hs b/frontend/app/Page/ListCollection.hs
index ff659af..9e3caaa 100644
--- a/frontend/app/Page/ListCollection.hs
+++ b/frontend/app/Page/ListCollection.hs
@@ -8,26 +8,28 @@ module Page.ListCollection
where
import ACMS.API.REST.Collection qualified as API.REST.Collection
+import ACMS.API.REST.Collection.Paginated (Paginated (..))
+import ACMS.API.REST.Collection.Paginated qualified as API.REST.Collection.Paginated
+import Collection
import Control.Monad.Catch (SomeException, try)
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Effect (Eff)
import Miso
import Schema
-import Collection
data Model = Model
{ collection :: Collection,
input :: A.Object,
schema :: Schema,
- posts :: [A.Object]
+ posts :: Paginated A.Object
}
deriving (Show, Eq)
initialModel :: Collection -> JSM (Either SomeException Model)
initialModel collection = do
schema' <- try (API.REST.Collection.schema collection)
- posts' <- try (API.REST.Collection.list collection)
+ posts' <- try (API.REST.Collection.Paginated.list (API.REST.Collection.Paginated.Pagination 10 0) collection)
pure do
schema <- schema'
posts <- posts'
diff --git a/frontend/app/Schema.hs b/frontend/app/Schema.hs
index c10cffe..be04906 100644
--- a/frontend/app/Schema.hs
+++ b/frontend/app/Schema.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
+
module Schema
( Schema,
viewSchema,
@@ -6,6 +8,7 @@ module Schema
)
where
+import ACMS.API.REST.Collection.Paginated (Paginated (..))
import Control.Applicative ((<|>))
import Data.Aeson qualified as A
import Data.Aeson.Key qualified as AK
@@ -20,6 +23,7 @@ import Miso
import Miso.String (MisoString, fromMisoString, intercalate, toMisoString)
import Route
import Safe
+import Text.Printf
data Schema = Schema
{ id :: MisoString,
@@ -76,9 +80,9 @@ viewSchema schema =
)
<$> (M.toList schema.properties)
-schemaTable :: MisoString -> Schema -> [A.Object] -> View action
-schemaTable collection schema values =
- table_ [] [thead, tbody]
+schemaTable :: MisoString -> Schema -> Paginated A.Object -> View action
+schemaTable collection schema paginated =
+ table_ [] [thead, tbody, tfoot]
where
thead =
thead_ [] $
@@ -108,8 +112,20 @@ schemaTable collection schema values =
]
| k <- M.keys schema.properties
]
- | value <- values
+ | value <- paginated.data_
]
+ tfoot =
+ let page, lastPage, perPage :: Int
+ page = 1
+ lastPage = ceiling (fromIntegral paginated.count / fromIntegral perPage)
+ perPage = 15
+ in tfoot_ [] $
+ [ tr_ [] $
+ [ td_ [colspan_ "999"] $
+ [ text (toMisoString (printf "Page %d of %d (%d total results)" page lastPage paginated.count :: String))
+ ]
+ ]
+ ]
schemaForm :: Schema -> F.Form A.Object A.Object
schemaForm schema =