Show pagesize widget iff rowCount is larger than minimum pagesize
This commit is contained in:
parent
1a900f215e
commit
19d46eb216
@ -602,11 +602,11 @@ dbTable PSValidator{..} dbtable@DBTable{ dbtIdent = dbtIdent'@(toPathPiece -> db
|
||||
| otherwise
|
||||
= def
|
||||
|
||||
referencePagesize = psLimit . snd . runPSValidator dbtable $ Just prevPi
|
||||
|
||||
(((filterRes, filterWdgt), filterEnc), ((pagesizeRes, pagesizeWdgt), pagesizeEnc)) <- mdo
|
||||
(filterRes'@((filterRes, _), _)) <- runFormGet . identForm FIDDBTableFilter . addPIHiddenField dbtable (prevPi & _piFilter .~ Nothing & _piPage .~ Nothing & _piLimit .~ (formResult' pagesizeRes <|> piLimit prevPi)) . renderAForm FormDBTableFilter $ dbtFilterUI (piFilter prevPi)
|
||||
|
||||
let referencePagesize = psLimit . snd . runPSValidator dbtable $ Just prevPi
|
||||
|
||||
(pagesizeRes'@((pagesizeRes, _), _)) <- lift . runFormGet . identForm FIDDBTablePagesize . addPIHiddenField dbtable (prevPi & _piPage .~ Nothing & _piLimit .~ Nothing & _piFilter .~ (formResult' filterRes <|> piFilter prevPi)) . renderAForm FormDBTablePagesize $
|
||||
areq (pagesizeField referencePagesize) (fslI MsgDBTablePagesize & addAutosubmit & addName (wIdent "pagesize") & addClass "select--pagesize") (Just referencePagesize)
|
||||
<* autosubmitButton
|
||||
@ -760,6 +760,15 @@ dbColonnade :: (Headedness h, Monoid x)
|
||||
-> Colonnade h r (DBCell (ReaderT SqlBackend (HandlerT UniWorX IO)) x)
|
||||
dbColonnade = id
|
||||
|
||||
pagesizeOptions :: PagesizeLimit -- ^ Current/previous value
|
||||
-> NonNull [PagesizeLimit]
|
||||
pagesizeOptions psLim = impureNonNull . Set.toAscList . Set.fromList $ psLim : PagesizeAll : map PagesizeLimit opts
|
||||
where
|
||||
opts :: [Int64]
|
||||
opts = filter (> 0) $ opts' <> map (`div` 2) opts'
|
||||
|
||||
opts' = [ 10^n | n <- [1..3]]
|
||||
|
||||
pagesizeField :: PagesizeLimit -> Field Handler PagesizeLimit
|
||||
pagesizeField psLim = selectField $ do
|
||||
MsgRenderer mr <- getMsgRenderer
|
||||
@ -767,16 +776,9 @@ pagesizeField psLim = selectField $ do
|
||||
optText (PagesizeLimit l) = tshow l
|
||||
optText PagesizeAll = mr MsgDBTablePagesizeAll
|
||||
|
||||
toOptionList = flip OptionList fromPathPiece . map (\o -> Option (optText o) o $ toPathPiece o) . Set.toAscList . Set.fromList
|
||||
return $ toOptionList limOpts
|
||||
where
|
||||
limOpts :: [PagesizeLimit]
|
||||
limOpts = psLim : PagesizeAll : map PagesizeLimit opts
|
||||
toOptionList = flip OptionList fromPathPiece . map (\o -> Option (optText o) o $ toPathPiece o)
|
||||
return . toOptionList . toNullable $ pagesizeOptions psLim
|
||||
|
||||
opts :: [Int64]
|
||||
opts = filter (> 0) $ opts' <> map (`div` 2) opts'
|
||||
|
||||
opts' = [ 10^n | n <- [1..3]]
|
||||
|
||||
--- DBCell utility functions
|
||||
|
||||
|
||||
@ -7,8 +7,8 @@ $else
|
||||
<div .table-footer>
|
||||
<div .table__row-count>
|
||||
_{MsgRowCount rowCount}
|
||||
<!-- TODO: replace '5' with 'minPagesize' -->
|
||||
$if rowCount > 5
|
||||
$# Since the current pagesize is always a member of pagesizeOptions we don't need to check `pageCount > 1`
|
||||
$if toEnum (fromIntegral rowCount) > minimum (pagesizeOptions referencePagesize)
|
||||
<form .pagesize method=GET enctype=#{pagesizeEnc} action=#{rawAction}>
|
||||
^{pagesizeWdgt}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user