From 8f33d1590cf61eef6830f72f0f7314da6d05970d Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 29 May 2019 13:36:11 +0200 Subject: [PATCH] defaultPagesize --- src/Handler/Utils/Table/Pagination.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Handler/Utils/Table/Pagination.hs b/src/Handler/Utils/Table/Pagination.hs index 063b06fd6..52c1b3ec8 100644 --- a/src/Handler/Utils/Table/Pagination.hs +++ b/src/Handler/Utils/Table/Pagination.hs @@ -13,6 +13,7 @@ module Handler.Utils.Table.Pagination , PagesizeLimit(..) , PaginationSettings(..), PaginationInput(..), piIsUnset , PSValidator(..) + , defaultPagesize , defaultFilter, defaultSorting , restrictFilter, restrictSorting , ToSortable(..), Sortable(..) @@ -314,6 +315,13 @@ defaultSorting psSorting (runPSValidator -> f) = PSValidator $ \dbTable' -> inje Just _ -> id Nothing -> set (_2._psSorting) psSorting +defaultPagesize :: PagesizeLimit -> PSValidator m x -> PSValidator m x +defaultPagesize psLimit (runPSValidator -> f) = PSValidator $ \dbTable' -> injectDefault <*> f dbTable' + where + injectDefault x = case x >>= piLimit of + Just _ -> id + Nothing -> set (_2._psLimit) psLimit + restrictFilter :: (FilterKey -> [Text] -> Bool) -> PSValidator m x -> PSValidator m x restrictFilter restrict (runPSValidator -> f) = PSValidator $ \dbTable' ps -> over _2 restrict' $ f dbTable' ps where