Rudimentary pagination for _changes
This commit is contained in:
parent
8b2e601a46
commit
94b3966e46
2 changed files with 27 additions and 2 deletions
|
@ -50,16 +50,35 @@ impl Resource for ChangesResource {
|
||||||
#[derive(BartDisplay)]
|
#[derive(BartDisplay)]
|
||||||
#[template="templates/changes.html"]
|
#[template="templates/changes.html"]
|
||||||
struct Template<'a> {
|
struct Template<'a> {
|
||||||
|
link_newer: Option<String>,
|
||||||
|
link_older: Option<String>,
|
||||||
changes: &'a [Row],
|
changes: &'a [Row],
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = self.state.get_article_revision_stubs(self.before, 30);
|
const PAGE_SIZE: i32 = 30;
|
||||||
|
|
||||||
|
let data = self.state.get_article_revision_stubs(self.before, PAGE_SIZE);
|
||||||
let head = self.head();
|
let head = self.head();
|
||||||
|
|
||||||
Box::new(data.join(head)
|
Box::new(data.join(head)
|
||||||
.and_then(move |(data, head)| {
|
.and_then(move |(data, head)| {
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
|
let link_newer = self.before.and_then(|_| {
|
||||||
|
data.first().and_then(|x| {
|
||||||
|
match x.sequence_number {
|
||||||
|
seq => Some(format!("?before={}", seq + PAGE_SIZE)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let link_older = data.last().and_then(|x| {
|
||||||
|
match x.sequence_number {
|
||||||
|
1 => None,
|
||||||
|
seq => Some(format!("?before={}", seq)),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let changes = &data.into_iter().map(|x| {
|
let changes = &data.into_iter().map(|x| {
|
||||||
Row {
|
Row {
|
||||||
_article_id: x.article_id,
|
_article_id: x.article_id,
|
||||||
|
@ -75,7 +94,11 @@ impl Resource for ChangesResource {
|
||||||
.with_body(Layout {
|
.with_body(Layout {
|
||||||
base: None, // Hmm, should perhaps accept `base` as argument
|
base: None, // Hmm, should perhaps accept `base` as argument
|
||||||
title: "Changes",
|
title: "Changes",
|
||||||
body: &Template { changes },
|
body: &Template {
|
||||||
|
link_newer,
|
||||||
|
link_older,
|
||||||
|
changes
|
||||||
|
},
|
||||||
style_css_checksum: StyleCss::checksum(),
|
style_css_checksum: StyleCss::checksum(),
|
||||||
}.to_string()))
|
}.to_string()))
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<article>
|
<article>
|
||||||
|
{{#link_newer}}<p><a href="{{.}}">Show more recent changes</a></p>{{/link_newer}}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Article</th>
|
<th>Article</th>
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
{{/changes}}
|
{{/changes}}
|
||||||
</table>
|
</table>
|
||||||
|
{{#link_older}}<p><a href="{{.}}">Show older changes</a></p>{{/link_older}}
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue