43 lines
1.8 KiB
Haskell
43 lines
1.8 KiB
Haskell
module Handler.Submission.Assign
|
|
( getSubAssignR, postSubAssignR
|
|
) where
|
|
|
|
import Import
|
|
|
|
import Handler.Utils
|
|
|
|
|
|
getSubAssignR, postSubAssignR :: TermId -> SchoolId -> CourseShorthand -> SheetName -> CryptoFileNameSubmission -> Handler Html
|
|
getSubAssignR = postSubAssignR
|
|
postSubAssignR tid ssh csh shn cID = do
|
|
let actionUrl = CSubmissionR tid ssh csh shn cID SubAssignR
|
|
sId <- decrypt cID
|
|
(currentCorrector, sheetCorrectors) <- runDB $ do
|
|
Submission{submissionRatingBy, submissionSheet} <- get404 sId
|
|
sheetCorrectors <- map (sheetCorrectorUser . entityVal) <$> selectList [SheetCorrectorSheet ==. submissionSheet] []
|
|
userCorrector <- traverse getJustEntity submissionRatingBy
|
|
return (userCorrector, maybe id (:) submissionRatingBy sheetCorrectors)
|
|
|
|
$logDebugS "SubAssignR" $ tshow currentCorrector
|
|
let correctorField = selectField $ optionsPersistCryptoId [UserId <-. sheetCorrectors] [Asc UserSurname, Asc UserDisplayName] userDisplayName
|
|
((corrResult, corrForm'), corrEncoding) <- runFormPost . renderAForm FormStandard $
|
|
aopt correctorField (fslI MsgCorrector) (Just currentCorrector)
|
|
formResult corrResult $ \(fmap entityKey -> mbUserId) -> do
|
|
when (mbUserId /= fmap entityKey currentCorrector) . runDB $ do
|
|
now <- liftIO getCurrentTime
|
|
update sId [ SubmissionRatingBy =. mbUserId
|
|
, SubmissionRatingAssigned =. (now <$ mbUserId)
|
|
]
|
|
addMessageI Success MsgCorrectorUpdated
|
|
sub <- getJust sId
|
|
audit $ TransactionSubmissionEdit sId $ sub ^. _submissionSheet
|
|
redirect actionUrl
|
|
let corrForm = wrapForm' BtnSave corrForm' def
|
|
{ formAction = Just $ SomeRoute actionUrl
|
|
, formEncoding = corrEncoding
|
|
, formSubmit = FormSubmit
|
|
}
|
|
defaultLayout $ do
|
|
setTitleI MsgCorrectorAssignTitle
|
|
$(widgetFile "submission-assign")
|