From ca42fcbf84d9bc038311ffaef578dbe793e4952d Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Wed, 28 Aug 2019 08:49:43 +0200 Subject: [PATCH] Continue work on challenge updating --- Foundation.hs | 1 + Handler/CreateChallenge.hs | 44 +++++++++++++++++++++++++++++++ config/routes | 1 + messages/en.msg | 4 +++ templates/show-challenge.hamlet | 5 +++- templates/update-challenge.hamlet | 7 +++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 templates/update-challenge.hamlet diff --git a/Foundation.hs b/Foundation.hs index 779175c..c850fcf 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -166,6 +166,7 @@ instance Yesod App where isAuthorized ListArchivedChallengesR _ = isAdmin isAuthorized (ArchiveR _) _ = isAdmin isAuthorized (UnarchiveR _) _ = isAdmin + isAuthorized (ChallengeUpdateR _) _ = isAdmin isAuthorized MyScoreR _ = return Authorized diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index 337deac..5a4aba8 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -89,6 +89,40 @@ doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl pr Nothing -> return () Nothing -> return () +data ChallengeUpdateType = MajorChange | MinorChange | ChallengePatch + deriving (Eq, Enum, Bounded) + +instance Show ChallengeUpdateType where + show MajorChange = "major change" + show MinorChange = "minor change" + show ChallengePatch = "patch" + +getChallengeUpdateR :: ChallengeId -> Handler Html +getChallengeUpdateR challengeId = do + (formWidget, formEnctype) <- generateFormPost updateChallengeForm + defaultLayout $ do + setTitle "Welcome To Yesod!" + $(widgetFile "update-challenge") + +postChallengeUpdateR :: ChallengeId -> Handler TypedContent +postChallengeUpdateR _ = do + ((result, _), _) <- runFormPost updateChallengeForm + let challengeData = case result of + FormSuccess res -> Just res + _ -> Nothing + Just (updateType, publicUrl, publicBranch, publicGitAnnexRemote, + privateUrl, privateBranch, privateGitAnnexRemote) = challengeData + + userId <- requireAuthId + user <- runDB $ get404 userId + if userIsAdmin user + then + do + runViewProgress $ (flip err) "TO BE IMPLEMENTED" + else + runViewProgress $ (flip err) "MUST BE AN ADMIN TO CREATE A CHALLENGE" + + defaultMajorVersion :: Int defaultMajorVersion = 1 @@ -230,3 +264,13 @@ createChallengeForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,) <*> areq textField (bfs MsgPrivateUrl) Nothing <*> areq textField (bfs MsgBranch) (Just "dont-peek") <*> aopt textField (bfs MsgGitAnnexRemote) Nothing + +updateChallengeForm :: Form (ChallengeUpdateType, Text, Text, Maybe Text, Text, Text, Maybe Text) +updateChallengeForm = renderBootstrap3 BootstrapBasicForm $ (,,,,,,) + <$> areq (radioField optionsEnum) (bfs MsgChangeType) Nothing + <*> areq textField (bfs MsgPublicUrl) Nothing + <*> areq textField (bfs MsgBranch) (Just "master") + <*> aopt textField (bfs MsgGitAnnexRemote) Nothing + <*> areq textField (bfs MsgPrivateUrl) Nothing + <*> areq textField (bfs MsgBranch) (Just "dont-peek") + <*> aopt textField (bfs MsgGitAnnexRemote) Nothing diff --git a/config/routes b/config/routes index b222948..6f9bf51 100644 --- a/config/routes +++ b/config/routes @@ -23,6 +23,7 @@ /challenge-discussion/#Text ChallengeDiscussionR GET POST /challenge-param-graph-data/#Text/#TestId/#Text ChallengeParamGraphDataR GET /challenge-discussion-rss/#Text ChallengeDiscussionFeedR GET +/challenge-update/#ChallengeId ChallengeUpdateR GET POST /trigger-remotely TriggerRemotelyR POST /trigger-locally TriggerLocallyR POST diff --git a/messages/en.msg b/messages/en.msg index 391f943..2907e29 100644 --- a/messages/en.msg +++ b/messages/en.msg @@ -78,3 +78,7 @@ Dashboard: dashboard TargetName: target name ShowArchivedChallenges: show archived challenges CoursesITeach: courses I teach +MajorChange: major change +MinorChange: minor change +Patch: patch +ChangeType: change type diff --git a/templates/show-challenge.hamlet b/templates/show-challenge.hamlet index 5174973..32f0fed 100644 --- a/templates/show-challenge.hamlet +++ b/templates/show-challenge.hamlet @@ -10,7 +10,10 @@ $if (checkIfAdmin mUserEnt) $if (challengeArchived challenge /= Just True)