module Web.View.Widgets.New where
import Web.View.Prelude
data NewView = NewView
{ widget :: !Widget
, hubs :: ![Hub]
, adapterSpecs :: ![WidgetAdapterSpec]
, widgetTypes :: ![WidgetTypeRegistry]
, policyScopes :: ![PolicyScopeRegistry]
}
instance View NewView where
html NewView { .. } = [hsx|
Register Widget
{renderForm widget hubs adapterSpecs widgetTypes policyScopes}
|]
renderForm :: Widget -> [Hub] -> [WidgetAdapterSpec] -> [WidgetTypeRegistry] -> [PolicyScopeRegistry] -> Html
renderForm widget hubs adapterSpecs widgetTypes policyScopes = formFor widget [hsx|
{textField #name}
{selectField #widgetType (widgetTypeOptions widgetTypes)}
{selectField #hubId (hubOptions hubs)}
{textField #capabilityRef}
{textField #viewContext}
{selectField #policyScope (policyScopeOptions policyScopes)}
{selectField #status statusOptions}
{submitButton}
|]
renderAdapterOption :: WidgetAdapterSpec -> Html
renderAdapterOption s = [hsx||]
hubOptions :: [Hub] -> [(Text, Id Hub)]
hubOptions hubs = map (\h -> (h.name, h.id)) hubs
widgetTypeOptions :: [WidgetTypeRegistry] -> [(Text, Text)]
widgetTypeOptions = map (\r -> (r.label_, r.name))
policyScopeOptions :: [PolicyScopeRegistry] -> [(Text, Text)]
policyScopeOptions = map (\r -> (r.label_, r.name))
statusOptions :: [(Text, Text)]
statusOptions =
[ ("Active", "active")
, ("Deprecated", "deprecated")
, ("Draft", "draft")
]