2017-02-25 19:13:55 +01:00
|
|
|
module Handler.SubmissionView where
|
|
|
|
|
|
|
|
import Import
|
|
|
|
import Handler.Shared
|
|
|
|
import PersistSHA1
|
2018-11-10 11:20:17 +01:00
|
|
|
import Handler.TagUtils
|
2017-02-25 19:13:55 +01:00
|
|
|
|
|
|
|
import Data.Text as T(pack)
|
|
|
|
|
2018-11-12 14:12:51 +01:00
|
|
|
import qualified Yesod.Table as Table
|
|
|
|
import Yesod.Table (Table)
|
|
|
|
|
2017-02-25 19:13:55 +01:00
|
|
|
data FullSubmissionInfo = FullSubmissionInfo {
|
|
|
|
fsiSubmissionId :: SubmissionId,
|
|
|
|
fsiSubmission :: Submission,
|
|
|
|
fsiUser :: User,
|
|
|
|
fsiRepo :: Repo,
|
2018-06-06 13:43:17 +02:00
|
|
|
fsiChallenge :: Challenge,
|
|
|
|
fsiChallengeRepo :: Repo,
|
2018-11-10 11:20:17 +01:00
|
|
|
fsiScheme :: RepoScheme,
|
2018-11-12 20:41:46 +01:00
|
|
|
fsiTags :: [(Entity Tag, Entity SubmissionTag)],
|
|
|
|
fsiExternalLinks :: [Entity ExternalLink] }
|
2017-02-25 19:13:55 +01:00
|
|
|
|
|
|
|
getFullInfo :: Entity Submission -> Handler FullSubmissionInfo
|
|
|
|
getFullInfo (Entity submissionId submission) = do
|
|
|
|
repo <- runDB $ get404 $ submissionRepo submission
|
|
|
|
user <- runDB $ get404 $ submissionSubmitter submission
|
|
|
|
challenge <- runDB $ get404 $ submissionChallenge submission
|
2018-06-06 13:43:17 +02:00
|
|
|
challengeRepo <- runDB $ get404 $ challengePublicRepo challenge
|
|
|
|
|
2018-11-10 11:20:17 +01:00
|
|
|
tags <- runDB $ getTags submissionId
|
|
|
|
|
2018-11-12 20:41:46 +01:00
|
|
|
links <- runDB $ selectList [ExternalLinkSubmission ==. submissionId] [Asc ExternalLinkTitle]
|
|
|
|
|
2018-06-06 13:43:17 +02:00
|
|
|
app <- getYesod
|
|
|
|
let scheme = appRepoScheme $ appSettings app
|
|
|
|
|
2017-02-25 19:13:55 +01:00
|
|
|
return $ FullSubmissionInfo {
|
|
|
|
fsiSubmissionId = submissionId,
|
|
|
|
fsiSubmission = submission,
|
|
|
|
fsiUser = user,
|
|
|
|
fsiRepo = repo,
|
2018-06-06 13:43:17 +02:00
|
|
|
fsiChallenge = challenge,
|
|
|
|
fsiChallengeRepo = challengeRepo,
|
2018-11-10 11:20:17 +01:00
|
|
|
fsiScheme = scheme,
|
2018-11-12 20:41:46 +01:00
|
|
|
fsiTags = tags,
|
|
|
|
fsiExternalLinks = links }
|
2018-06-06 13:43:17 +02:00
|
|
|
|
2017-02-25 19:13:55 +01:00
|
|
|
getTags submissionId = do
|
|
|
|
sts <- selectList [SubmissionTagSubmission ==. submissionId] []
|
2017-02-25 22:53:17 +01:00
|
|
|
let tagIds = Import.map (submissionTagTag . entityVal) sts
|
|
|
|
tags <- mapM get404 $ tagIds
|
2017-05-27 22:31:53 +02:00
|
|
|
let tagEnts = Import.map (\(k, v) -> Entity k v) $ Import.zip tagIds tags
|
|
|
|
return $ zip tagEnts sts
|