From 8b46a690a8e0dfd82d8775adf256ac42b850264d Mon Sep 17 00:00:00 2001 From: SJost Date: Wed, 20 Jun 2018 15:31:45 +0200 Subject: [PATCH] Show Participant association on profile page --- src/Foundation.hs | 4 +++- src/Handler/Profile.hs | 8 +++++++- src/Handler/Utils/DateTime.hs | 7 +++++-- src/Utils.hs | 2 ++ templates/profile.hamlet | 12 +++++++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index ce6de1fac..cd447ff78 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -69,6 +69,7 @@ import System.FilePath import Handler.Utils.Templates import Handler.Utils.StudyFeatures +import Handler.Utils.DateTime import Control.Lens import Utils.Lens @@ -76,7 +77,8 @@ import Utils.Lens instance DisplayAble TermId where display = termToText . unTermKey - +instance DisplayAble UTCTime where + display = pack . formatTimeGerDT2 -- default Time Format to be used: 00.00.00 00:00 -- infixl 9 :$: -- pattern a :$: b = a b diff --git a/src/Handler/Profile.hs b/src/Handler/Profile.hs index 42edd418c..0727e7015 100644 --- a/src/Handler/Profile.hs +++ b/src/Handler/Profile.hs @@ -20,7 +20,7 @@ getProfileR :: Handler Html getProfileR = do (uid, User{..}) <- requireAuthPair mr <- getMessageRender - (admin_rights,lecturer_rights,lecture_owner,lecture_corrector,studies) <- runDB $ (,,,,) <$> + (admin_rights,lecturer_rights,lecture_owner,lecture_corrector,participant,studies) <- runDB $ (,,,,,) <$> (E.select $ E.from $ \(adright `E.InnerJoin` school) -> do E.where_ $ adright ^. UserAdminUser E.==. E.val uid E.on $ adright ^. UserAdminSchool E.==. school ^. SchoolId @@ -45,6 +45,12 @@ getProfileR = do return (course ^. CourseShorthand, course ^. CourseTerm) ) <*> + (E.select $ E.from $ \(participant `E.InnerJoin` course) -> do + E.where_ $ participant ^. CourseParticipantUser E.==. E.val uid + E.on $ participant ^. CourseParticipantCourse E.==. course ^. CourseId + return (course ^. CourseShorthand, course ^. CourseTerm, participant ^. CourseParticipantRegistration) + ) + <*> (E.select $ E.from $ \(studydegree `E.InnerJoin` studyfeat `E.InnerJoin` studyterms) -> do E.where_ $ studyfeat ^. StudyFeaturesUser E.==. E.val uid E.on $ studyfeat ^. StudyFeaturesField E.==. studyterms ^. StudyTermsId diff --git a/src/Handler/Utils/DateTime.hs b/src/Handler/Utils/DateTime.hs index 456a00ce5..af8bfa639 100644 --- a/src/Handler/Utils/DateTime.hs +++ b/src/Handler/Utils/DateTime.hs @@ -43,8 +43,11 @@ formatTimeGerDTlong = formatTimeGer "%A, %e. %B %Y, %k:%M:%S" formatTimeGerWDT :: FormatTime t => t -> String formatTimeGerWDT = formatTimeGer $ dateTimeFmt germanTimeLocale -formatTimeGerDT :: FormatTime t => t -> String -formatTimeGerDT = formatTimeGer "%e.%m.%y %k:%M" +formatTimeGerDT :: FormatTime t => t -> String -- 0.00.00 0:00 +formatTimeGerDT = formatTimeGer "%e.%m.%y %k:%M" -- leading spaces at start, otherwise 0 padding + +formatTimeGerDT2 :: FormatTime t => t -> String -- 00.00.00 00:00 +formatTimeGerDT2 = formatTimeGer "%d.%m.%y %H:%M" -- always padding with 0 formatTimeGerWD :: FormatTime t => t -> String formatTimeGerWD = formatTimeGer "%a %e.%m.%y" diff --git a/src/Utils.hs b/src/Utils.hs index b31056a01..39d79c37b 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -91,6 +91,8 @@ instance DisplayAble Text where instance DisplayAble String where display = pack + + instance DisplayAble a => DisplayAble (Maybe a) where display Nothing = "" display (Just x) = display x diff --git a/templates/profile.hamlet b/templates/profile.hamlet index 8b28247f1..e2f31cf94 100644 --- a/templates/profile.hamlet +++ b/templates/profile.hamlet @@ -34,7 +34,17 @@ $forall (E.Value csh, E.Value tid) <- lecture_corrector
  • #{display tid} - #{csh} +

    + Kursteilnehmer: +