From 612da78d17c575cd5ade1de62dc1a3c514129de0 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Thu, 6 Jun 2024 15:31:16 +0200
Subject: link to edit page from list page

---
 frontend/app/Page/ListCollection.hs |  2 +-
 frontend/app/Route.hs               |  6 ++++++
 frontend/app/Schema.hs              | 22 ++++++++++++++++------
 3 files changed, 23 insertions(+), 7 deletions(-)

(limited to 'frontend')

diff --git a/frontend/app/Page/ListCollection.hs b/frontend/app/Page/ListCollection.hs
index 16517d9..d08e414 100644
--- a/frontend/app/Page/ListCollection.hs
+++ b/frontend/app/Page/ListCollection.hs
@@ -41,7 +41,7 @@ viewModel :: Model -> View Action
 viewModel m =
   div_ [] $
     [ h3_ [] [text "entities"],
-      schemaTable m.schema m.posts,
+      schemaTable m.collection m.schema m.posts,
       h3_ [] [text "schema"],
       viewSchema m.schema
     ]
diff --git a/frontend/app/Route.hs b/frontend/app/Route.hs
index 18a3273..546939c 100644
--- a/frontend/app/Route.hs
+++ b/frontend/app/Route.hs
@@ -1,6 +1,7 @@
 module Route
   ( Route (..),
     parseURI,
+    routeToString,
   )
 where
 
@@ -32,3 +33,8 @@ parseURI uri =
           <* P.endOfInput
       )
       (T.pack uri.uriFragment)
+
+routeToString :: Route -> String
+routeToString Home = "#"
+routeToString (ListCollection collection) = "#collection/" <> collection
+routeToString (EditValue collection fileName) = "#collection/" <> collection <> "/" <> fileName
diff --git a/frontend/app/Schema.hs b/frontend/app/Schema.hs
index ee958d8..0530061 100644
--- a/frontend/app/Schema.hs
+++ b/frontend/app/Schema.hs
@@ -19,6 +19,7 @@ import Data.Text qualified as T
 import Form qualified as F
 import Miso
 import Miso.String (toMisoString)
+import Route
 
 data Schema = Schema
   { id :: String,
@@ -66,8 +67,8 @@ viewSchema schema =
         )
           <$> (M.toList properties)
 
-schemaTable :: Schema -> [A.Value] -> View action
-schemaTable schema values =
+schemaTable :: String -> Schema -> [A.Value] -> View action
+schemaTable collection schema values =
   table_ [] [thead, tbody]
   where
     thead =
@@ -85,10 +86,19 @@ schemaTable schema values =
           [ tr_
               []
               [ td_ [] $
-                  [ text $
-                      case getO (AK.fromString k) value of
-                        A.String s -> toMisoString s
-                        value -> toMisoString (A.encode value)
+                  [ case (k, getO (AK.fromString k) value) of
+                      ("$fileName", A.String fn) ->
+                        a_
+                          [ 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
               ]
-- 
cgit v1.2.3