From c759364ab1d43a4e796cd92a494cafb939dd2568 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 19 Aug 2019 15:55:33 +0200 Subject: [PATCH] feat(allocations): link allocations from home --- messages/uniworx/de.msg | 9 +++- src/Handler/Home.hs | 66 +++++++++++++++++++++++++- templates/home/openAllocations.hamlet | 4 ++ templates/i18n/changelog/de.hamlet | 10 ++++ templates/i18n/info-lecturer/de.hamlet | 27 ++++------- 5 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 templates/home/openAllocations.hamlet diff --git a/messages/uniworx/de.msg b/messages/uniworx/de.msg index d43d2c7eb..c4862d134 100644 --- a/messages/uniworx/de.msg +++ b/messages/uniworx/de.msg @@ -127,7 +127,7 @@ CourseShorthand: Kürzel CourseShorthandUnique: Muss innerhalb Institut und Semester eindeutig sein CourseSemester: Semester CourseSchool: Institut -CourseSchoolShort: Fach +CourseSchoolShort: Institut CourseSecretTip: Anmeldung zum Kurs erfordert Eingabe des Passworts, sofern gesetzt CourseSecretFormat: beliebige Zeichenkette CourseRegisterFromTip: Ohne Datum ist KEINE eigenständige Anmeldung von Studierenden möglich @@ -451,6 +451,7 @@ TokensLastReset: Tokens zuletzt invalidiert TokensResetSuccess: Authorisierungs-Tokens invalidiert HomeOpenCourses: Kurse mit offener Registrierung +HomeOpenAllocations: Offene Zentralanmeldungen HomeUpcomingSheets: Anstehende Übungsblätter HomeUpcomingExams: Bevorstehende Prüfungen @@ -1502,4 +1503,8 @@ ApplicationRatingPoints: Bewertung ApplicationRatingPointsTip: Bewerber mit 5.0 werden garantiert nicht dem Kurs zugeteilt ApplicationRatingComment: Kommentar ApplicationRatingCommentVisibleTip: Feedback an den Bewerbers -ApplicationRatingCommentInvisibleTip: Dient zunächst nur als Notiz für Kursverwalter \ No newline at end of file +ApplicationRatingCommentInvisibleTip: Dient zunächst nur als Notiz für Kursverwalter + +AllocationSchoolShort: Institut +Allocation: Zentralanmeldung +AllocationRegisterTo: Anmeldungen bis \ No newline at end of file diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index b4d16ff10..51e9975a5 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -20,9 +20,65 @@ getHomeR = do setTitleI MsgHomeHeading fromMaybe mempty upcomingExamsWidget maybe mempty homeUpcomingSheets muid + homeOpenAllocations homeOpenCourses +homeOpenAllocations :: Widget +homeOpenAllocations = do + cTime <- liftIO getCurrentTime + let tableData :: E.SqlExpr (Entity Allocation) + -> E.SqlQuery (E.SqlExpr (Entity Allocation)) + tableData allocation = do + E.where_ $ E.maybe E.false (\rf -> rf E.<=. E.val cTime) (allocation E.^. AllocationRegisterFrom) + E.&&. E.maybe E.true (\rt -> rt E.>=. E.val cTime) (allocation E.^. AllocationRegisterTo) + return allocation + + colonnade :: Colonnade Sortable (DBRow (Entity Allocation)) (DBCell (HandlerT UniWorX IO) ()) + colonnade = mconcat + [ -- dbRow + sortable (Just "term") (i18nCell MsgTerm) + $ \DBRow{ dbrOutput=Entity{entityVal = Allocation{..}} } -> + anchorCell (TermCourseListR allocationTerm) [whamlet|#{allocationTerm}|] + , sortable (Just "schoolshort") (i18nCell MsgAllocationSchoolShort) + $ \DBRow{ dbrOutput=(Entity _ Allocation{..}) } -> + anchorCell (TermSchoolCourseListR allocationTerm allocationSchool) [whamlet|_{unSchoolKey allocationSchool}|] + , sortable (Just "allocation") (i18nCell MsgAllocation) $ \DBRow{ dbrOutput=Entity{entityVal = Allocation{..}} } -> do + anchorCell (AllocationR allocationTerm allocationSchool allocationShorthand AShowR) allocationName + , sortable (Just "deadline") (i18nCell MsgAllocationRegisterTo) $ \DBRow{ dbrOutput=Entity{entityVal = Allocation{..}} } -> + cell $ traverse (formatTime SelFormatDateTime) allocationRegisterTo >>= maybe mempty toWidget + ] + validator = def & defaultSorting [SortAscBy "deadline", SortAscBy "allocation"] + allocationTable <- liftHandlerT . runDB $ dbTableWidget' validator DBTable + { dbtSQLQuery = tableData + , dbtRowKey = (E.^. AllocationId) + , dbtColonnade = colonnade + , dbtProj = return + , dbtSorting = Map.fromList + [ ( "term" + , SortColumn $ \allocation -> allocation E.^. AllocationTerm + ) + , ( "schoolshort" + , SortColumn $ \allocation -> allocation E.^. AllocationSchool + ) + , ( "allocation" + , SortColumn $ \allocation -> allocation E.^. AllocationShorthand + ) + , ( "deadline" + , SortColumn $ \allocation -> allocation E.^. AllocationRegisterTo + ) + ] + , dbtFilter = mempty + , dbtFilterUI = mempty + , dbtStyle = def + , dbtParams = def + , dbtIdent = "open-allocations" :: Text + , dbtCsvEncode = noCsvEncode + , dbtCsvDecode = Nothing + } + $(widgetFile "home/openAllocations") + + homeOpenCourses :: Widget homeOpenCourses = do cTime <- liftIO getCurrentTime @@ -34,6 +90,13 @@ homeOpenCourses = do E.&&. ( E.isNothing (course E.^. CourseRegisterTo) E.||. course E.^. CourseRegisterTo E.>=. E.val (Just cTime) ) + E.&&. E.not_ (E.exists . E.from $ \(allocation `E.InnerJoin` allocationCourse) -> do + E.on $ allocation E.^. AllocationId E.==. allocationCourse E.^. AllocationCourseAllocation + E.where_ $ allocationCourse E.^. AllocationCourseCourse E.==. course E.^. CourseId + E.where_ $ E.maybe E.true (\rf -> rf E.>. E.val cTime) (allocation E.^. AllocationRegisterFrom) + E.||. E.maybe E.false (\rt -> rt E.<. E.val cTime) (allocation E.^. AllocationRegisterTo) + E.where_ $ E.maybe E.true (\rf -> rf E.>. E.val cTime) (allocation E.^. AllocationRegisterByCourse) + ) return course colonnade :: Colonnade Sortable (DBRow (Entity Course)) (DBCell (HandlerT UniWorX IO) ()) @@ -53,7 +116,8 @@ homeOpenCourses = do , sortable (Just "deadline") (i18nCell MsgRegisterTo) $ \DBRow{ dbrOutput=Entity{entityVal = course} } -> cell $ traverse (formatTime SelFormatDateTime) (courseRegisterTo course) >>= maybe mempty toWidget ] - courseTable <- liftHandlerT . runDB $ dbTableWidget' def DBTable + validator = def & defaultSorting [SortAscBy "deadline", SortAscBy "course"] + courseTable <- liftHandlerT . runDB $ dbTableWidget' validator DBTable { dbtSQLQuery = tableData , dbtRowKey = (E.^. CourseId) , dbtColonnade = colonnade diff --git a/templates/home/openAllocations.hamlet b/templates/home/openAllocations.hamlet new file mode 100644 index 000000000..16c84d41a --- /dev/null +++ b/templates/home/openAllocations.hamlet @@ -0,0 +1,4 @@ +$newline never +
+

_{MsgHomeOpenAllocations} + ^{allocationTable} diff --git a/templates/i18n/changelog/de.hamlet b/templates/i18n/changelog/de.hamlet index d32d6a27c..d2c436d00 100644 --- a/templates/i18n/changelog/de.hamlet +++ b/templates/i18n/changelog/de.hamlet @@ -1,5 +1,15 @@ $newline never
+
19.08.2019 +
+