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:
parent
1be333a09a
commit
40f382d74c
@ -202,7 +202,11 @@ makeCourseTable whereClause colChoices psValidator = do
|
|||||||
[ Just $ prismAForm (singletonFilter "search") mPrev $ aopt textField (fslI MsgCourseFilterSearch)
|
[ Just $ prismAForm (singletonFilter "search") mPrev $ aopt textField (fslI MsgCourseFilterSearch)
|
||||||
, muid $> prismAForm (singletonFilter "registered" . maybePrism _PathPiece) mPrev (aopt boolField (fslI MsgCourseFilterRegistered))
|
, 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
|
, dbtParams = def
|
||||||
, dbtIdent = "courses" :: Text
|
, dbtIdent = "courses" :: Text
|
||||||
, dbtCsvEncode = noCsvEncode
|
, dbtCsvEncode = noCsvEncode
|
||||||
|
|||||||
@ -843,44 +843,53 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db
|
|||||||
. setParam (wIdent "page") Nothing
|
. setParam (wIdent "page") Nothing
|
||||||
. setParam (wIdent "pagination") 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' :: HandlerSite m ~ UniWorX => WriterT x m Widget
|
||||||
table' = do
|
table' = case dbsCellTemplate of
|
||||||
let
|
DBSTCourse c l r -> do
|
||||||
genHeaders SortableP{..} = forM (toSortable . oneColonnadeHead <$> getColonnade dbtColonnade) $ \Sortable{..} -> do
|
let
|
||||||
widget <- sortableContent ^. cellContents
|
columnCount :: Int64
|
||||||
let
|
columnCount = olength64 $ getColonnade dbtColonnade
|
||||||
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
|
-- TODO: better name
|
||||||
columnCount = olength64 $ getColonnade dbtColonnade
|
htmlToCourseDescriptionText :: Maybe Html -> Html
|
||||||
|
htmlToCourseDescriptionText (Just html) = html
|
||||||
|
htmlToCourseDescriptionText Nothing = "No description available."
|
||||||
|
|
||||||
wHeaders <- maybe (return Nothing) (fmap Just . genHeaders) pSortable
|
utcTimeToWidget :: Maybe UTCTime -> Widget
|
||||||
|
utcTimeToWidget (Just t) = formatTimeW SelFormatDateTime t
|
||||||
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> cell') -> case dbsCellTemplate of
|
utcTimeToWidget Nothing = mempty -- TODO: Fallunterscheidung in hamlet (andere Darstellung)
|
||||||
DBSTCourse c l r -> let
|
wRows <- forM rows $ \row' -> forM (oneColonnadeEncode <$> getColonnade dbtColonnade) $ \(($ row') -> _cell') -> let
|
||||||
Course{..} = row' ^. c . _entityVal
|
Course{..} = row' ^. c . _entityVal
|
||||||
lecturers = toListOf l row'
|
lecturers = toListOf l row'
|
||||||
courseLecturers = intercalate ", " $ userSurname . entityVal <$> lecturers
|
courseLecturers = intercalate ", " $ userSurname . entityVal <$> lecturers
|
||||||
isRegistered = row' ^. r
|
isRegistered = row' ^. r
|
||||||
courseSchoolName = unSchoolKey courseSchool
|
courseSchoolName = unSchoolKey courseSchool
|
||||||
in return $(widgetFile "table/cell/course-teaser")
|
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
|
widget <- cell' ^. cellContents
|
||||||
let attrs = cell' ^. cellAttrs
|
let attrs = cell' ^. cellAttrs
|
||||||
return $(widgetFile "table/cell/body")
|
return $(widgetFile "table/cell/body")
|
||||||
|
|
||||||
return $(widgetFile "table/colonnade")
|
return $(widgetFile "table/colonnade")
|
||||||
|
|
||||||
pageCount
|
pageCount
|
||||||
| PagesizeLimit l <- psLimit
|
| PagesizeLimit l <- psLimit
|
||||||
|
|||||||
@ -1,13 +1,6 @@
|
|||||||
$newline never
|
$newline never
|
||||||
<div .scrolltable>
|
<div .scrolltable>
|
||||||
<table *{dbsAttrs'}>
|
<table *{dbsAttrs'}>
|
||||||
$maybe wHeaders' <- wHeaders
|
|
||||||
<thead>
|
|
||||||
<tr .table__row.table__row--head>
|
|
||||||
$forall widget <- wHeaders'
|
|
||||||
$# cell/header.hamlet
|
|
||||||
^{widget}
|
|
||||||
$nothing
|
|
||||||
<tbody>
|
<tbody>
|
||||||
$if null wRows && (dbsEmptyStyle == DBESHeading)
|
$if null wRows && (dbsEmptyStyle == DBESHeading)
|
||||||
<tr .table__row>
|
<tr .table__row>
|
||||||
Reference in New Issue
Block a user