working with tags

This commit is contained in:
nek0 2014-09-14 05:03:13 +02:00
parent 3046d2416d
commit 57610a8b99
6 changed files with 41 additions and 0 deletions

View file

@ -45,6 +45,7 @@ import Handler.Admin
import Handler.AdminProfileSettings import Handler.AdminProfileSettings
import Handler.AdminAlbumSettings import Handler.AdminAlbumSettings
import Handler.AdminMediumSettings import Handler.AdminMediumSettings
import Handler.Tag
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- of the call to mkYesodData which occurs in Foundation.hs. Please see the

16
Handler/Tag.hs Normal file
View file

@ -0,0 +1,16 @@
module Handler.Tag where
import Import
import Data.Maybe
getTagR :: Text -> Handler Html
getTagR tag = do
tempMedia <- runDB $ selectList [] [Desc MediumTitle]
almostMedia <- mapM (\a -> do
case tag `elem` (mediumTags $ entityVal a) of
True -> return (Just a)
False -> return Nothing
) tempMedia
media <- return $ removeItem Nothing almostMedia
defaultLayout $ do
$(widgetFile "tagMedia")

View file

@ -36,3 +36,4 @@
/admin/medium AdminMediaR GET /admin/medium AdminMediaR GET
/admin/medium/#MediumId AdminMediumSettingsR GET POST /admin/medium/#MediumId AdminMediumSettingsR GET POST
/admin/meidum/#MediumId/delete AdminMediumDeleteR GET /admin/meidum/#MediumId/delete AdminMediumDeleteR GET
/tag/#Text TagR GET

View file

@ -38,6 +38,7 @@ library
Handler.AdminProfileSettings Handler.AdminProfileSettings
Handler.AdminAlbumSettings Handler.AdminAlbumSettings
Handler.AdminMediumSettings Handler.AdminMediumSettings
Handler.Tag
if flag(dev) || flag(library-only) if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT cpp-options: -DDEVELOPMENT

View file

@ -13,5 +13,14 @@ by <a href=@{UserR ownerName}>#{ownerName}</a> from album <a href=@{AlbumR album
Description:<br> Description:<br>
#{mediumDescription medium} #{mediumDescription medium}
<br> <br>
<div class="tags">
Tags:
<ul>
$if null (mediumTags medium)
none
$else
$forall tag <- mediumTags medium
<li>
<a href=@{TagR tag}>#{tag}
$if presence == True $if presence == True
<a href=@{MediumSettingsR mediumId}>Change medium settings <a href=@{MediumSettingsR mediumId}>Change medium settings

13
templates/tagMedia.hamlet Normal file
View file

@ -0,0 +1,13 @@
$newline always
<h3>#{tag}
$if null media
There are no media tagged with #{tag}
$else
<ul>
$forall Just (Entity mId m) <- media
<li>
<a href=@{MediumR mId}>
<img src=#{mediumPath m}>
#{mediumTitle m}