From 77a81b7a2f5ebd8befce7eaf2fcc7308ab418efa Mon Sep 17 00:00:00 2001 From: Chris Done Date: Fri, 14 Nov 2014 13:54:50 +0100 Subject: [PATCH] Display count for tags list/sort by that count (#26) --- Handler/Tag.hs | 9 +++++---- templates/tag-list.hamlet | 12 ++++++++---- templates/tag-list.lucius | 4 ++++ templates/tag.hamlet | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Handler/Tag.hs b/Handler/Tag.hs index 09087f0..8966dc5 100644 --- a/Handler/Tag.hs +++ b/Handler/Tag.hs @@ -7,10 +7,11 @@ import Import getTagListR :: Handler Html getTagListR = do - tags <- fmap (map (\(E.Value v) -> v)) $ runDB $ - E.selectDistinct $ E.from $ \tag -> do - E.orderBy [E.asc (tag E.^. TagTag)] - return (tag E.^. TagTag) + tags <- fmap (zip [0::Int ..] . (map (\(E.Value v,E.Value i) -> (v,i::Int)))) $ runDB $ + E.select $ E.from $ \tag -> do + E.groupBy (tag E.^. TagTag) + E.orderBy [E.desc (E.count (tag E.^. TagTag) :: E.SqlExpr (E.Value Int))] + return (tag E.^. TagTag, E.count (tag E.^. TagTag)) defaultLayout $ do setTitle "Stackage tags" $(widgetFile "tag-list") diff --git a/templates/tag-list.hamlet b/templates/tag-list.hamlet index c98e4f1..58c6432 100644 --- a/templates/tag-list.hamlet +++ b/templates/tag-list.hamlet @@ -1,7 +1,11 @@ +$newline never

Tags -