From f23875927094e66864f8d9153c5888435465505a Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 29 Dec 2018 13:38:31 +0100 Subject: [PATCH] Hide FilterUI by default --- src/Handler/Course.hs | 2 +- src/Handler/Utils/Table/Pagination.hs | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Handler/Course.hs b/src/Handler/Course.hs index 59c898aab..e29c19cb1 100644 --- a/src/Handler/Course.hs +++ b/src/Handler/Course.hs @@ -179,7 +179,7 @@ makeCourseTable whereClause colChoices psValidator = do [ Map.singleton "search" . maybeToList <$> aopt textField (fslI MsgCourseFilterSearch) (Just <$> listToMaybe =<< Map.lookup "search" =<< mPrev) , Map.singleton "registered" . fmap toPathPiece . maybeToList <$> aopt boolField (fslI MsgCourseFilterRegistered) (Just <$> fromPathPiece =<< listToMaybe =<< Map.lookup "registered" =<< mPrev) ] - , dbtStyle = def + , dbtStyle = def { dbsFilterLayout = defaultDBSFilterLayout } , dbtParams = def , dbtIdent = "courses" :: Text } diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index 86fddd4ee..31945a503 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -6,7 +6,7 @@ module Handler.Utils.Table.Pagination , pattern SortAscBy, pattern SortDescBy , FilterColumn(..), IsFilterColumn , DBRow(..), _dbrOutput, _dbrIndex, _dbrCount - , DBStyle(..), DBEmptyStyle(..) + , DBStyle(..), defaultDBSFilterLayout, DBEmptyStyle(..) , DBTable(..), IsDBTable(..), DBCell(..) , DBParams(..) , cellAttrs, cellContents @@ -316,7 +316,7 @@ data DBStyle = DBStyle { dbsEmptyStyle :: DBEmptyStyle , dbsEmptyMessage :: UniWorXMessage , dbsAttrs :: [(Text, Text)] - , dbsLayoutFilter :: Widget -- ^ Filter UI + , dbsFilterLayout :: Widget -- ^ Filter UI -> Enctype -> Text -- ^ Filter action (target uri) -> Widget -- ^ Table @@ -328,9 +328,21 @@ instance Default DBStyle where { dbsEmptyStyle = def , dbsEmptyMessage = MsgNoTableContent , dbsAttrs = [ ("class", "table table--striped table--hover table--sortable") ] - , dbsLayoutFilter = \filterWgdt filterEnctype filterAction scrolltable -> $(widgetFile "table/layout-filter-default") + , dbsFilterLayout = \_filterWgdt _filterEnctype _filterAction scrolltable -> + [whamlet| + $newline never + + ^{scrolltable} + |] } +defaultDBSFilterLayout :: Widget -- ^ Filter UI + -> Enctype + -> Text -- ^ Filter action (target uri) + -> Widget -- ^ Table + -> Widget +defaultDBSFilterLayout filterWgdt filterEnctype filterAction scrolltable = $(widgetFile "table/layout-filter-default") + data DBTable m x = forall a r r' h i t k k'. ( ToSortable h, Functor h , E.SqlSelect a r, SqlIn k k', ToJSON k', FromJSON k', Eq k' @@ -677,7 +689,7 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db return $(widgetFile "table/layout") - bool (dbHandler (Proxy @m) (Proxy @x) $ (\table -> $(widgetFile "table/layout-wrapper")) . dbsLayoutFilter filterWdgt filterEnc rawAction) (sendResponse <=< tblLayout . dbsLayoutFilter filterWdgt filterEnc rawAction <=< dbWidget (Proxy @m) (Proxy @x)) psShortcircuit <=< runDBTable dbtable paginationInput currentKeys . fmap swap $ runWriterT table' + bool (dbHandler (Proxy @m) (Proxy @x) $ (\table -> $(widgetFile "table/layout-wrapper")) . dbsFilterLayout filterWdgt filterEnc rawAction) (sendResponse <=< tblLayout . dbsFilterLayout filterWdgt filterEnc rawAction <=< dbWidget (Proxy @m) (Proxy @x)) psShortcircuit <=< runDBTable dbtable paginationInput currentKeys . fmap swap $ runWriterT table' where tblLayout :: forall m'. (MonadHandler m', HandlerSite m' ~ UniWorX) => Widget -> m' Html tblLayout tbl' = do