From 70ad55f565f8d4698a7b7735d8b9c912f9ddddf9 Mon Sep 17 00:00:00 2001 From: SJost Date: Mon, 27 Nov 2017 13:21:11 +0100 Subject: [PATCH] Course participant count working now, albeit inefficient through runDB per Collonade-Row --- src/Handler/Course.hs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Handler/Course.hs b/src/Handler/Course.hs index 450800dcf..a0077ce64 100644 --- a/src/Handler/Course.hs +++ b/src/Handler/Course.hs @@ -33,22 +33,24 @@ getCourseListTermR tidini = do when (isNothing term) $ do setMessage [shamlet| Semester #{termToText tidini} nicht gefunden. |] redirect TermShowR + -- TODO: several runDBs per TableRow are probably too inefficient! let colonnadeTerms = mconcat - [ headed "Kürzel" $ (\c -> - let shd = courseShorthand c + [ headed "Kürzel" $ (\ckv -> + let c = entityVal ckv + shd = courseShorthand c tid = unTermKey $ courseTermId c in [whamlet| #{shd} |] ) -- , headed "Institut" $ [shamlet| #{course} |] - , headed "Beginn Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterFrom - , headed "Ende Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterTo --- TODO --- , headed "Teilnehmer" $ (\c -> do --- let cid = courseId c --- partiNum <- runDB $ count [CourseParticipantCourseId ==. cid] --- return $ fromString $ show partiNum --- ) - , headed " " $ (\c -> - let shd = courseShorthand c + , headed "Beginn Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterFrom.entityVal + , headed "Ende Anmeldung" $ fromString.(maybe "" formatTimeGerWD).courseRegisterTo.entityVal + , headed "Teilnehmer" $ (\ckv -> do + let cid = entityKey ckv + partiNum <- handlerToWidget $ runDB $ count [CourseParticipantCourseId ==. cid] + [whamlet| #{show partiNum} |] + ) + , headed " " $ (\ckv -> + let c = entityVal ckv + shd = courseShorthand c tid = unTermKey $ courseTermId c in do adminLink <- handlerToWidget $ isAuthorized (CourseEditExistR tid shd ) False @@ -70,8 +72,8 @@ getCourseListTermR tidini = do defaultLinkLayout pageLinks $ do -- defaultLayout $ do setTitle "Semesterkurse" - linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR - encodeHeadedWidgetTable tableDefault colonnadeTerms (map entityVal courses) + -- linkButton "Neuen Kurs anlegen" BCPrimary CourseEditR + encodeHeadedWidgetTable tableDefault colonnadeTerms courses -- (map entityVal courses) getCourseShowR :: TermIdentifier -> Text -> Handler Html getCourseShowR tid csh = do @@ -81,7 +83,7 @@ getCourseShowR tid csh = do dependent <- (,,) <$> get (courseSchoolId course) -- join <*> count [CourseParticipantCourseId ==. cid] -- join - <*> (case mbAid of -- Someone please refactor this late-night mess here! + <*> (case mbAid of -- TODO: Someone please refactor this late-night mess here! Nothing -> return False (Just aid) -> do regL <- getBy (UniqueCourseParticipant cid aid)