@@ -24,24 +24,24 @@ import Distribution.Text
24
24
import Distribution.Utils.ShortText (fromShortText )
25
25
26
26
import qualified Text.XHtml.Strict as XHtml
27
- import Text.XHtml
28
- ( Html , URL , (<<) , (!) )
27
+ import Text.XHtml ( Html , URL , (<<) , (!) )
29
28
import qualified Text.RSS as RSS
30
29
import Text.RSS ( RSS (RSS ) )
31
30
import Network.URI ( URI (.. ), uriToString )
32
31
import Data.Time.Clock ( UTCTime )
33
32
import Data.Time.Format ( defaultTimeLocale , formatTime )
34
- import Data.Maybe ( listToMaybe )
35
- import Distribution.Server.Util.Paging (PaginatedConf (.. ), paginate , allPagedURLS , hasNext , hasPrev , pageIndexRange )
36
- import qualified Text.XHtml as Xhtml
33
+ import Data.Maybe ( listToMaybe , fromMaybe )
34
+ import Distribution.Server.Util.Paging (PaginatedConfiguration (.. ), hasNext ,
35
+ hasPrev , nextURL , pageIndexRange , paginate , prevURL , toURL , allPagedURLs )
37
36
38
37
-- | Takes a list of package info, in reverse order by timestamp.
39
38
40
- recentPage :: PaginatedConf -> Users -> [PkgInfo ] -> Html
39
+ recentPage :: PaginatedConfiguration -> Users -> [PkgInfo ] -> Html
41
40
recentPage conf users pkgs =
42
41
let log_rows = makeRow users <$> paginate conf pkgs
43
42
docBody =
44
43
[ XHtml. h2 << " Recent additions" ,
44
+ pageSizeForm recentURL,
45
45
XHtml. table ! [XHtml. align " center" ] << log_rows,
46
46
paginator conf recentURL,
47
47
XHtml. anchor ! [XHtml. href recentRevisionsURL] << XHtml. toHtml " Recent revisions"
@@ -51,26 +51,36 @@ recentPage conf users pkgs =
51
51
! [ XHtml. rel " alternate" ,
52
52
XHtml. thetype " application/rss+xml" ,
53
53
XHtml. title " Hackage RSS Feed" ,
54
- XHtml. href rssFeedURL
54
+ XHtml. href $ toURL rssFeedURL conf
55
55
]
56
56
<< XHtml. noHtml
57
57
in hackagePageWithHead [rss_link] " recent additions" docBody
58
58
59
- paginator :: PaginatedConf -> URL -> Html
60
- paginator pc@ (PaginatedConf currPage _ totalAmount) baseUrl =
59
+
60
+ pageSizeForm :: URL -> Html
61
+ pageSizeForm base =
62
+ let pageSizeLabel = XHtml. label ! [XHtml. thefor " pageSize" ] << " Page Size: "
63
+ pageSizeInput = XHtml. input ! [XHtml. thetype " number" , XHtml. name " pageSize" , XHtml. strAttr " min" " 0" ]
64
+ submitButton = XHtml. button ! [XHtml. thetype " submit" ] << " Submit"
65
+ theForm = XHtml. form ! [XHtml. action base, XHtml. method " GET" ]
66
+ in theForm << (pageSizeLabel <> pageSizeInput <> submitButton)
67
+
68
+
69
+ paginator :: PaginatedConfiguration -> URL -> Html
70
+ paginator pc@ PaginatedConfiguration {currPage,totalAmount} baseUrl =
61
71
let
62
72
(start, end) = pageIndexRange pc
63
73
infoText = " Showing " ++ show start ++ " to " ++ show end ++ " of " ++ show totalAmount ++ " entries"
64
74
info = XHtml. thediv << infoText
65
75
66
76
next = if hasNext pc
67
- then XHtml. anchor ! [XHtml. href (paginateURLNext pc baseUrl)] << " Next"
68
- else Xhtml . noHtml
77
+ then XHtml. anchor ! [XHtml. href (fromMaybe " " (nextURL baseUrl pc) )] << " Next"
78
+ else XHtml . noHtml
69
79
prev = if hasPrev pc
70
- then XHtml. anchor ! [XHtml. href (paginateURLPrev pc baseUrl) ] << " Previous"
80
+ then XHtml. anchor ! [XHtml. href (fromMaybe " " (prevURL baseUrl pc) ) ] << " Previous"
71
81
else XHtml. noHtml
72
82
73
- pagedURLS = zip [1 .. ] (allPagedURLS baseUrl pc)
83
+ pagedURLS = zip [1 .. ] (allPagedURLs baseUrl pc)
74
84
pagedLinks = (\ (x,y) -> XHtml. anchor ! [XHtml. href y,
75
85
if currPage == x then XHtml. theclass " current" else noAttr ] << show x) <$> pagedURLS
76
86
@@ -84,14 +94,14 @@ paginator pc@(PaginatedConf currPage _ totalAmount) baseUrl =
84
94
noAttr :: XHtml. HtmlAttr
85
95
noAttr = XHtml. theclass " "
86
96
87
- -- Worst code I've written so far
88
- reducePagedLinks :: PaginatedConf -> [Html ] -> Html
89
- reducePagedLinks PaginatedConf {currPage} xs
97
+ -- | Generates a list of links of the current possible paging links, recreates the functionality of the paging links on the search page
98
+ reducePagedLinks :: PaginatedConfiguration -> [Html ] -> Html
99
+ reducePagedLinks PaginatedConfiguration {currPage} xs
90
100
| currPage >= (length xs - 3 ) = mconcat . keepLastPages . fillFirst $ xs -- Beginning ellipses
91
101
| length xs > 5 && currPage < 5 = mconcat . keepFirstPages . fillLast $ xs -- Ending ellipses
92
102
| length xs <= 5 = mconcat xs -- Do Nothing
93
103
| otherwise = mconcat . keepMiddlePages . fillLast . fillFirst $ xs -- Begin and End ellipses
94
- where filler = XHtml. anchor << " ..."
104
+ where filler = XHtml. thespan << " ..."
95
105
fillFirst x = insertAt 1 filler x
96
106
fillLast x = insertAt (pred . length $ x) filler x
97
107
keepFirstPages x = case splitAt (length x - 2 ) x of (hts, hts') -> take 5 hts ++ hts'
@@ -106,16 +116,12 @@ insertAt n a x = case splitAt n x of (hts, hts') -> hts ++ [a] ++ hts'
106
116
takeLast :: Int -> [a ] -> [a ]
107
117
takeLast n = reverse . take n . reverse
108
118
109
- -- Should actually check if next exists
110
- paginateURLNext ,paginateURLPrev :: PaginatedConf -> URL -> URL
111
- paginateURLNext (PaginatedConf cp _ _) url = url <> " ?page=" ++ (show . succ ) cp
112
- paginateURLPrev (PaginatedConf cp _ _) url = url <> " ?page=" ++ (show . pred ) cp
113
-
114
- revisionsPage :: PaginatedConf -> Users -> [PkgInfo ] -> Html
119
+ revisionsPage :: PaginatedConfiguration -> Users -> [PkgInfo ] -> Html
115
120
revisionsPage conf users pkgs =
116
121
let log_rows = map (makeRevisionRow users) (paginate conf pkgs)
117
122
docBody =
118
123
[ XHtml. h2 << " Recent cabal metadata revisions" ,
124
+ pageSizeForm recentRevisionsURL,
119
125
XHtml. table ! [XHtml. align " center" ] << log_rows,
120
126
paginator conf recentRevisionsURL
121
127
]
@@ -124,7 +130,7 @@ revisionsPage conf users pkgs =
124
130
! [ XHtml. rel " alternate" ,
125
131
XHtml. thetype " application/rss+xml" ,
126
132
XHtml. title " Hackage Revisions RSS Feed" ,
127
- XHtml. href revisionsRssFeedURL
133
+ XHtml. href $ toURL revisionsRssFeedURL conf
128
134
]
129
135
<< XHtml. noHtml
130
136
in hackagePageWithHead [rss_link] " recent revisions" docBody
@@ -190,7 +196,7 @@ recentRevisionsURL :: URL
190
196
recentRevisionsURL = " /packages/recent/revisions.html"
191
197
192
198
193
- recentFeed :: PaginatedConf -> Users -> URI -> UTCTime -> [PkgInfo ] -> RSS
199
+ recentFeed :: PaginatedConfiguration -> Users -> URI -> UTCTime -> [PkgInfo ] -> RSS
194
200
recentFeed conf users hostURI now pkgs = RSS
195
201
" Recent additions"
196
202
(hostURI { uriPath = recentAdditionsURL})
@@ -203,7 +209,7 @@ recentFeed conf users hostURI now pkgs = RSS
203
209
pkgList = paginate conf pkgs
204
210
updated = maybe now (fst . pkgOriginalUploadInfo) (listToMaybe pkgList)
205
211
206
- recentRevisionsFeed :: PaginatedConf -> Users -> URI -> UTCTime -> [PkgInfo ] -> RSS
212
+ recentRevisionsFeed :: PaginatedConfiguration -> Users -> URI -> UTCTime -> [PkgInfo ] -> RSS
207
213
recentRevisionsFeed conf users hostURI now pkgs = RSS
208
214
" Recent revisions"
209
215
(hostURI { uriPath = recentRevisionsURL})
0 commit comments