From 0a745175aa316b2c38a8023a91e56000c32cf4c9 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Fri, 29 Sep 2017 14:50:09 +0200 Subject: [PATCH] add table for courses, challenge could be selected for an achievement --- Handler/Achievements.hs | 18 +++++++++++------- config/models | 3 +++ messages/en.msg | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Handler/Achievements.hs b/Handler/Achievements.hs index 79a1515..3c04427 100644 --- a/Handler/Achievements.hs +++ b/Handler/Achievements.hs @@ -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 diff --git a/config/models b/config/models index 273dfcf..cb937ca 100644 --- a/config/models +++ b/config/models @@ -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) diff --git a/messages/en.msg b/messages/en.msg index 6881a9d..c89ae96 100644 --- a/messages/en.msg +++ b/messages/en.msg @@ -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