From 40f382d74cf8233eacdbd151148d077daafa0e5c Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Mon, 22 Jul 2019 11:16:49 +0200 Subject: [PATCH] refactor(pagination): refactored table' in dbTable Moved case distinction on dbsCellTemplate outside in order to have different widgetFiles for course tables and headers --- src/Handler/Course.hs | 6 +- src/Handler/Utils/Table/Pagination.hs | 69 +++++++++++-------- ...e-table.hamlet => colonnade-course.hamlet} | 7 -- 3 files changed, 44 insertions(+), 38 deletions(-) rename templates/table/{course-table.hamlet => colonnade-course.hamlet} (60%) diff --git a/src/Handler/Course.hs b/src/Handler/Course.hs index 404338e73..3a0a64914 100644 --- a/src/Handler/Course.hs +++ b/src/Handler/Course.hs @@ -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 diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index 500ae400d..dbfb2a73e 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -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 diff --git a/templates/table/course-table.hamlet b/templates/table/colonnade-course.hamlet similarity index 60% rename from templates/table/course-table.hamlet rename to templates/table/colonnade-course.hamlet index 1044d18c8..87475c1af 100644 --- a/templates/table/course-table.hamlet +++ b/templates/table/colonnade-course.hamlet @@ -1,13 +1,6 @@ $newline never
- $maybe wHeaders' <- wHeaders - - - $forall widget <- wHeaders' - $# cell/header.hamlet - ^{widget} - $nothing $if null wRows && (dbsEmptyStyle == DBESHeading)