From 3fb3139d28e0dc5957855bc5a9215beaf8f08732 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Tue, 24 Oct 2017 12:27:39 +0200 Subject: [PATCH] Tweak links to _changes feed --- src/resources/article_revision_resource.rs | 3 ++- src/resources/changes_resource.rs | 19 +++++++++++++++---- templates/changes.html | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/resources/article_revision_resource.rs b/src/resources/article_revision_resource.rs index bc12f48..70a70c9 100644 --- a/src/resources/article_revision_resource.rs +++ b/src/resources/article_revision_resource.rs @@ -38,7 +38,7 @@ pub fn timestamp_and_author(sequence_number: i32, article_id: i32, created: &Dat author: Option>, } - let pagination = Pagination::Before(sequence_number + 1); + let pagination = Pagination::After(sequence_number - 1); Template { created: &created.to_rfc2822(), @@ -53,6 +53,7 @@ pub fn timestamp_and_author(sequence_number: i32, article_id: i32, created: &Dat history: format!("_changes{}", QueryParameters::default() .pagination(pagination) + .article_id(Some(article_id)) .author(Some(author.to_owned())) .into_link() ), diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index 8a6043c..18787da 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -202,8 +202,9 @@ impl Resource for ChangesResource { fn get(self: Box) -> ResponseFuture { use chrono::{TimeZone, Local}; - struct Row { - sequence_number_plus_one: i32, + struct Row<'a> { + resource: &'a ChangesResource, + sequence_number: i32, article_id: i32, revision: i32, @@ -216,6 +217,15 @@ impl Resource for ChangesResource { _latest: bool, } + impl<'a> Row<'a> { + fn author_link(&self) -> String { + self.resource.query_args() + .pagination(Pagination::After(self.sequence_number)) + .author(self.author.clone()) + .into_link() + } + } + struct NavLinks { more: String, end: String, @@ -226,7 +236,7 @@ impl Resource for ChangesResource { struct Template<'a> { newer: Option, older: Option, - changes: &'a [Row], + changes: &'a [Row<'a>], } let (before, article_id, author, limit) = @@ -281,7 +291,8 @@ impl Resource for ChangesResource { let changes = &data.into_iter().map(|x| { Row { - sequence_number_plus_one: x.sequence_number + 1, + resource: &self, + sequence_number: x.sequence_number, article_id: x.article_id, revision: x.revision, created: Local.from_utc_datetime(&x.created).to_rfc2822(), diff --git a/templates/changes.html b/templates/changes.html index 317e5f6..1aebf1e 100644 --- a/templates/changes.html +++ b/templates/changes.html @@ -20,7 +20,7 @@ {{.title}} {{.created}} - {{#.author}}{{.}}{{/.author}}{{^.author}}Anonymous{{/.author}} + {{#.author}}{{.}}{{/.author}}{{^.author}}Anonymous{{/.author}} {{/changes}}