tags can be accepted now
This commit is contained in:
parent
f8779ce044
commit
372d814983
@ -139,6 +139,8 @@ instance Yesod App where
|
|||||||
isAuthorized MyScoreR _ = return Authorized
|
isAuthorized MyScoreR _ = return Authorized
|
||||||
|
|
||||||
isAuthorized (ResetPasswordR _) _ = return Authorized
|
isAuthorized (ResetPasswordR _) _ = return Authorized
|
||||||
|
isAuthorized (ToggleSubmissionTagR _) _ = return Authorized
|
||||||
|
|
||||||
|
|
||||||
-- Default to Authorized for now.
|
-- Default to Authorized for now.
|
||||||
isAuthorized _ _ = isTrustedAuthorized
|
isAuthorized _ _ = isTrustedAuthorized
|
||||||
|
@ -31,11 +31,19 @@ $forall (Entity _ v) <- tagEnts
|
|||||||
fragmentWithSubmissionTags t tagEnts = [whamlet|
|
fragmentWithSubmissionTags t tagEnts = [whamlet|
|
||||||
#{t}
|
#{t}
|
||||||
|
|
||||||
$forall ((Entity _ v), (Entity _ s)) <- tagEnts
|
$forall ((Entity _ v), (Entity sid s)) <- tagEnts
|
||||||
\ <span class="label #{tagClass $ submissionTagAccepted s}">#{tagName v}</span>
|
\ <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 :: Maybe Bool -> Text
|
||||||
tagClass (Just True) = "label-success"
|
tagClass (Just True) = "label-success"
|
||||||
tagClass (Just False) = "label-default"
|
tagClass (Just False) = "label-default"
|
||||||
tagClass Nothing = "label-primary"
|
tagClass Nothing = "label-primary"
|
||||||
|
|
||||||
|
toggleTag :: Maybe Bool -> Maybe Bool
|
||||||
|
toggleTag (Just True) = Just False
|
||||||
|
toggleTag _ = Just True
|
||||||
|
@ -6,6 +6,8 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, bfs)
|
|||||||
|
|
||||||
import qualified Yesod.Table as Table
|
import qualified Yesod.Table as Table
|
||||||
|
|
||||||
|
import Handler.TagUtils
|
||||||
|
|
||||||
getTagsR :: Handler Html
|
getTagsR :: Handler Html
|
||||||
getTagsR = do
|
getTagsR = do
|
||||||
(formWidget, formEnctype) <- generateFormPost tagForm
|
(formWidget, formEnctype) <- generateFormPost tagForm
|
||||||
@ -41,3 +43,17 @@ tagForm :: Form (Text, Maybe Text)
|
|||||||
tagForm = renderBootstrap3 BootstrapBasicForm $ (,)
|
tagForm = renderBootstrap3 BootstrapBasicForm $ (,)
|
||||||
<$> areq textField (bfs MsgTagName) Nothing
|
<$> areq textField (bfs MsgTagName) Nothing
|
||||||
<*> aopt textField (bfs MsgTagDescription) 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)
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
/start-working-on/#AchievementId StartWorkingOnR GET
|
/start-working-on/#AchievementId StartWorkingOnR GET
|
||||||
/give-up-working-on/#AchievementId GiveUpWorkingOnR GET
|
/give-up-working-on/#AchievementId GiveUpWorkingOnR GET
|
||||||
/submission-for-achievement/#SubmissionId/#WorkingOnId SubmissionForAchievementR GET
|
/submission-for-achievement/#SubmissionId/#WorkingOnId SubmissionForAchievementR GET
|
||||||
|
/toggle-submission-tag/#SubmissionTagId ToggleSubmissionTagR GET
|
||||||
|
|
||||||
/score/#UserId ScoreR GET
|
/score/#UserId ScoreR GET
|
||||||
/my-score MyScoreR GET
|
/my-score MyScoreR GET
|
||||||
|
Loading…
Reference in New Issue
Block a user