tags can be accepted now

This commit is contained in:
Filip Gralinski 2017-05-28 10:06:50 +02:00
parent f8779ce044
commit 372d814983
4 changed files with 29 additions and 2 deletions

View File

@ -139,6 +139,8 @@ instance Yesod App where
isAuthorized MyScoreR _ = return Authorized
isAuthorized (ResetPasswordR _) _ = return Authorized
isAuthorized (ToggleSubmissionTagR _) _ = return Authorized
-- Default to Authorized for now.
isAuthorized _ _ = isTrustedAuthorized

View File

@ -31,11 +31,19 @@ $forall (Entity _ v) <- tagEnts
fragmentWithSubmissionTags t tagEnts = [whamlet|
#{t}
$forall ((Entity _ v), (Entity _ s)) <- tagEnts
\ <span class="label #{tagClass $ submissionTagAccepted s}">#{tagName v}</span>
$forall ((Entity _ v), (Entity sid s)) <- tagEnts
\ <span class="label #{tagClass $ submissionTagAccepted s}" onclick="t=$(this); $.get('/toggle-submission-tag/#{toPathPiece sid}', function(data){ if (!(data == 'BLOCKED')) {t.removeClass('#{allTagClasses}'); t.addClass(data);} }); ">#{tagName v}</span>
|]
allTagClasses :: Text
allTagClasses = (tagClass $ Just True) <> " " <> (tagClass $ Just False) <> " " <> (tagClass $ Nothing);
tagClass :: Maybe Bool -> Text
tagClass (Just True) = "label-success"
tagClass (Just False) = "label-default"
tagClass Nothing = "label-primary"
toggleTag :: Maybe Bool -> Maybe Bool
toggleTag (Just True) = Just False
toggleTag _ = Just True

View File

@ -6,6 +6,8 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, bfs)
import qualified Yesod.Table as Table
import Handler.TagUtils
getTagsR :: Handler Html
getTagsR = do
(formWidget, formEnctype) <- generateFormPost tagForm
@ -41,3 +43,17 @@ tagForm :: Form (Text, Maybe Text)
tagForm = renderBootstrap3 BootstrapBasicForm $ (,)
<$> areq textField (bfs MsgTagName) Nothing
<*> aopt textField (bfs MsgTagDescription) Nothing
getToggleSubmissionTagR :: SubmissionTagId -> Handler RepPlain
getToggleSubmissionTagR submissionTagId = do
mUser <- maybeAuth
if (checkIfAdmin mUser)
then
do
submissionTag <- runDB $ get404 submissionTagId
let newState = toggleTag $ submissionTagAccepted submissionTag
runDB $ update submissionTagId [SubmissionTagAccepted =. newState]
return $ RepPlain $ toContent $ tagClass newState
else
do
return $ RepPlain $ toContent ("BLOCKED" :: Text)

View File

@ -36,6 +36,7 @@
/start-working-on/#AchievementId StartWorkingOnR GET
/give-up-working-on/#AchievementId GiveUpWorkingOnR GET
/submission-for-achievement/#SubmissionId/#WorkingOnId SubmissionForAchievementR GET
/toggle-submission-tag/#SubmissionTagId ToggleSubmissionTagR GET
/score/#UserId ScoreR GET
/my-score MyScoreR GET