Skip to content

Commit 2e0de96

Browse files
committed
Fix showing ellipsis on small paging results
1 parent 798745f commit 2e0de96

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Distribution/Server/Pages/Recent.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Data.Time.Clock ( UTCTime )
3232
import Data.Time.Format ( defaultTimeLocale, formatTime )
3333
import Data.Maybe ( listToMaybe, fromMaybe)
3434
import Distribution.Server.Util.Paging (PaginatedConfiguration(..), hasNext,
35-
hasPrev, nextURL, pageIndexRange, paginate, prevURL, toURL, allPagedURLs)
35+
hasPrev, nextURL, pageIndexRange, paginate, prevURL, toURL, allPagedURLs, pagingInfo)
3636

3737
-- | Takes a list of package info, in reverse order by timestamp.
3838

@@ -67,11 +67,9 @@ pageSizeForm base =
6767

6868

6969
paginator :: PaginatedConfiguration -> URL -> Html
70-
paginator pc@PaginatedConfiguration{currPage,totalAmount} baseUrl =
70+
paginator pc@PaginatedConfiguration{currPage} baseUrl =
7171
let
72-
(start, end) = pageIndexRange pc
73-
infoText = "Showing " ++ show start ++ " to " ++ show end ++ " of " ++ show totalAmount ++ " entries"
74-
info = XHtml.thediv << infoText
72+
info = XHtml.thediv << pagingInfo pc
7573

7674
next = XHtml.anchor ! [XHtml.href (fromMaybe "" (nextURL baseUrl pc)) | hasNext pc] << "Next"
7775
prev = XHtml.anchor ! [XHtml.href (fromMaybe "" (prevURL baseUrl pc)) | hasPrev pc] << "Previous"
@@ -93,9 +91,9 @@ noAttr = XHtml.theclass ""
9391
-- | Generates a list of links of the current possible paging links, recreates the functionality of the paging links on the search page
9492
reducePagedLinks :: PaginatedConfiguration -> [Html] -> Html
9593
reducePagedLinks PaginatedConfiguration{currPage} xs
96-
| currPage >= (length xs - 3) = mconcat . keepLastPages .fillFirst $ xs -- Beginning ellipses
97-
| length xs > 5 && currPage < 5 = mconcat . keepFirstPages . fillLast $ xs -- Ending ellipses
9894
| length xs <= 5 = mconcat xs -- Do Nothing
95+
| currPage >= (length xs - 3) = mconcat . keepLastPages .fillFirst $ xs -- Beginning ellipses
96+
| currPage < 5 = mconcat . keepFirstPages . fillLast $ xs -- Ending ellipses
9997
| otherwise = mconcat . keepMiddlePages . fillLast . fillFirst $ xs -- Begin and End ellipses
10098
where filler = XHtml.thespan << "..."
10199
fillFirst x = insertAt 1 filler x

src/Distribution/Server/Util/Paging.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ module Distribution.Server.Util.Paging
1414
nextURL,
1515
prevURL,
1616
toURL,
17+
pagingInfo,
1718
PaginatedConfiguration(..),
1819
)
1920
where
2021
import Text.XHtml (URL)
2122
import Data.List (genericTake, genericDrop, genericLength)
2223

23-
-- This could be better designed, perhaps turning PaginatedConfiguration into a function that returns the paging info
24-
-- and the paged data
24+
-- This could be better designed, perhaps turning PaginatedConfiguration into a
25+
-- function that returns the paging info and the paged data
2526
data PaginatedConfiguration = PaginatedConfiguration
2627
{ currPage :: Int,
2728
pageSize :: Int,
@@ -78,3 +79,11 @@ prevURL base conf@PaginatedConfiguration {currPage}
7879
| page < 1 = Nothing
7980
| otherwise = Just $ toURL base conf{currPage=page}
8081
where page = pred currPage
82+
83+
84+
pagingInfo :: PaginatedConfiguration -> String
85+
pagingInfo pc@PaginatedConfiguration{totalAmount} = "Showing " ++ show start ++ " to "
86+
++ show end ++ " of " ++ show totalAmount ++ endingText
87+
where (start, end) = pageIndexRange pc
88+
endingText = if pageAmount > 0 then " entries" else " entry"
89+
pageAmount = end - start -- Starts Indexing at 1

0 commit comments

Comments
 (0)