Show downstream submissions

This commit is contained in:
Filip Gralinski 2018-11-17 13:49:44 +01:00
parent 879eb4e044
commit ccae7e284f
5 changed files with 57 additions and 39 deletions

View File

@ -10,7 +10,6 @@ import PersistSHA1
import Handler.Tables import Handler.Tables
import qualified Yesod.Table as Table import qualified Yesod.Table as Table
import Yesod.Table (Table)
import Database.Persist.Sql import Database.Persist.Sql
@ -24,7 +23,8 @@ import Data.List (nub)
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3) import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3)
rawCommitQuery :: (MonadIO m, RawSql a) => Text -> ReaderT SqlBackend m [a] rawCommitQuery :: (MonadIO m, RawSql a) => Text -> ReaderT SqlBackend m [a]
rawCommitQuery sha1Prefix = rawSql "SELECT ?? FROM submission WHERE is_public AND cast(commit as text) like ?" [PersistText $ "\\\\x" ++ sha1Prefix ++ "%"] rawCommitQuery sha1Prefix =
rawSql "SELECT ?? FROM submission WHERE is_public AND cast(commit as text) like ?" [PersistText $ "\\\\x" ++ sha1Prefix ++ "%"]
findSubmissions :: Text -> Handler [FullSubmissionInfo] findSubmissions :: Text -> Handler [FullSubmissionInfo]
findSubmissions sha1Prefix = do findSubmissions sha1Prefix = do
@ -111,6 +111,7 @@ resultTable (Entity submissionId submission) = do
$(widgetFile "result-table") $(widgetFile "result-table")
queryResult :: FullSubmissionInfo -> WidgetFor App ()
queryResult submission = do queryResult submission = do
$(widgetFile "query-result") $(widgetFile "query-result")
where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission

View File

