feat(eo-exams): select column for exam list in case of actions
This commit is contained in:
parent
9e81f03742
commit
42f58da44f
@ -128,8 +128,7 @@ resultIsSynced :: Getter ExamsTableData Bool
|
||||
resultIsSynced = to $ (>=) <$> view resultSynchronised <*> view resultResults
|
||||
|
||||
|
||||
-- | List of all exams where the current user may (in her function as
|
||||
-- exam-office) access users grades
|
||||
-- | List of all exams where the current user may (in their function as exam-office) access users grades
|
||||
getEOExamsR, postEOExamsR :: Handler Html
|
||||
getEOExamsR = postEOExamsR
|
||||
postEOExamsR = do
|
||||
@ -177,6 +176,14 @@ postEOExamsR = do
|
||||
externalExamLink ExternalExam{..}
|
||||
= SomeRoute $ EExamR externalExamTerm externalExamSchool externalExamCourseName externalExamExamName EEGradesR
|
||||
|
||||
examActions :: Map ExamAction (AForm Handler ExamActionData)
|
||||
examActions = Map.fromList $
|
||||
bool mempty
|
||||
[ ( ExamSetLabel, ExamSetLabelData
|
||||
<$> apopt (selectField' Nothing . fmap (fmap entityKey) $ optionsPersist [ExamOfficeLabelUser ==. uid] [Asc ExamOfficeLabelName] examOfficeLabelName) (fslI MsgExamLabel) Nothing
|
||||
)
|
||||
, ( ExamRemoveLabel, pure ExamRemoveLabelData )
|
||||
] getLabels
|
||||
|
||||
examsDBTable = DBTable{..}
|
||||
where
|
||||
@ -316,7 +323,8 @@ postEOExamsR = do
|
||||
|
||||
dbtColonnade :: Colonnade Sortable _ _
|
||||
dbtColonnade = mconcat
|
||||
[ bool mempty colLabel getLabels
|
||||
[ bool mempty (dbSelect (applying _2) id $ \DBRow{ dbrOutput=(ex,_,_) } -> return $ bimap (\(Entity eeId _,_) -> eeId) (\(Entity eId _,_,_,_) -> eId) ex) (not $ Map.null examActions)
|
||||
, bool mempty colLabel getLabels
|
||||
, bool mempty colSynced getSynced
|
||||
, maybeAnchorColonnade ( runMaybeT $ mpreview ($(multifocusG 2) (pre $ resultCourse . _entityVal) (pre $ resultExam . _entityVal) . to (uncurry $ liftA2 examLink) . _Just)
|
||||
<|> mpreviews (resultExternalExam . _entityVal) externalExamLink
|
||||
@ -372,17 +380,9 @@ postEOExamsR = do
|
||||
, dbParamsFormAttrs = []
|
||||
, dbParamsFormSubmit = FormSubmit
|
||||
, dbParamsFormAdditional
|
||||
= let actions :: Map ExamAction (AForm Handler ExamActionData)
|
||||
actions = Map.fromList $
|
||||
bool mempty
|
||||
[ ( ExamSetLabel, ExamSetLabelData
|
||||
<$> apopt (selectField' Nothing . fmap (fmap entityKey) $ optionsPersist [ExamOfficeLabelUser ==. uid] [Asc ExamOfficeLabelName] examOfficeLabelName) (fslI MsgExamLabel) Nothing
|
||||
)
|
||||
, ( ExamRemoveLabel, pure ExamRemoveLabelData )
|
||||
] getLabels
|
||||
in renderAForm FormStandard
|
||||
$ (, mempty) . First . Just
|
||||
<$> multiActionA actions (fslI MsgTableAction) Nothing
|
||||
= renderAForm FormStandard
|
||||
$ (, mempty) . First . Just
|
||||
<$> multiActionA examActions (fslI MsgTableAction) Nothing
|
||||
, dbParamsFormEvaluate = liftHandler . runFormPost
|
||||
, dbParamsFormResult = id
|
||||
, dbParamsFormIdent = def
|
||||
@ -401,10 +401,13 @@ postEOExamsR = do
|
||||
& forceFilter "may-access" (Any True)
|
||||
& forceFilter "has-results" (Any True)
|
||||
|
||||
postprocess :: FormResult (First ExamActionData, DBFormResult (Either ExternalExamId ExamId) Bool (DBRow (Either (Entity ExternalExam) (Entity Exam)))) -> FormResult (ExamActionData, Set (Either ExternalExamId ExamId))
|
||||
postprocess (FormFailure errs) = FormFailure errs
|
||||
postprocess FormMissing = FormMissing
|
||||
postprocess (FormSuccess (First mExamActionData, examRes)) = maybe FormMissing (\act -> FormSuccess . (act,) . Map.keysSet . Map.filter id $ getDBFormResult (const False) examRes) mExamActionData
|
||||
postprocess :: FormResult (First ExamActionData , DBFormResult (Either ExternalExamId ExamId) Bool (DBRow (Either (Entity ExternalExam, Maybe (Entity ExamOfficeLabel)) (Entity Exam, Entity Course, Entity School, Maybe (Entity ExamOfficeLabel)), Maybe Natural, Maybe Natural)))
|
||||
-> FormResult ( ExamActionData , Set (Either ExternalExamId ExamId))
|
||||
postprocess (FormFailure errs) = FormFailure errs
|
||||
postprocess FormMissing = FormMissing
|
||||
postprocess (FormSuccess (First mExamActionData, examRes))
|
||||
| Just act <- mExamActionData = FormSuccess . (act,) . Map.keysSet . Map.filter id $ getDBFormResult (const False) examRes
|
||||
| otherwise = FormMissing
|
||||
|
||||
over _1 postprocess <$> dbTable examsDBTableValidator examsDBTable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user