add table for courses, challenge could be selected for an achievement

This commit is contained in:
Filip Gralinski 2017-09-29 14:50:09 +02:00
parent 63806e7e61
commit 0a745175aa
3 changed files with 15 additions and 7 deletions

View File

@ -30,11 +30,8 @@ postAchievementsR = do
mUser <- maybeAuth
when (checkIfAdmin mUser) $ do
case result of
FormSuccess (name, description, points, deadlineDay, deadlineTime, maxSubmitters, mTags) -> do
-- @TODO for the time being hardcoded
Just challengeEnt <- runDB $ getBy $ UniqueName "petite-difference-challenge2"
achievementId <- runDB $ insert $ Achievement name (entityKey challengeEnt) points description (UTCTime { utctDay = deadlineDay, utctDayTime = timeOfDayToTime deadlineTime }) maxSubmitters
FormSuccess (name, description, points, deadlineDay, deadlineTime, maxSubmitters, mTags, challengeId) -> do
achievementId <- runDB $ insert $ Achievement name challengeId points description (UTCTime { utctDay = deadlineDay, utctDayTime = timeOfDayToTime deadlineTime }) maxSubmitters
tids <- runDB $ tagsAsTextToTagIds mTags
@ -162,8 +159,8 @@ formatMaxSubmitters :: Maybe Int -> String
formatMaxSubmitters Nothing = "no limit"
formatMaxSubmitters (Just m) = show m
achievementForm :: Form (Text, Maybe Text, Int, Day, TimeOfDay, Maybe Int, Maybe Text)
achievementForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,)
achievementForm :: Form (Text, Maybe Text, Int, Day, TimeOfDay, Maybe Int, Maybe Text, ChallengeId)
achievementForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,,)
<$> areq textField (bfs MsgAchievementName) Nothing
<*> aopt textField (bfs MsgAchievementDescription) Nothing
<*> areq intField (bfs MsgAchievementPoints) Nothing
@ -171,3 +168,10 @@ achievementForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,)
<*> areq timeFieldTypeTime (bfs MsgAchievementDeadlineTime) Nothing
<*> aopt intField (bfs MsgAchievementMaxWinners) Nothing
<*> aopt textField (tagsfs MsgAchievementTags) Nothing
<*> challengesSelectFieldList
challengesSelectFieldList = areq (selectField challenges) (bfs MsgChallenge) Nothing
where
challenges = do
challengeEnts <- runDB $ selectList [] [Asc ChallengeTitle]
optionsPairs $ Import.map (\ch -> (challengeTitle $ entityVal ch, entityKey ch)) challengeEnts

View File

@ -101,4 +101,7 @@ WorkingOn
user UserId
finalSubmission SubmissionId Maybe
UniqueWorkingOnAchievementUser achievement user
Course
name Text
UniqueCourseName name
-- By default this file is used in Model.hs (which is imported by Foundation.hs)

View File

@ -48,3 +48,4 @@ WantToBeAnonimised: I want to stay anonymous for other user of Gonito.net
YourScore: your score
PasswordForNewAccount: enter a password for your new account
SubmissionDescriptionTooltip: the first non-empty line of the commit message will be used, if this is left empty
Challenge: challenge