module Web.View.WidgetPatterns.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Data.Aeson (encode) import qualified Data.ByteString.Lazy.Char8 as BL data ShowView = ShowView { pattern :: !WidgetPattern , hub :: !Hub , versions :: ![WidgetPatternVersion] , adopterCount :: !Int , anonCount :: !Int , meanFriction :: !(Maybe Double) , outcomeCount :: !Int } instance View ShowView where html ShowView { .. } = [hsx|
← Widget Patterns

{pattern.name}

{pattern.widgetType} {if pattern.isCrossHub then [hsx|cross-hub|] else mempty} {if pattern.isPublished then [hsx|published|] else [hsx|draft|]}

Hub: {hub.name}

{tshow adopterCount} adopters

{maybe mempty (\d -> [hsx|

{d}

|]) pattern.description} {aggregatePanel adopterCount anonCount meanFriction outcomeCount}
{if not pattern.isPublished then [hsx| Edit Publish |] else [hsx| Adopt Pattern |]}

Version History

{if null versions then [hsx|

No versions published yet.

|] else [hsx|
{forEach versions renderVersionRow}
|]} {if pattern.isPublished then [hsx|

Publish New Version

{csrfTokenFormField}
|] else mempty} |] -- | Aggregate friction/outcome panel (T07) aggregatePanel :: Int -> Int -> Maybe Double -> Int -> Html aggregatePanel adopterCount anonCount meanFriction outcomeCount = [hsx|

Adoption Metrics

Total Adopters

{tshow adopterCount}

{if anonCount > 0 then [hsx|

{tshow anonCount} opted out of aggregate feedback

|] else mempty}

Mean Friction Score

{maybe "—" (\f -> tshow (round f :: Int)) meanFriction}

non-anonymous adopters

Outcome Signals

{tshow outcomeCount}

|] renderVersionRow :: WidgetPatternVersion -> Html renderVersionRow v = [hsx|
v{tshow v.versionNumber} {tshow v.publishedAt}
{maybe mempty (\c -> [hsx|

{c}

|]) v.changelog}
Definition
{cs (BL.unpack (encode v.definition)) :: Text}
|]