module Web.View.WidgetPatterns.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () 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 crossHubBadge else mempty} {renderPublishedBadge pattern.isPublished}

Hub: {hub.name}

{tshow adopterCount} adopters

{maybe mempty renderPatternDescription pattern.description} {aggregatePanel adopterCount anonCount meanFriction outcomeCount}
{renderPatternActions pattern.isPublished pattern.id}

Version History

{renderVersionHistory versions} {renderPublishNewVersionForm pattern.isPublished pattern.id} |] -- | 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 renderAnonCountNote anonCount 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 renderChangelog v.changelog}
Definition
{cs (BL.unpack (encode v.definition)) :: Text}
|] crossHubBadge :: Html crossHubBadge = [hsx|cross-hub|] renderPublishedBadge :: Bool -> Html renderPublishedBadge True = [hsx|published|] renderPublishedBadge False = [hsx|draft|] renderPatternDescription :: Text -> Html renderPatternDescription d = [hsx|

{d}

|] renderAnonCountNote :: Int -> Html renderAnonCountNote n = [hsx|

{tshow n} opted out of aggregate feedback

|] renderChangelog :: Text -> Html renderChangelog c = [hsx|

{c}

|] renderPatternActions :: Bool -> Id WidgetPattern -> Html renderPatternActions False pid = [hsx| Edit Publish |] renderPatternActions True pid = [hsx| Adopt Pattern |] renderVersionHistory :: [WidgetPatternVersion] -> Html renderVersionHistory [] = [hsx|

No versions published yet.

|] renderVersionHistory vs = [hsx|
{forEach vs renderVersionRow}
|] renderPublishNewVersionForm :: Bool -> Id WidgetPattern -> Html renderPublishNewVersionForm False _ = mempty renderPublishNewVersionForm True pid = [hsx|

Publish New Version

{csrfTokenFormField}
|]