From 735c86658d058512f5d86408e18e3c81c32788d1 Mon Sep 17 00:00:00 2001 From: snu-ceyda Date: Thu, 9 Jul 2020 14:56:15 +0900 Subject: fileserver: Enable browse pagination with offset parameter (#3542) * Update browse.go * Update browselisting.go * Update browsetpl.go * fix linter err * Update modules/caddyhttp/fileserver/browse.go Co-authored-by: Matt Holt * Update modules/caddyhttp/fileserver/browselisting.go Co-authored-by: Matt Holt * Update browsetpl.go change from -> offset * Update browse.go * Update browselisting.go Co-authored-by: Matt Holt --- modules/caddyhttp/fileserver/browselisting.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'modules/caddyhttp/fileserver/browselisting.go') diff --git a/modules/caddyhttp/fileserver/browselisting.go b/modules/caddyhttp/fileserver/browselisting.go index 9c7c4a2..cebfe8f 100644 --- a/modules/caddyhttp/fileserver/browselisting.go +++ b/modules/caddyhttp/fileserver/browselisting.go @@ -101,6 +101,9 @@ type browseListing struct { // If ≠0 then Items have been limited to that many elements. ItemsLimitedTo int + + // If ≠0 then Items starting from that many elements. + ItemOffset int } // Breadcrumbs returns l.Path where every element maps @@ -131,7 +134,7 @@ func (l browseListing) Breadcrumbs() []crumb { return result } -func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam string) { +func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam string, offsetParam string) { l.Sort = sortParam l.Order = orderParam @@ -159,8 +162,17 @@ func (l *browseListing) applySortAndLimit(sortParam, orderParam, limitParam stri } } + if offsetParam != "" { + offset, _ := strconv.Atoi(offsetParam) + if offset > 0 && offset <= len(l.Items) { + l.Items = l.Items[offset:] + l.ItemOffset = offset + } + } + if limitParam != "" { limit, _ := strconv.Atoi(limitParam) + if limit > 0 && limit <= len(l.Items) { l.Items = l.Items[:limit] l.ItemsLimitedTo = limit -- cgit v1.2.3