refactor(pagination): refactored table' in dbTable

Moved case distinction on dbsCellTemplate outside in order to have
different widgetFiles for course tables and headers
This commit is contained in:
Sarah Vaupel 2019-07-22 11:16:49 +02:00
parent 1be333a09a
commit 40f382d74c
3 changed files with 44 additions and 38 deletions

View File

@ -202,7 +202,11 @@ makeCourseTable whereClause colChoices psValidator = do
[ Just $ prismAForm (singletonFilter "search") mPrev $ aopt textField (fslI MsgCourseFilterSearch)
, muid $> prismAForm (singletonFilter "registered" . maybePrism _PathPiece) mPrev (aopt boolField (fslI MsgCourseFilterRegistered))
]
, dbtStyle = def { dbsFilterLayout = defaultDBSFilterLayout }
, dbtStyle = def
{ dbsFilterLayout = defaultDBSFilterLayout
-- DBSTCourse :: Lens' r (Entity Course) -> Traversal' r (Entity User) -> Lens' r Bool -> DBSTemplateMode r
-- , dbsCellTemplate = DBSTCourse undefined undefined undefined
}
, dbtParams = def
, dbtIdent = "courses" :: Text
, dbtCsvEncode = noCsvEncode

View File

@ -843,44 +843,53 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db
. setParam (wIdent "page") Nothing
. setParam (wIdent "pagination") Nothing
htmlToCourseDescriptionText (Just html) = html
htmlToCourseDescriptionText Nothing = "No description available."
utcTimeToWidget (Just t) = formatTimeW SelFormatDateTime t
utcTimeToWidget Nothing = mempty -- TODO: Fallunterscheidung in hamlet (andere Darstellung)
table' :: HandlerSite m ~ UniWorX => WriterT x m Widget
table' = do
let
genHeaders SortableP{..} = forM (toSortable . oneColonnadeHead <$> getColonnade dbtColonnade) $ \Sortable{..} -> do
widget <- sortableContent ^. cellContents
let
directions = [dir | SortingSetting k dir <- psSorting, Just k == sortableKey ]
isSortable = isJust sortableKey
isSorted = (`elem` directions)
attrs = sortableContent ^. cellAttrs
piSorting' = [ sSet | sSet <- fromMaybe [] piSorting, Just (sortKey sSet) /= sortableKey ]
return $(widgetFile "table/cell/header")
table' = case dbsCellTemplate of
DBSTCourse c l r -> do
let
columnCount :: Int64
columnCount = olength64 $ getColonnade dbtColonnade
columnCount :: Int64
columnCount = olength64 $ getColonnade dbtColonnade
-- TODO: better name
htmlToCourseDescriptionText :: Maybe Html -> Html
htmlToCourseDescriptionText (Just html) = html
htmlToCourseDescriptionText Nothing = "No description available."
wHeaders <- maybe (return Nothing) (fmap Just . genHeaders) pSortable
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> cell') -> case dbsCellTemplate of
DBSTCourse c l r -> let
Course{..} = row' ^. c . _entityVal
lecturers = toListOf l row'
courseLecturers = intercalate ", " $ userSurname . entityVal <$> lecturers
isRegistered = row' ^. r
courseSchoolName = unSchoolKey courseSchool
utcTimeToWidget :: Maybe UTCTime -> Widget
utcTimeToWidget (Just t) = formatTimeW SelFormatDateTime t
utcTimeToWidget Nothing = mempty -- TODO: Fallunterscheidung in hamlet (andere Darstellung)
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> _cell') -> let
Course{..} = row' ^. c . _entityVal
lecturers = toListOf l row'
courseLecturers = intercalate ", " $ userSurname . entityVal <$> lecturers
isRegistered = row' ^. r
courseSchoolName = unSchoolKey courseSchool
in return $(widgetFile "table/cell/course-teaser")
DBSTDefault -> do
return $(widgetFile "table/colonnade-course")
DBSTDefault -> do
let
genHeaders SortableP{..} = forM (toSortable . oneColonnadeHead <$> getColonnade dbtColonnade) $ \Sortable{..} -> do
widget <- sortableContent ^. cellContents
let
directions = [dir | SortingSetting k dir <- psSorting, Just k == sortableKey ]
isSortable = isJust sortableKey
isSorted = (`elem` directions)
attrs = sortableContent ^. cellAttrs
piSorting' = [ sSet | sSet <- fromMaybe [] piSorting, Just (sortKey sSet) /= sortableKey ]
return $(widgetFile "table/cell/header")
columnCount :: Int64
columnCount = olength64 $ getColonnade dbtColonnade
wHeaders <- maybe (return Nothing) (fmap Just . genHeaders) pSortable
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> cell') -> do
widget <- cell' ^. cellContents
let attrs = cell' ^. cellAttrs
return $(widgetFile "table/cell/body")
return $(widgetFile "table/colonnade")
return $(widgetFile "table/colonnade")
pageCount
| PagesizeLimit l <- psLimit

View File

@ -1,13 +1,6 @@
$newline never
<div .scrolltable>
<table *{dbsAttrs'}>
$maybe wHeaders' <- wHeaders
<thead>
<tr .table__row.table__row--head>
$forall widget <- wHeaders'
$# cell/header.hamlet
^{widget}
$nothing
<tbody>
$if null wRows && (dbsEmptyStyle == DBESHeading)
<tr .table__row>