-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from f3l/add_pagination
Add pagination for cites view.
- Loading branch information
Showing
12 changed files
with
288 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
extends ./layout | ||
|
||
block content | ||
- import citesystem.rest : FullCiteData; | ||
p#desc. | ||
F3L-Zitate Seite #{paginationInfo.currentPage}/#{paginationInfo.lastPage} – #[a(href="/all") Alle anzeigen] | ||
div#citebody | ||
- foreach(FullCiteData cite; cites) | ||
include rendercite | ||
include pagination_footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
div.pagination_footer | ||
- if (paginationInfo.needsPreviousPage) | ||
a.pagination.pagination_first(href="/all_paginated?page=1&pagesize=#{paginationInfo.pagesize}") « | ||
a.pagination.pagination_previous(href="/all_paginated?page=#{paginationInfo.currentPage - 1}&pagesize=#{paginationInfo.pagesize}") ‹ | ||
- if (paginationInfo.needsFrontTruncation) | ||
a.pagination.pagination_truncation … | ||
- foreach(ulong mark; paginationInfo.pagesToShow) | ||
- if (mark == paginationInfo.currentPage) | ||
a.pagination_mark.pagination.pagination_current #{mark} | ||
- else | ||
a.pagination.pagination_mark(href="/all_paginated?page=#{mark}&pagesize=#{paginationInfo.pagesize}") #{mark} | ||
- if (paginationInfo.needsBackTruncation) | ||
a.pagination.pagination_truncation … | ||
- if (paginationInfo.needsNextPage) | ||
a.pagination.pagination_next(href="/all_paginated?page=#{paginationInfo.currentPage + 1}&pagesize=#{paginationInfo.pagesize}") › | ||
a.pagination.pagination_last(href="/all_paginated?pagesize=#{paginationInfo.pagesize}&page=#{paginationInfo.lastPage}") » |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module citesystem.server.paginationinfo; | ||
|
||
private import diet.dom : Node; | ||
|
||
public struct PaginationInfo { | ||
const size_t pagesize; | ||
const size_t currentPage; | ||
const size_t numberOfElements; | ||
|
||
this(size_t page, size_t pagesize,size_t count) { | ||
this.currentPage = page; | ||
this.pagesize = pagesize; | ||
this.numberOfElements = count; | ||
} | ||
|
||
@property | ||
size_t lastPage() const { | ||
auto numberOfFullPages = numberOfElements / pagesize; | ||
if (numberOfFullPages % pagesize == 0) { | ||
return numberOfFullPages + 1; | ||
} else { | ||
return numberOfFullPages; | ||
} | ||
} | ||
|
||
@property | ||
size_t[] pagesToShow() const { | ||
import std.range : iota; | ||
import std.array : array; | ||
|
||
auto firstPageLabel = firstPageLabel(); | ||
// assert(firstPageLabel > 0); | ||
auto lastPageLabel = lastPageLabel(); | ||
// assert(lastPageLabel <= lastPage); | ||
return iota(firstPageLabel, lastPageLabel + 1).array(); | ||
} | ||
|
||
private ulong firstPageLabel() const { | ||
return (currentPage > 3) ? currentPage - 3 : 1; | ||
} | ||
|
||
private ulong lastPageLabel() const { | ||
import std.algorithm.comparison : min; | ||
return min(currentPage + 3, lastPage); | ||
} | ||
|
||
@property | ||
size_t firstCiteOffset() const { | ||
return (pagesize * (currentPage - 1)); | ||
} | ||
|
||
@property | ||
size_t lastCite() const { | ||
import std.algorithm.comparison : min; | ||
return min( | ||
pagesize * currentPage, | ||
numberOfElements | ||
); | ||
} | ||
|
||
@property | ||
Node[] allMarks() const { | ||
import diet.parser : parseDietRaw, identity; | ||
import diet.input : InputFile; | ||
InputFile inputFile = InputFile("pageinationInfo-footer", q{a(href="https://pheerai.de/") HP}); | ||
|
||
return parseDietRaw!identity(inputFile); | ||
} | ||
|
||
@property | ||
bool needsFrontTruncation() const { | ||
return firstPageLabel != 1; | ||
} | ||
|
||
@property | ||
bool needsBackTruncation() const { | ||
return lastPageLabel != lastPage; | ||
} | ||
|
||
@property | ||
bool needsNextPage() const { | ||
return currentPage != lastPage; | ||
} | ||
|
||
@property | ||
bool needsPreviousPage() const { | ||
return currentPage != 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.