60 lines
1.5 KiB
Haskell
60 lines
1.5 KiB
Haskell
|
|
module Web.View.Widgets.New where
|
||
|
|
|
||
|
|
import Web.Types
|
||
|
|
import Generated.Types
|
||
|
|
import IHP.Prelude
|
||
|
|
import IHP.ViewPrelude
|
||
|
|
|
||
|
|
data NewView = NewView
|
||
|
|
{ widget :: !Widget
|
||
|
|
, hubs :: ![Hub]
|
||
|
|
}
|
||
|
|
|
||
|
|
instance View NewView where
|
||
|
|
html NewView { .. } = [hsx|
|
||
|
|
<div class="max-w-lg">
|
||
|
|
<h1 class="text-2xl font-semibold mb-6">Register Widget</h1>
|
||
|
|
{renderForm widget hubs}
|
||
|
|
</div>
|
||
|
|
|]
|
||
|
|
|
||
|
|
renderForm :: Widget -> [Hub] -> Html
|
||
|
|
renderForm widget hubs = formFor widget [hsx|
|
||
|
|
{textField #name}
|
||
|
|
{selectField #widgetType widgetTypeOptions}
|
||
|
|
{selectField #hubId (hubOptions hubs)}
|
||
|
|
{textField #capabilityRef}
|
||
|
|
{textField #viewContext}
|
||
|
|
{selectField #policyScope policyScopeOptions}
|
||
|
|
{selectField #status statusOptions}
|
||
|
|
{submitButton}
|
||
|
|
|]
|
||
|
|
|
||
|
|
hubOptions :: [Hub] -> [(Text, Id Hub)]
|
||
|
|
hubOptions hubs = map (\h -> (h.name, h.id)) hubs
|
||
|
|
|
||
|
|
widgetTypeOptions :: [(Text, Text)]
|
||
|
|
widgetTypeOptions =
|
||
|
|
[ ("Chart", "chart")
|
||
|
|
, ("Form", "form")
|
||
|
|
, ("Table", "table")
|
||
|
|
, ("Action", "action")
|
||
|
|
, ("Panel", "panel")
|
||
|
|
, ("Navigation", "nav")
|
||
|
|
, ("Other", "other")
|
||
|
|
]
|
||
|
|
|
||
|
|
policyScopeOptions :: [(Text, Text)]
|
||
|
|
policyScopeOptions =
|
||
|
|
[ ("Internal", "internal")
|
||
|
|
, ("Hub", "hub")
|
||
|
|
, ("Public", "public")
|
||
|
|
]
|
||
|
|
|
||
|
|
statusOptions :: [(Text, Text)]
|
||
|
|
statusOptions =
|
||
|
|
[ ("Active", "active")
|
||
|
|
, ("Deprecated", "deprecated")
|
||
|
|
, ("Draft", "draft")
|
||
|
|
]
|