module Web.View.GovernanceTemplates.Index 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 type TemplateIndexRow = (GovernanceTemplate, Int) data IndexView = IndexView { templates :: ![TemplateIndexRow] } instance View IndexView where html IndexView { .. } = [hsx|

Governance Template Library

Published reusable governance templates.

New Template
{forEach templates renderTemplateRow} {if null templates then [hsx|

No published templates yet.

|] else mempty}
|] renderTemplateRow :: TemplateIndexRow -> Html renderTemplateRow (template, cloneCount) = [hsx|
{template.name} {maybe mempty (\d -> [hsx|

{d}

|]) template.description}
{tshow cloneCount} clones
{forEach (jsonArrayTexts template.categories) renderCategoryTag}
|] renderCategoryTag :: Text -> Html renderCategoryTag cat = [hsx| {cat} |] jsonArrayTexts :: Value -> [Text] jsonArrayTexts val = case decode (encode val) of Just (arr :: [Text]) -> arr Nothing -> []