@ -1,14 +1,9 @@
module Handler.SubmissionView where module Handler.SubmissionView where
import Import import Import
import Handler.Shared
import PersistSHA1
import Handler.TagUtils
import Data.Text as T(pack) import qualified Database.Esqueleto as E
import Database.Esqueleto ((^.))
import qualified Yesod.Table as Table
import Yesod.Table (Table)
data FullSubmissionInfo = FullSubmissionInfo { data FullSubmissionInfo = FullSubmissionInfo {
fsiSubmissionId :: SubmissionId, fsiSubmissionId :: SubmissionId,
@ -19,7 +14,8 @@ data FullSubmissionInfo = FullSubmissionInfo {
fsiChallengeRepo :: Repo, fsiChallengeRepo :: Repo,
fsiScheme :: RepoScheme, fsiScheme :: RepoScheme,
fsiTags :: [(Entity Tag, Entity SubmissionTag)], fsiTags :: [(Entity Tag, Entity SubmissionTag)],
fsiExternalLinks :: [Entity ExternalLink] } fsiExternalLinks :: [Entity ExternalLink],
fsiSuperSubmissions :: [FullSubmissionInfo] }
getFullInfo :: Entity Submission -> Handler FullSubmissionInfo getFullInfo :: Entity Submission -> Handler FullSubmissionInfo
getFullInfo (Entity submissionId submission) = do getFullInfo (Entity submissionId submission) = do
@ -35,6 +31,13 @@ getFullInfo (Entity submissionId submission) = do
app <- getYesod app <- getYesod
let scheme = appRepoScheme $ appSettings app let scheme = appRepoScheme $ appSettings app
superSubmissions <- runDB $ E.select $ E.from $ \(submission', dependency) -> do
E.where_ (submission' ^. SubmissionCommit E.==. dependency ^. DependencySuperRepoCommit
E.&&. dependency ^. DependencySubRepoCommit E.==. (E.val (submissionCommit submission)))
return submission'
superSubmissionFsis <- mapM getFullInfo superSubmissions
return $ FullSubmissionInfo { return $ FullSubmissionInfo {
fsiSubmissionId = submissionId, fsiSubmissionId = submissionId,
fsiSubmission = submission, fsiSubmission = submission,
@ -44,8 +47,10 @@ getFullInfo (Entity submissionId submission) = do
fsiChallengeRepo = challengeRepo, fsiChallengeRepo = challengeRepo,
fsiScheme = scheme, fsiScheme = scheme,
fsiTags = tags, fsiTags = tags,
fsiExternalLinks = links } fsiExternalLinks = links,
fsiSuperSubmissions = superSubmissionFsis }
getTags :: (BaseBackend backend ~ SqlBackend, MonadIO m, PersistQueryRead backend) => Key Submission -> ReaderT backend m [(Entity Tag, Entity SubmissionTag)]
getTags submissionId = do getTags submissionId = do
sts <- selectList [SubmissionTagSubmission ==. submissionId] [] sts <- selectList [SubmissionTagSubmission ==. submissionId] []
let tagIds = Import.map (submissionTagTag . entityVal) sts let tagIds = Import.map (submissionTagTag . entityVal) sts

View File

@ -1,29 +1,39 @@
<div .subm-commit>#{commitSha1AsText} <div class="media">
<div .subm-description>^{fragmentWithTags (submissionDescription $ fsiSubmission submission) (map fst $ fsiTags submission)} <div class="media-left">
<p>&nbsp;</p> <p class="media-object">
<dl class="dl-horizontal"> <span class="glyphicon glyphicon-asterisk" aria-hidden="hidden">
<dt>challenge <div class="media-body">
<dd><a href="@{ShowChallengeR $ challengeName $ fsiChallenge submission}">#{challengeTitle $ fsiChallenge submission}</a> <div class="media-heading">
<dt>submitter <div .subm-commit>#{commitSha1AsText}
<dd>#{submitter}
<dt>submitted
<dd>#{stamp}
<dt>original repo
<dd><code>#{repoUrl $ fsiRepo submission}</code> / branch <code>#{repoBranch $ fsiRepo submission}</code>
$if submissionIsPublic $ fsiSubmission submission
<dt>publicly available at
<dd><code>#{publicSubmissionRepo}</code> / branch <code>#{publicSubmissionBranch}</code>
<dt>browsable at
<dd><a href="#{browsableUrl}">#{browsableUrl}</a>
<dt>clone by
<dd><code>git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}</code>
$if not (null (fsiExternalLinks submission))
<dt>see also
<dd>
$forall (Entity _ externalLink) <- fsiExternalLinks submission
<a href="#{externalLinkUrl externalLink}">
#{fromMaybe (externalLinkUrl externalLink) (externalLinkTitle externalLink)}
<br>
^{resultTable (Entity (fsiSubmissionId submission) (fsiSubmission submission))}
<hr> <div .subm-description>^{fragmentWithTags (submissionDescription $ fsiSubmission submission) (map fst $ fsiTags submission)}
<p>&nbsp;</p>
<dl class="dl-horizontal">
<dt>challenge
<dd><a href="@{ShowChallengeR $ challengeName $ fsiChallenge submission}">#{challengeTitle $ fsiChallenge submission}</a>
<dt>submitter
<dd>#{submitter}
<dt>submitted
<dd>#{stamp}
<dt>original repo
<dd><code>#{repoUrl $ fsiRepo submission}</code> / branch <code>#{repoBranch $ fsiRepo submission}</code>
$if submissionIsPublic $ fsiSubmission submission
<dt>publicly available at
<dd><code>#{publicSubmissionRepo}</code> / branch <code>#{publicSubmissionBranch}</code>
<dt>browsable at
<dd><a href="#{browsableUrl}">#{browsableUrl}</a>
<dt>clone by
<dd><code>git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}</code>
$if not (null (fsiExternalLinks submission))
<dt>see also
<dd>
$forall (Entity _ externalLink) <- fsiExternalLinks submission
<a href="#{externalLinkUrl externalLink}">
#{fromMaybe (externalLinkUrl externalLink) (externalLinkTitle externalLink)}
<br>
^{resultTable (Entity (fsiSubmissionId submission) (fsiSubmission submission))}
$if not (null (fsiSuperSubmissions submission))
<h4>downstream submissions
$forall superSubmission <- (fsiSuperSubmissions submission)
^{queryResult superSubmission}

View File

@ -6,3 +6,4 @@ $if null submissions
$else $else
$forall submission <- submissions $forall submission <- submissions
^{queryResult submission} ^{queryResult submission}
<hr>

View File

@ -2,6 +2,7 @@
$(document).ready(function() { $(document).ready(function() {
$(#{jsSelector}).DataTable({ $(#{jsSelector}).DataTable({
'pageLength': 50, 'pageLength': 50,
'lengthChange': false,
'order': [[0, 'asc'], [#{delta} + ($.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})).length-1, 'desc']], 'order': [[0, 'asc'], [#{delta} + ($.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})).length-1, 'desc']],
'columnDefs': $.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray}) 'columnDefs': $.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})
}); });