diff --git a/src/Handler/Material.hs b/src/Handler/Material.hs index 29b3a0792..483f35671 100644 --- a/src/Handler/Material.hs +++ b/src/Handler/Material.hs @@ -79,16 +79,44 @@ fetchMaterial tid ssh csh mnm = do getMaterialListR :: TermId -> SchoolId -> CourseShorthand -> Handler Html -getMaterialListR _tid _ssh _csh = do - -- muid <- maybeAuthId - -- cid <- runDB . getKeyBy404 $ TermSchoolCourseShort tid ssh csh - -- table <- return $ error "unimplemented" -- TODO - -- let headingLong = prependCourseTitle tid ssh csh $ MsgMaterialListHeading - -- headingShort = prependCourseTitle tid ssh csh $ MsgMaterialListHeading - -- siteLayoutMsg headingLong $ do - -- setTitleI headingShort - -- $(widgetFile "material-list") - error "unimplemented" -- TODO +getMaterialListR tid ssh csh = do + let matLink :: MaterialName -> Route UniWorX + matLink = CourseR tid ssh csh . flip MaterialR MShowR + _muid <- maybeAuthId + table <- runDB $ do + cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh + let psValidator = def & defaultSorting [SortDescBy "last-edit"] + table <- dbTableWidget' psValidator DBTable + { dbtIdent = "material-list" :: Text + , dbtStyle = def + , dbtParams = def + , dbtSQLQuery = \material -> do + E.where_ $ material E.^. MaterialCourse E.==. E.val cid + return material + , dbtRowKey = (E.^. MaterialId) + , dbtProj = \dbr@DBRow{ dbrOutput=(Entity _ Material{..}) } -> + let link = matLink materialName + in guardAuthorizedFor link dbr + , dbtColonnade = widgetColonnade $ mconcat + [ dbRow + , sortable (Just "name") (i18nCell MsgMaterialName) + $ \DBRow{dbrOutput=(Entity _ Material{..})} -> cell $ toWgt materialName + ] + , dbtSorting = const Map.empty -- Map.fromList + [ + + ] + , dbtFilter = mempty + , dbtFilterUI = mempty + } + return table + + let headingLong = prependCourseTitle tid ssh csh $ MsgMaterialListHeading + headingShort = prependCourseTitle tid ssh csh $ MsgMaterialListHeading + siteLayoutMsg headingLong $ do + setTitleI headingShort + $(widgetFile "material-list") + getMFileR :: TermId -> SchoolId -> CourseShorthand -> MaterialName -> FilePath -> Handler TypedContent getMFileR tid ssh csh mnm title = serveOneFile fileQuery @@ -125,14 +153,12 @@ getMShowR tid ssh csh mnm = do return (file E.^. FileTitle, file E.^. FileModified) , dbtRowKey = \(_ `E.InnerJoin` file) -> file E.^. FileId , dbtColonnade = widgetColonnade $ mconcat - [ -- dbRowIndicator -- important: contains writer to indicate that the tables is not empty - colFilePathSimple (view _1) matLink - , colFileModification (view _2) + [ dbRowIndicator -- important: contains writer to indicate that the tables is not empty + , colFilePathSimple (view $ _dbrOutput . _1) matLink + , colFileModification (view $ _dbrOutput . _2) ] - , dbtProj = \row -> - let dbrOutput = row ^. _dbrOutput - fPath = dbrOutput ^. _1 . _Value - in guardAuthorizedFor (matLink fPath) dbrOutput + , dbtProj = \dbr@DBRow{ dbrOutput=(E.Value fPath, _) } -> + guardAuthorizedFor (matLink fPath) dbr , dbtStyle = def , dbtParams = def , dbtFilter = mempty