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]
, adapterSpecs :: ![WidgetAdapterSpec]
}
instance View NewView where
html NewView { .. } = [hsx|
Register Widget
{renderForm widget hubs adapterSpecs}
|]
renderForm :: Widget -> [Hub] -> [WidgetAdapterSpec] -> Html
renderForm widget hubs adapterSpecs = 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")
]