module Web.View.HubCapabilityManifests.Edit where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () import Data.Aeson (Value(..), encode, decode) import qualified Data.Vector as V import qualified Data.ByteString.Lazy.Char8 as BL data EditView = EditView { manifest :: !HubCapabilityManifest , hub :: !Hub , widgetTypeEntries :: ![WidgetTypeRegistry] , eventTypeEntries :: ![EventTypeRegistry] , categoryEntries :: ![AnnotationCategoryRegistry] , policyScopeEntries :: ![PolicyScopeRegistry] } instance View EditView where html EditView { .. } = [hsx|
← {hub.name} Manifest

Edit Capability Manifest — {hub.name}

Declare the type names this hub owns. After saving, activate the manifest to register them.

{renderReadOnlyWarning manifest}

Manifest Details

{typeArraySection "Declared Widget Types" "declaredWidgetTypes" manifest.declaredWidgetTypes widgetTypeEntries} {typeArraySection "Declared Event Types" "declaredEventTypes" manifest.declaredEventTypes eventTypeEntries} {typeArraySection2 "Declared Annotation Categories" "declaredAnnotationCategories" manifest.declaredAnnotationCategories categoryEntries} {typeArraySection3 "Declared Policy Scopes" "declaredPolicyScopes" manifest.declaredPolicyScopes policyScopeEntries}
{if manifest.status == "draft" then renderActivateLink manifest.id else mempty}
|] renderActivateLink :: Id HubCapabilityManifest -> Html renderActivateLink mid = [hsx| Save & Activate |] -- | Render a JSON array text area with available registry options shown below. typeArraySection :: Text -> Text -> Value -> [WidgetTypeRegistry] -> Html typeArraySection title fieldName val entries = [hsx|

{title}

JSON array of type names to declare ownership of. Names that don't yet exist in the registry will be created on activation.

Registered: {intercalate ", " (map (.name) entries)}

|] typeArraySection2 :: Text -> Text -> Value -> [AnnotationCategoryRegistry] -> Html typeArraySection2 title fieldName val entries = [hsx|

{title}

JSON array of annotation category names.

Registered: {intercalate ", " (map (.name) entries)}

|] typeArraySection3 :: Text -> Text -> Value -> [PolicyScopeRegistry] -> Html typeArraySection3 title fieldName val entries = [hsx|

{title}

JSON array of policy scope names.

Registered: {intercalate ", " (map (.name) entries)}

|] renderReadOnlyWarning :: HubCapabilityManifest -> Html renderReadOnlyWarning manifest | manifest.status /= "draft" = [hsx|
This manifest is {manifest.status} and is read-only. Retire it first to create a new draft amendment.
|] | otherwise = mempty valueText :: Value -> Text valueText v = cs (BL.unpack (encode v)) intercalate :: Text -> [Text] -> Text intercalate _ [] = "" intercalate _ [x] = x intercalate sep (x:xs) = x <> sep <> intercalate sep xs