link to edit page from list page

This commit is contained in:
Alexander Foremny
2024-06-06 15:31:16 +02:00
parent a569f8d7a2
commit 612da78d17
3 changed files with 23 additions and 7 deletions

View File

@@ -41,7 +41,7 @@ viewModel :: Model -> View Action
viewModel m = viewModel m =
div_ [] $ div_ [] $
[ h3_ [] [text "entities"], [ h3_ [] [text "entities"],
schemaTable m.schema m.posts, schemaTable m.collection m.schema m.posts,
h3_ [] [text "schema"], h3_ [] [text "schema"],
viewSchema m.schema viewSchema m.schema
] ]

View File

@@ -1,6 +1,7 @@
module Route module Route
( Route (..), ( Route (..),
parseURI, parseURI,
routeToString,
) )
where where
@@ -32,3 +33,8 @@ parseURI uri =
<* P.endOfInput <* P.endOfInput
) )
(T.pack uri.uriFragment) (T.pack uri.uriFragment)
routeToString :: Route -> String
routeToString Home = "#"
routeToString (ListCollection collection) = "#collection/" <> collection
routeToString (EditValue collection fileName) = "#collection/" <> collection <> "/" <> fileName

View File

@@ -19,6 +19,7 @@ import Data.Text qualified as T
import Form qualified as F import Form qualified as F
import Miso import Miso
import Miso.String (toMisoString) import Miso.String (toMisoString)
import Route
data Schema = Schema data Schema = Schema
{ id :: String, { id :: String,
@@ -66,8 +67,8 @@ viewSchema schema =
) )
<$> (M.toList properties) <$> (M.toList properties)
schemaTable :: Schema -> [A.Value] -> View action schemaTable :: String -> Schema -> [A.Value] -> View action
schemaTable schema values = schemaTable collection schema values =
table_ [] [thead, tbody] table_ [] [thead, tbody]
where where
thead = thead =
@@ -85,10 +86,19 @@ schemaTable schema values =
[ tr_ [ tr_
[] []
[ td_ [] $ [ td_ [] $
[ text $ [ case (k, getO (AK.fromString k) value) of
case getO (AK.fromString k) value of ("$fileName", A.String fn) ->
A.String s -> toMisoString s a_
value -> toMisoString (A.encode value) [ href_
(toMisoString (routeToString (EditValue collection (T.unpack fn))))
]
[ text (toMisoString fn)
]
(_, v) ->
text $
case v of
A.String s -> toMisoString s
_ -> toMisoString (A.encode v)
] ]
| k <- M.keys properties | k <- M.keys properties
] ]