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)]
|
||||
#[template="templates/changes.html"]
|
||||
struct Template<'a> {
|
||||
link_newer: Option<String>,
|
||||
link_older: Option<String>,
|
||||
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();
|
||||
|
||||
Box::new(data.join(head)
|
||||
.and_then(move |(data, head)| {
|
||||
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| {
|
||||
Row {
|
||||
_article_id: x.article_id,
|
||||
|
@ -75,7 +94,11 @@ impl Resource for ChangesResource {
|
|||
.with_body(Layout {
|
||||
base: None, // Hmm, should perhaps accept `base` as argument
|
||||
title: "Changes",
|
||||
body: &Template { changes },
|
||||
body: &Template {
|
||||
link_newer,
|
||||
link_older,
|
||||
changes
|
||||
},
|
||||
style_css_checksum: StyleCss::checksum(),
|
||||
}.to_string()))
|
||||
}))
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
</header>
|
||||
|
||||
<article>
|
||||
{{#link_newer}}<p><a href="{{.}}">Show more recent changes</a></p>{{/link_newer}}
|
||||
<table>
|
||||
<tr>
|
||||
<th>Article</th>
|
||||
|
@ -16,6 +17,7 @@
|
|||
</tr>
|
||||
{{/changes}}
|
||||
</table>
|
||||
{{#link_older}}<p><a href="{{.}}">Show older changes</a></p>{{/link_older}}
|
||||
</article>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue