Fixes #337
This commit is contained in:
parent
d1a8d9cc17
commit
6743e3b4d7
@ -223,6 +223,7 @@ MaterialTypeExample: Beispiel
|
|||||||
MaterialDescription: Beschreibung
|
MaterialDescription: Beschreibung
|
||||||
MaterialVisibleFrom: Sichtbar für Teilnehmer ab
|
MaterialVisibleFrom: Sichtbar für Teilnehmer ab
|
||||||
MaterialVisibleFromTip: Ohne Datum nie sichtbar für Teilnehmer; leer lassen ist nur sinnvoll für unfertige Materialien oder zur ausschließlichen Verteilung an Korrektoren
|
MaterialVisibleFromTip: Ohne Datum nie sichtbar für Teilnehmer; leer lassen ist nur sinnvoll für unfertige Materialien oder zur ausschließlichen Verteilung an Korrektoren
|
||||||
|
MaterialVisibleFromEditWarning: Das Datum der Veröffentlichung liegt in der Vergangenheit und sollte nicht mehr verändert werden, da dies die Benutzer verwirren könnte.
|
||||||
MaterialInvisible: Dieses Material ist für Teilnehmer momentan unsichtbar!
|
MaterialInvisible: Dieses Material ist für Teilnehmer momentan unsichtbar!
|
||||||
MaterialInvisibleUntil date@Text: Dieses Material ist für Teilnehmer momentan unsichtbar bis #{date}!
|
MaterialInvisibleUntil date@Text: Dieses Material ist für Teilnehmer momentan unsichtbar bis #{date}!
|
||||||
MaterialFiles: Dateien
|
MaterialFiles: Dateien
|
||||||
|
|||||||
@ -53,7 +53,13 @@ makeMaterialForm cid template = identifyForm FIDmaterial $ \html -> do
|
|||||||
return $ material E.^. MaterialType
|
return $ material E.^. MaterialType
|
||||||
return $ defaults <> Set.fromList (mapMaybe E.unValue previouslyUsed)
|
return $ defaults <> Set.fromList (mapMaybe E.unValue previouslyUsed)
|
||||||
|
|
||||||
ctime <- ceilingQuarterHour <$> liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
let ctime = ceilingQuarterHour now
|
||||||
|
let visibleToolTip = case mfVisibleFrom <$> template of
|
||||||
|
(Just (Just vistime)) | vistime <= now
|
||||||
|
-> MsgMaterialVisibleFromEditWarning
|
||||||
|
_ -> MsgMaterialVisibleFromTip
|
||||||
|
|
||||||
flip (renderAForm FormStandard) html $ MaterialForm
|
flip (renderAForm FormStandard) html $ MaterialForm
|
||||||
<$> areq ciField (fslI MsgMaterialName) (mfName <$> template)
|
<$> areq ciField (fslI MsgMaterialName) (mfName <$> template)
|
||||||
<*> aopt (textField & addDatalist typeOptions)
|
<*> aopt (textField & addDatalist typeOptions)
|
||||||
@ -61,8 +67,8 @@ makeMaterialForm cid template = identifyForm FIDmaterial $ \html -> do
|
|||||||
(mfType <$> template)
|
(mfType <$> template)
|
||||||
<*> aopt htmlField (fslpI MsgMaterialDescription "Html")
|
<*> aopt htmlField (fslpI MsgMaterialDescription "Html")
|
||||||
(mfDescription <$> template)
|
(mfDescription <$> template)
|
||||||
<*> aopt utcTimeField (fslI MsgMaterialVisibleFrom
|
<*> aopt utcTimeField (fslI MsgMaterialVisibleFrom & setTooltip visibleToolTip)
|
||||||
& setTooltip MsgMaterialVisibleFromTip) ((mfVisibleFrom <$> template) <|> pure (Just ctime))
|
((mfVisibleFrom <$> template) <|> pure (Just ctime))
|
||||||
<*> aopt (multiFileField oldFileIds)
|
<*> aopt (multiFileField oldFileIds)
|
||||||
(fslI MsgMaterialFiles) (mfFiles <$> template)
|
(fslI MsgMaterialFiles) (mfFiles <$> template)
|
||||||
|
|
||||||
@ -83,7 +89,15 @@ getMaterialListR :: TermId -> SchoolId -> CourseShorthand -> Handler Html
|
|||||||
getMaterialListR tid ssh csh = do
|
getMaterialListR tid ssh csh = do
|
||||||
let matLink :: MaterialName -> Route UniWorX
|
let matLink :: MaterialName -> Route UniWorX
|
||||||
matLink = CourseR tid ssh csh . flip MaterialR MShowR
|
matLink = CourseR tid ssh csh . flip MaterialR MShowR
|
||||||
|
|
||||||
|
materialModDateCell :: IsDBTable m a => Material -> DBCell m a
|
||||||
|
materialModDateCell Material{materialVisibleFrom, materialLastEdit}
|
||||||
|
| NTop materialVisibleFrom >= NTop (Just materialLastEdit)
|
||||||
|
= mempty -- empty cells mean no modification after publication
|
||||||
|
| otherwise = dateTimeCell materialLastEdit -- modification after publication is highlighted by being shown
|
||||||
|
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
seeAllModificationTimestamps <- hasWriteAccessTo $ CourseR tid ssh csh MaterialNewR -- ordinary users should not see modification dates older than visibility
|
||||||
table <- runDB $ do
|
table <- runDB $ do
|
||||||
cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh
|
cid <- getKeyBy404 $ TermSchoolCourseShort tid ssh csh
|
||||||
let row2material = entityVal . dbrOutput -- no inner join, just Entity Material
|
let row2material = entityVal . dbrOutput -- no inner join, just Entity Material
|
||||||
@ -109,7 +123,9 @@ getMaterialListR tid ssh csh = do
|
|||||||
, sortable (Just "visible-from") (i18nCell MsgAccessibleSince)
|
, sortable (Just "visible-from") (i18nCell MsgAccessibleSince)
|
||||||
$ foldMap (dateTimeCellVisible now) . materialVisibleFrom . row2material
|
$ foldMap (dateTimeCellVisible now) . materialVisibleFrom . row2material
|
||||||
, sortable (Just "last-edit") (i18nCell MsgFileModified)
|
, sortable (Just "last-edit") (i18nCell MsgFileModified)
|
||||||
$ dateTimeCell . materialLastEdit . row2material
|
$ if seeAllModificationTimestamps
|
||||||
|
then dateTimeCell . materialLastEdit . row2material
|
||||||
|
else materialModDateCell . row2material
|
||||||
]
|
]
|
||||||
, dbtSorting = Map.fromList
|
, dbtSorting = Map.fromList
|
||||||
[ ( "type" , SortColumn (E.^. MaterialType) )
|
[ ( "type" , SortColumn (E.^. MaterialType) )
|
||||||
@ -128,6 +144,8 @@ getMaterialListR tid ssh csh = do
|
|||||||
$(widgetFile "material-list")
|
$(widgetFile "material-list")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getMFileR :: TermId -> SchoolId -> CourseShorthand -> MaterialName -> FilePath -> Handler TypedContent
|
getMFileR :: TermId -> SchoolId -> CourseShorthand -> MaterialName -> FilePath -> Handler TypedContent
|
||||||
getMFileR tid ssh csh mnm title = serveOneFile fileQuery
|
getMFileR tid ssh csh mnm title = serveOneFile fileQuery
|
||||||
where
|
where
|
||||||
@ -151,9 +169,16 @@ getMShowR :: TermId -> SchoolId -> CourseShorthand -> MaterialName -> Handler Ht
|
|||||||
getMShowR tid ssh csh mnm = do
|
getMShowR tid ssh csh mnm = do
|
||||||
let matLink :: FilePath -> Route UniWorX
|
let matLink :: FilePath -> Route UniWorX
|
||||||
matLink = CourseR tid ssh csh . MaterialR mnm . MFileR
|
matLink = CourseR tid ssh csh . MaterialR mnm . MFileR
|
||||||
|
|
||||||
|
seeAllModificationTimestamps <- hasWriteAccessTo $ CourseR tid ssh csh MaterialNewR -- ordinary users should not see modification dates older than visibility
|
||||||
|
|
||||||
( Entity _mid material@Material{materialType, materialDescription}
|
( Entity _mid material@Material{materialType, materialDescription}
|
||||||
, (Any hasFiles,fileTable)) <- runDB $ do
|
, (Any hasFiles,fileTable)) <- runDB $ do
|
||||||
matEnt <- fetchMaterial tid ssh csh mnm
|
matEnt <- fetchMaterial tid ssh csh mnm
|
||||||
|
let materialModDateCell :: (IsDBTable m c) => (t -> E.Value UTCTime) -> Colonnade Sortable t (DBCell m c)
|
||||||
|
materialModDateCell = if seeAllModificationTimestamps
|
||||||
|
then colFileModification
|
||||||
|
else colFileModificationWhen $ \t -> NTop (Just t) > NTop (materialVisibleFrom $ entityVal matEnt)
|
||||||
let psValidator = def & defaultSortingByFileTitle
|
let psValidator = def & defaultSortingByFileTitle
|
||||||
fileTable' <- dbTable psValidator DBTable
|
fileTable' <- dbTable psValidator DBTable
|
||||||
{ dbtSQLQuery = \(matFile `E.InnerJoin` file) -> do
|
{ dbtSQLQuery = \(matFile `E.InnerJoin` file) -> do
|
||||||
@ -165,7 +190,7 @@ getMShowR tid ssh csh mnm = do
|
|||||||
, dbtColonnade = widgetColonnade $ mconcat
|
, dbtColonnade = widgetColonnade $ mconcat
|
||||||
[ dbRowIndicator -- important: contains writer to indicate that the tables is not empty
|
[ dbRowIndicator -- important: contains writer to indicate that the tables is not empty
|
||||||
, colFilePathSimple (view $ _dbrOutput . _1) matLink
|
, colFilePathSimple (view $ _dbrOutput . _1) matLink
|
||||||
, colFileModification (view $ _dbrOutput . _2)
|
, materialModDateCell (view $ _dbrOutput . _2)
|
||||||
]
|
]
|
||||||
, dbtProj = \dbr -> guardAuthorizedFor (matLink $ dbr ^. _dbrOutput . _1 . _Value) dbr
|
, dbtProj = \dbr -> guardAuthorizedFor (matLink $ dbr ^. _dbrOutput . _1 . _Value) dbr
|
||||||
, dbtStyle = def
|
, dbtStyle = def
|
||||||
|
|||||||
@ -53,11 +53,15 @@ pathPieceCell = cell . toWidget . toPathPiece
|
|||||||
sqlCell :: (IsDBTable (YesodDB UniWorX) a) => YesodDB UniWorX Widget -> DBCell (YesodDB UniWorX) a
|
sqlCell :: (IsDBTable (YesodDB UniWorX) a) => YesodDB UniWorX Widget -> DBCell (YesodDB UniWorX) a
|
||||||
sqlCell act = mempty & cellContents .~ lift act
|
sqlCell act = mempty & cellContents .~ lift act
|
||||||
|
|
||||||
markCell :: (IsDBTable m a) => (a -> Bool) -> (a -> DBCell m a) -> a -> DBCell m a
|
markCell :: (IsDBTable m a) => (t -> Bool) -> (t -> DBCell m a) -> (t -> DBCell m a)
|
||||||
markCell condition normal x
|
markCell condition normal x
|
||||||
| condition x = normal x <> cell (isVisibleWidget False)
|
| condition x = normal x <> cell (isVisibleWidget False)
|
||||||
| otherwise = normal x
|
| otherwise = normal x
|
||||||
|
|
||||||
|
ifCell :: (IsDBTable m a) => (t -> Bool) -> (t -> DBCell m a) -> (t -> DBCell m a) -> (t -> DBCell m a)
|
||||||
|
ifCell decision cTrue cFalse x
|
||||||
|
| decision x = cTrue x
|
||||||
|
| otherwise = cFalse x
|
||||||
|
|
||||||
-- Recall: for line numbers, use dbRow
|
-- Recall: for line numbers, use dbRow
|
||||||
|
|
||||||
|
|||||||
@ -69,6 +69,11 @@ colFilePathSimple row2path row2link = sortable (Just "path") (i18nCell MsgFileTi
|
|||||||
colFileModification :: (IsDBTable m c) => (t -> E.Value UTCTime) -> Colonnade Sortable t (DBCell m c)
|
colFileModification :: (IsDBTable m c) => (t -> E.Value UTCTime) -> Colonnade Sortable t (DBCell m c)
|
||||||
colFileModification row2time = sortable (Just "time") (i18nCell MsgFileModified) (dateTimeCell . E.unValue . row2time)
|
colFileModification row2time = sortable (Just "time") (i18nCell MsgFileModified) (dateTimeCell . E.unValue . row2time)
|
||||||
|
|
||||||
|
colFileModificationWhen :: (IsDBTable m c) => (UTCTime -> Bool) -> (t -> E.Value UTCTime) -> Colonnade Sortable t (DBCell m c)
|
||||||
|
colFileModificationWhen condition row2time = sortable (Just "time") (i18nCell MsgFileModified) (conDTCell . E.unValue . row2time)
|
||||||
|
where conDTCell = ifCell condition dateTimeCell $ const mempty
|
||||||
|
|
||||||
|
|
||||||
sortFilePath :: IsString s => (r -> E.SqlExpr (Entity File)) -> (s, SortColumn r)
|
sortFilePath :: IsString s => (r -> E.SqlExpr (Entity File)) -> (s, SortColumn r)
|
||||||
sortFilePath queryPath = ("path", SortColumn $ queryPath >>> (E.^. FileTitle))
|
sortFilePath queryPath = ("path", SortColumn $ queryPath >>> (E.^. FileTitle))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user