From d69e953c35aec015e359e66f5a65f6e679bb0573 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Wed, 11 Nov 2015 22:10:41 +0100 Subject: [PATCH] add how-to --- Handler/ShowChallenge.hs | 30 ++++++++++++++++----- config/routes | 1 + templates/challenge-how-to.hamlet | 43 +++++++++++++++++++++++++++++++ templates/challenge.hamlet | 3 ++- 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 templates/challenge-how-to.hamlet diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index b78f613..d467dba 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -44,17 +44,35 @@ getChallengeReadmeR name = do showChallengeWidget challenge repo = $(widgetFile "show-challenge") +getChallengeHowToR :: Text -> Handler Html +getChallengeHowToR name = do + (Entity _ challenge) <- runDB $ getBy404 $ UniqueName name + maybeUser <- maybeAuth + challengeLayout False challenge (challengeHowTo challenge (idToBeShown challenge maybeUser)) + +idToBeShown challenge maybeUser = + case maybeUser of + Just user -> case userLocalId $ entityVal user of + Just localId -> localId + Nothing -> defaultIdToBe + Nothing -> defaultIdToBe + where defaultIdToBe = "YOURID" :: Text + +defaultRepo challenge maybeUser = "ssh://gitolite@gonito.net/" ++ (idToBeShown challenge maybeUser) ++ "/" ++ (challengeName challenge) + +challengeHowTo challenge idToBeShown = $(widgetFile "challenge-how-to") getChallengeSubmissionR :: Text -> Handler Html getChallengeSubmissionR name = do (Entity _ challenge) <- runDB $ getBy404 $ UniqueName name - (formWidget, formEnctype) <- generateFormPost submissionForm + maybeUser <- maybeAuth + (formWidget, formEnctype) <- generateFormPost $ submissionForm (Just $ defaultRepo challenge maybeUser) challengeLayout True challenge $ challengeSubmissionWidget formWidget formEnctype challenge postChallengeSubmissionR :: Text -> Handler TypedContent postChallengeSubmissionR name = do (Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName name - ((result, formWidget), formEnctype) <- runFormPost submissionForm + ((result, formWidget), formEnctype) <- runFormPost $ submissionForm Nothing let submissionData = case result of FormSuccess res -> Just res _ -> Nothing @@ -203,11 +221,11 @@ checkRepoAvailibility challengeId repoId chan = do challengeSubmissionWidget formWidget formEnctype challenge = $(widgetFile "challenge-submission") -submissionForm :: Form (Text, Text, Text) -submissionForm = renderBootstrap3 BootstrapBasicForm $ (,,) +submissionForm :: Maybe Text -> Form (Text, Text, Text) +submissionForm defaultUrl = renderBootstrap3 BootstrapBasicForm $ (,,) <$> areq textField (fieldSettingsLabel MsgSubmissionDescription) Nothing - <*> areq textField (fieldSettingsLabel MsgSubmissionUrl) Nothing - <*> areq textField (fieldSettingsLabel MsgSubmissionBranch) Nothing + <*> areq textField (fieldSettingsLabel MsgSubmissionUrl) defaultUrl + <*> areq textField (fieldSettingsLabel MsgSubmissionBranch) (Just "master") getChallengeMySubmissionsR :: Text -> Handler Html getChallengeMySubmissionsR name = do diff --git a/config/routes b/config/routes index 2865b13..a44da53 100644 --- a/config/routes +++ b/config/routes @@ -16,5 +16,6 @@ /challenge-submission/#Text ChallengeSubmissionR GET POST /challenge-my-submissions/#Text ChallengeMySubmissionsR GET /challenge-all-submissions/#Text ChallengeAllSubmissionsR GET +/challenge-how-to/#Text ChallengeHowToR GET /account YourAccountR GET POST diff --git a/templates/challenge-how-to.hamlet b/templates/challenge-how-to.hamlet new file mode 100644 index 0000000..f8ae2ea --- /dev/null +++ b/templates/challenge-how-to.hamlet @@ -0,0 +1,43 @@ +

Challenge How To + +

Install GEval + +

In order to evaluate your work locally, you need the GEval tool. First install Haskell Stack and then install GEval itselt: + +

+  git clone git://gonito.net/geval
+  cd geval
+  stack setup
+  stack install
+
+

Get your repo + +

You need to upload your SSH public key (see your account) if you want to have a repo hosted on Gonito.net, then: + +

+  git clone ssh://gitolite@gonito.net/#{idToBeShown}/#{challengeName challenge}
+  cd #{challengeName challenge}
+  git pull ssh://gitolite@gonito.net/#{challengeName challenge}
+  git push origin master
+
+

Work on your solution + +

You need to generate your solution for the test set as test-A/out.tsv. You may also generate the solution for the dev set (dev-0/out.tsv). + +

You can evaluate results for the dev set locally: + +

+  cd #{challengeName challenge}
+  geval --test-name dev-0
+
+

Submit your solution + +

Push out.tsv files to your repo. It is also recommended to push your source codes along with out.tsv files. + +

+  cd #{challengeName challenge}
+  git add dev-0/out.tsv test-A/out.tsv # also your source codes could be added
+  git commit -m 'my brilliant solution'
+  git push origin master
+
+

Finally, you need to tell Gonito.net to evaluate your submission. Go to the submit form. diff --git a/templates/challenge.hamlet b/templates/challenge.hamlet index 7dcf8bc..78d2f69 100644 --- a/templates/challenge.hamlet +++ b/templates/challenge.hamlet @@ -2,8 +2,9 @@