From 94b3966e467adf66ed4af955a4dbc10e0d985651 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Sun, 15 Oct 2017 23:15:12 +0200 Subject: [PATCH] Rudimentary pagination for _changes --- src/resources/changes_resource.rs | 27 +++++++++++++++++++++++++-- templates/changes.html | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index 50a2c5b..cbfa3f2 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -50,16 +50,35 @@ impl Resource for ChangesResource { #[derive(BartDisplay)] #[template="templates/changes.html"] struct Template<'a> { + link_newer: Option, + link_older: Option, 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())) })) diff --git a/templates/changes.html b/templates/changes.html index 04b5a0e..038cef8 100644 --- a/templates/changes.html +++ b/templates/changes.html @@ -4,6 +4,7 @@