From c8500ea1280769a2d492157d95b017bc4aeeeab0 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 3 Oct 2017 07:23:52 +0200 Subject: [PATCH] show course in Achievements --- Handler/AchievementUtils.hs | 5 +++++ Handler/Achievements.hs | 3 ++- config/models | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Handler/AchievementUtils.hs b/Handler/AchievementUtils.hs index 12342da..1ec6f83 100644 --- a/Handler/AchievementUtils.hs +++ b/Handler/AchievementUtils.hs @@ -9,6 +9,7 @@ import qualified Yesod.Table as Table data AchievementInfo = AchievementInfo { achievementInfoId :: AchievementId, achievementInfoName :: Text, + achievementInfoCourse :: Entity Course, achievementInfoChallenge :: Entity Challenge, achievementInfoDescription :: Maybe Text, achievementInfoPoints :: Int, @@ -32,9 +33,13 @@ getAchievementInfo mUser (Entity achievementId achievement) = do let challengeId = achievementChallenge achievement challenge <- get404 challengeId + let courseId = achievementCourse achievement + course <- get404 courseId + return $ AchievementInfo { achievementInfoId = achievementId, achievementInfoName = achievementName achievement, + achievementInfoCourse = Entity courseId course, achievementInfoChallenge = Entity challengeId challenge, achievementInfoDescription = achievementDescription achievement, achievementInfoPoints = achievementPoints achievement, diff --git a/Handler/Achievements.hs b/Handler/Achievements.hs index 58502b1..2501ff7 100644 --- a/Handler/Achievements.hs +++ b/Handler/Achievements.hs @@ -31,7 +31,7 @@ postAchievementsR = do when (checkIfAdmin mUser) $ do case result of FormSuccess (name, description, points, deadlineDay, deadlineTime, maxSubmitters, mTags, challengeId, courseId) -> do - achievementId <- runDB $ insert $ Achievement name challengeId points description (UTCTime { utctDay = deadlineDay, utctDayTime = timeOfDayToTime deadlineTime }) maxSubmitters (Just courseId) + achievementId <- runDB $ insert $ Achievement name challengeId points description (UTCTime { utctDay = deadlineDay, utctDayTime = timeOfDayToTime deadlineTime }) maxSubmitters courseId tids <- runDB $ tagsAsTextToTagIds mTags @@ -56,6 +56,7 @@ doAchievements mUser formWidget formEnctype = do achievementsTable :: Table.Table App (AchievementInfo) achievementsTable = mempty ++ Table.text "achievement" achievementInfoName + ++ Table.text "course" (courseName . entityVal . achievementInfoCourse) ++ Table.linked "challenge" (challengeTitle . entityVal . achievementInfoChallenge) (ShowChallengeR . challengeName . entityVal . achievementInfoChallenge) ++ achievementDescriptionCell id ++ Table.int "points" achievementInfoPoints diff --git a/config/models b/config/models index a6b9c9a..1cf4aca 100644 --- a/config/models +++ b/config/models @@ -91,7 +91,7 @@ Achievement description Text Maybe deadline UTCTime maxWinners Int Maybe - course CourseId Maybe + course CourseId UniqueAchievementName name AchievementTag achievement AchievementId