module Web.View.GovernanceTemplates.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Data.Aeson (Value(..), decode, encode) import qualified Data.ByteString.Lazy.Char8 as BL data ShowView = ShowView { template :: !GovernanceTemplate , hub :: !Hub , cloneCount :: !Int } instance View ShowView where html ShowView { .. } = [hsx|
← Governance Templates

{template.name}

{if template.isPublished then [hsx|published|] else [hsx|draft|]}

Hub: {hub.name}

{tshow cloneCount} clones

{maybe mempty (\d -> [hsx|

{d}

|]) template.description}

Categories

{forEach (jsonArrayTexts template.categories) renderCategoryTag} {if null (jsonArrayTexts template.categories) then [hsx|None|] else mempty}

Template Body

                {cs (BL.unpack (encode template.templateBody)) :: Text}
            
{if template.isPublished then [hsx| Clone to My Hub |] else mempty} |] renderCategoryTag :: Text -> Html renderCategoryTag cat = [hsx| {cat} |] jsonArrayTexts :: Value -> [Text] jsonArrayTexts val = case decode (encode val) of Just (arr :: [Text]) -> arr Nothing -> []