Display count for tags list/sort by that count (#26)

This commit is contained in:
Chris Done 2014-11-14 13:54:50 +01:00
parent df66e5d982
commit 77a81b7a2f
4 changed files with 18 additions and 9 deletions

View File

@ -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")

View File

@ -1,7 +1,11 @@
$newline never
<div .container>
<h1>Tags
<ul .tags>
$forall tag <- tags
<li>
<p .tags>
$forall (i,(tag,count)) <- tags
$if i /= 0
, #
<span .tag>
<a href=@{TagR tag}>
#{tag}
#{tag} #
<span .count>(#{count})

View File

@ -10,3 +10,7 @@
h1 {
margin-bottom: 0.5em;
}
.count {
color: #666;
}

View File

@ -2,7 +2,7 @@ $newline never
<div .container>
<h1>
Packages tagged: #{tag} (
Tag: #{tag} (
<a href=@{TagListR}>
all tags
)