aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Schema.hs
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/Schema.hs')
-rw-r--r--frontend/app/Schema.hs24
1 files changed, 20 insertions, 4 deletions
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 =