list and show challenges

This commit is contained in:
Filip Gralinski 2015-09-04 23:23:32 +02:00
parent c05a3c55ef
commit 8b885c0dca
10 changed files with 38 additions and 0 deletions

View File

@ -37,6 +37,8 @@ import Handler.Common
import Handler.Fay import Handler.Fay
import Handler.Home import Handler.Home
import Handler.CreateChallenge import Handler.CreateChallenge
import Handler.ListChallenges
import Handler.ShowChallenge
import Handler.Shared import Handler.Shared
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half

13
Handler/ListChallenges.hs Normal file
View File

@ -0,0 +1,13 @@
module Handler.ListChallenges where
import Import
getListChallengesR :: Handler Html
getListChallengesR = do
challenges' <- runDB $ selectList [] [Desc ChallengeStamp]
let challenges = map (\(Entity _ v) -> v) challenges'
defaultLayout $ do
setTitle "List challenges"
$(widgetFile "list-challenges")
listChallengesCore challenges = $(widgetFile "list-challenges-core")

10
Handler/ShowChallenge.hs Normal file
View File

@ -0,0 +1,10 @@
module Handler.ShowChallenge where
import Import
getShowChallengeR :: Text -> Handler Html
getShowChallengeR name = do
(Entity _ challenge) <- runDB $ getBy404 $ UniqueName name
defaultLayout $ do
setTitle "Show a challenge"
$(widgetFile "show-challenge")

View File

@ -9,3 +9,5 @@
/create-challenge CreateChallengeR GET POST /create-challenge CreateChallengeR GET POST
/view-progress/#Int ViewProgressR GET /view-progress/#Int ViewProgressR GET
/list-challenges ListChallengesR GET
/challenge/#Text ShowChallengeR GET

View File

@ -26,7 +26,9 @@ library
Handler.CreateChallenge Handler.CreateChallenge
Handler.Fay Handler.Fay
Handler.Home Handler.Home
Handler.ListChallenges
Handler.Shared Handler.Shared
Handler.ShowChallenge
Handler.Extract Handler.Extract
if flag(dev) || flag(library-only) if flag(dev) || flag(library-only)

View File

@ -7,3 +7,4 @@ PublicUrl: public repo (URL)
PrivateUrl: private repo (URL) PrivateUrl: private repo (URL)
Branch: branch Branch: branch
Add: Add! Add: Add!
ListChallenges: list challenges

View File

@ -2,6 +2,7 @@
$maybe user <- maybeUser $maybe user <- maybeUser
_{MsgLoggedAs} #{userIdent $ entityVal user} _{MsgLoggedAs} #{userIdent $ entityVal user}
\ | <a href="@{CreateChallengeR}">_{MsgCreateChallenge}</a> \ | <a href="@{CreateChallengeR}">_{MsgCreateChallenge}</a>
\ | <a href="@{ListChallengesR}">_{MsgListChallenges}</a>
\ | <a href="@{AuthR LogoutR}">_{MsgLogOut}</a> \ | <a href="@{AuthR LogoutR}">_{MsgLogOut}</a>
$nothing $nothing
<a href="@{AuthR LoginR}">_{MsgLogIn}</a> <a href="@{AuthR LoginR}">_{MsgLogIn}</a>

View File

@ -0,0 +1,4 @@
$forall challenge <- challenges
<div .challenge-item>
<p .challenge-title><a .challenge-link href="@{ShowChallengeR (challengeName challenge)}">#{challengeTitle challenge}</a>
<p .challenge-description>#{challengeDescription challenge}

View File

@ -0,0 +1 @@
^{listChallengesCore challenges}

View File

@ -0,0 +1,2 @@
<p .challenge-title>#{challengeTitle challenge}
<p .challenge-description>#{challengeDescription challenge}