diff options
Diffstat (limited to 'frontend/app/Schema.hs')
-rw-r--r-- | frontend/app/Schema.hs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/frontend/app/Schema.hs b/frontend/app/Schema.hs index 1a52f52..bc504cc 100644 --- a/frontend/app/Schema.hs +++ b/frontend/app/Schema.hs @@ -18,7 +18,7 @@ import Data.Maybe import Data.Text qualified as T import Form qualified as F import Miso -import Miso.String (toMisoString) +import Miso.String (MisoString, fromMisoString, toMisoString) import Route data Schema = Schema @@ -67,7 +67,7 @@ viewSchema schema = ) <$> (M.toList properties) -schemaTable :: String -> Schema -> [A.Value] -> View action +schemaTable :: MisoString -> Schema -> [A.Object] -> View action schemaTable collection schema values = table_ [] [thead, tbody] where @@ -90,7 +90,7 @@ schemaTable collection schema values = ("$fileName", A.String fn) -> a_ [ href_ - (toMisoString (routeToString (EditValue collection (T.unpack fn)))) + (routeToMisoString (EditValue collection (toMisoString fn))) ] [ text (toMisoString fn) ] @@ -105,7 +105,7 @@ schemaTable collection schema values = | value <- values ] -schemaForm :: Schema -> F.Form A.Value A.Value +schemaForm :: Schema -> F.Form A.Object A.Object schemaForm schema = fmap mergeJson . sequence $ case schema.type_ of @@ -113,36 +113,36 @@ schemaForm schema = ( \(AK.fromString -> k, v) -> case v of "string" -> - A.Object . AM.singleton k + AM.singleton k <$> ( F.mapValues (getO k) (setO k) $ - fmap A.String . F.mapValues fromJson toJson $ - F.input (AK.toString k) + fmap (A.String . fromMisoString) . F.mapValues fromJson toJson $ + F.input (toMisoString (AK.toString k)) ) "string?" -> - A.Object . AM.singleton k + AM.singleton k <$> ( F.mapValues (getO k) (setO k) - $ fmap (maybe A.Null A.String) + $ fmap (maybe A.Null (A.String . fromMisoString)) . F.mapValues fromJson toJson - $ F.optional (F.input (AK.toString k)) + $ F.optional (F.input (toMisoString (AK.toString k))) ) ) <$> (M.toList properties) -mergeJson :: [A.Value] -> A.Value -mergeJson = foldl' mergeObject (A.Object AM.empty) +mergeJson :: [A.Object] -> A.Object +mergeJson = foldl' mergeObject AM.empty -mergeObject :: A.Value -> A.Value -> A.Value -mergeObject (A.Object kvs) (A.Object kvs') = A.Object (AM.union kvs kvs') +mergeObject :: A.Object -> A.Object -> A.Object +mergeObject kvs kvs' = AM.union kvs kvs' -fromJson :: A.Value -> T.Text -fromJson (A.String x) = x +fromJson :: A.Value -> MisoString +fromJson (A.String x) = toMisoString x fromJson _ = "" -toJson :: T.Text -> A.Value -> A.Value -toJson x _ = A.String x +toJson :: MisoString -> A.Value -> A.Value +toJson x _ = A.String (fromMisoString x) -getO :: AK.Key -> A.Value -> A.Value -getO k (A.Object kvs) = fromMaybe A.Null (AM.lookup k kvs) +getO :: AK.Key -> A.Object -> A.Value +getO k kvs = fromMaybe A.Null (AM.lookup k kvs) -setO :: AK.Key -> A.Value -> A.Value -> A.Value -setO k v (A.Object kvs) = A.Object (AM.insert k v kvs) +setO :: AK.Key -> A.Value -> A.Object -> A.Object +setO k v kvs = AM.insert k v kvs |