diff --git a/Handler/Query.hs b/Handler/Query.hs index fb56e2b..2ee4129 100644 --- a/Handler/Query.hs +++ b/Handler/Query.hs @@ -10,7 +10,6 @@ import PersistSHA1 import Handler.Tables import qualified Yesod.Table as Table -import Yesod.Table (Table) import Database.Persist.Sql @@ -24,7 +23,8 @@ import Data.List (nub) import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3) 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 sha1Prefix = do @@ -111,6 +111,7 @@ resultTable (Entity submissionId submission) = do $(widgetFile "result-table") +queryResult :: FullSubmissionInfo -> WidgetFor App () queryResult submission = do $(widgetFile "query-result") where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission diff --git a/Handler/SubmissionView.hs b/Handler/SubmissionView.hs index f3bfe2c..bfcc5da 100644 --- a/Handler/SubmissionView.hs +++ b/Handler/SubmissionView.hs @@ -1,14 +1,9 @@ module Handler.SubmissionView where import Import -import Handler.Shared -import PersistSHA1 -import Handler.TagUtils -import Data.Text as T(pack) - -import qualified Yesod.Table as Table -import Yesod.Table (Table) +import qualified Database.Esqueleto as E +import Database.Esqueleto ((^.)) data FullSubmissionInfo = FullSubmissionInfo { fsiSubmissionId :: SubmissionId, @@ -19,7 +14,8 @@ data FullSubmissionInfo = FullSubmissionInfo { fsiChallengeRepo :: Repo, fsiScheme :: RepoScheme, fsiTags :: [(Entity Tag, Entity SubmissionTag)], - fsiExternalLinks :: [Entity ExternalLink] } + fsiExternalLinks :: [Entity ExternalLink], + fsiSuperSubmissions :: [FullSubmissionInfo] } getFullInfo :: Entity Submission -> Handler FullSubmissionInfo getFullInfo (Entity submissionId submission) = do @@ -35,6 +31,13 @@ getFullInfo (Entity submissionId submission) = do app <- getYesod 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 { fsiSubmissionId = submissionId, fsiSubmission = submission, @@ -44,8 +47,10 @@ getFullInfo (Entity submissionId submission) = do fsiChallengeRepo = challengeRepo, fsiScheme = scheme, 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 sts <- selectList [SubmissionTagSubmission ==. submissionId] [] let tagIds = Import.map (submissionTagTag . entityVal) sts diff --git a/templates/query-result.hamlet b/templates/query-result.hamlet index a9d061c..609171e 100644 --- a/templates/query-result.hamlet +++ b/templates/query-result.hamlet @@ -1,29 +1,39 @@ -
-
#{repoUrl $ fsiRepo submission}
/ branch #{repoBranch $ fsiRepo submission}
- $if submissionIsPublic $ fsiSubmission submission
- #{publicSubmissionRepo}
/ branch #{publicSubmissionBranch}
- git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}
- $if not (null (fsiExternalLinks submission))
-
+
+
+
+
#{repoUrl $ fsiRepo submission}
/ branch #{repoBranch $ fsiRepo submission}
+ $if submissionIsPublic $ fsiSubmission submission
+ #{publicSubmissionRepo}
/ branch #{publicSubmissionBranch}
+ git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}
+ $if not (null (fsiExternalLinks submission))
+
+ ^{resultTable (Entity (fsiSubmissionId submission) (fsiSubmission submission))}
+
+ $if not (null (fsiSuperSubmissions submission))
+ downstream submissions
+ $forall superSubmission <- (fsiSuperSubmissions submission)
+ ^{queryResult superSubmission}
diff --git a/templates/query-results.hamlet b/templates/query-results.hamlet
index e3447be..7f73f8e 100644
--- a/templates/query-results.hamlet
+++ b/templates/query-results.hamlet
@@ -6,3 +6,4 @@ $if null submissions
$else
$forall submission <- submissions
^{queryResult submission}
+
diff --git a/templates/result-table.julius b/templates/result-table.julius
index fe9b252..3e18f14 100644
--- a/templates/result-table.julius
+++ b/templates/result-table.julius
@@ -2,6 +2,7 @@
$(document).ready(function() {
$(#{jsSelector}).DataTable({
'pageLength': 50,
+ 'lengthChange': false,
'order': [[0, 'asc'], [#{delta} + ($.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})).length-1, 'desc']],
'columnDefs': $.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})
});