diff --git a/src/Handler/Corrections.hs b/src/Handler/Corrections.hs index 0e2f70e21..6a9c1b7aa 100644 --- a/src/Handler/Corrections.hs +++ b/src/Handler/Corrections.hs @@ -1042,19 +1042,21 @@ data SubAssignInfo = SubAssignInfo { saiName :: SheetName, saiSubmissionNr, saiC getCAssignR, postCAssignR :: TermId -> SchoolId -> CourseShorthand -> Handler Html getCAssignR = postCAssignR postCAssignR tid ssh csh = do - shids <- runDB $ do + (shids,cid) <- runDB $ do cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh - selectKeysList [SheetCourse ==. cid] [Asc SheetActiveTo] - assignHandler tid ssh csh shids + shids <- selectKeysList [SheetCourse ==. cid] [Asc SheetActiveTo] + return (shids,cid) + assignHandler tid ssh csh cid shids getSAssignR, postSAssignR :: TermId -> SchoolId -> CourseShorthand -> SheetName -> Handler Html getSAssignR = postSAssignR postSAssignR tid ssh csh shn = do - shid <- runDB $ fetchSheetId tid ssh csh shn - assignHandler tid ssh csh [shid] + (shid,cid) <- runDB $ fetchSheetIdCourseId tid ssh csh shn + assignHandler tid ssh csh cid [shid] -assignHandler :: TermId -> SchoolId -> CourseShorthand -> [SheetId] -> Handler Html -assignHandler tid ssh csh rawSids = do +-- DEPRECATED assignHandler' +assignHandler' :: TermId -> SchoolId -> CourseShorthand -> CourseId -> [SheetId] -> Handler Html +assignHandler' tid ssh csh _cid rawSids = do -- gather data openSubs <- runDB $ (\f -> foldM f Map.empty rawSids) $ \acc sid -> maybeT (return acc) $ do @@ -1094,11 +1096,28 @@ assignHandler tid ssh csh rawSids = do else btnForm -assignHandler' :: TermId -> SchoolId -> CourseShorthand -> [SheetId] -> Handler Html -assignHandler' tid ssh csh _rawSids = do +{- TODO: make buttons for each sheet, so that users see which sheet is assigned +data ButtonCorrectionsAssign = BtnCorrectionsAssignAll | BtnCorrectionsAssignSheet SheetName + deriving (Enum, Eq, Ord, Bounded, Read, Show, Generic, Typeable) +instance Button UniWorX ButtonCorrectionsAssign +-- Are those needed any more? +instance Universe ButtonCorrectionsAssign +instance Finite ButtonCorrectionsAssign +nullaryPathPiece ''ButtonCorrectionsAssign camelToPathPiece +embedRenderMessage ''UniWorX ''ButtonCorrectionsAssign id +instance Button UniWorX ButtonCorrectionsAssign where + btnClasses BtnCorrectionsAssign = [BCIsButton, BCPrimary] +-- use runButtonForm' instead later on +-} + +assignHandler :: TermId -> SchoolId -> CourseShorthand -> CourseId -> [SheetId] -> Handler Html +assignHandler tid ssh csh cid assignSids = do + -- evaluate form first, since it affects DB action + (btnWdgt, btnResult) <- runButtonForm FIDAssignSubmissions + -- gather data - (nrParticipants, groupsPossible, infoMap, correctorMap) <- runDB $ do - cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh + (nrParticipants, groupsPossible, infoMap, correctorMap, assignment) <- runDB $ do + -- cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh nrParticipants <- count [CourseParticipantCourse ==. cid] sheetList <- selectList [SheetCourse ==. cid] [Asc SheetName] @@ -1144,7 +1163,19 @@ assignHandler' tid ssh csh _rawSids = do , ciMax = corTime } in Map.insertWith (Map.unionWith (<>)) shnm cinf m - return (nrParticipants, groupsPossible, infoMap, correctorMap) + -- plan or assign unassigned submissions for given sheets + -- assignment :: Map SheetName ((Set SubmissionId, Set SubmissionId), Map (Maybe UserId) Int) + assignment <- fmap Map.fromList $ forM assignSids $ \sid -> do + plan <- planSubmissions sid Nothing + let shn = sheetName $ sheets ! sid + status <- case btnResult of + Nothing -> return (Set.empty, Set.empty) + (Just BtnSubmissionsAssign) -> writeSubmissionPlan plan + return (shn, (status, countMapElems plan)) + + return (nrParticipants, groupsPossible, infoMap, correctorMap, assignment) + + let -- create aggregate maps sheetMap :: Map SheetName CorrectionInfo @@ -1167,60 +1198,7 @@ assignHandler' tid ssh csh _rawSids = do headingLong = prependCourseTitle tid ssh csh MsgMenuCorrectionsAssign siteLayoutMsg headingShort $ do setTitleI headingLong - -- TODO: Move whamlet into separate Widget-File, once completed - [whamlet| -
| _{MsgSheet} - $if groupsPossible - | _{MsgNrSubmittorsTotal} - | _{MsgNrSubmissionsTotal} - | _{MsgNrSubmissionsNotAssigned} - | _{MsgNrSubmissionsNotCorrected} - | _{MsgCorrectionTime} - $forall (sheetName, CorrectionInfo{ciSubmittors, ciSubmissions, ciAssigned, ciCorrected, ciMin, ciTot, ciMax}) <- Map.toList sheetMap - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ^{simpleLink (toWidget sheetName) (CSheetR tid ssh csh sheetName SSubsR)} - $if groupsPossible - | #{ciSubmittors} - | #{ciSubmissions} - | #{ciSubmissions - ciAssigned} - | #{ciSubmissions - ciCorrected} - | #{showDiffDays ciMin} - | #{showAvgsDays ciTot ciCorrected} - | #{showDiffDays ciMax}
-
- _{MsgCorrectionCorrectors} -
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||