Tweak links to _changes feed

This commit is contained in:
Magnus Hoff 2017-10-24 12:27:39 +02:00
parent de413f69bf
commit 3fb3139d28
3 changed files with 18 additions and 6 deletions

View file

@ -38,7 +38,7 @@ pub fn timestamp_and_author(sequence_number: i32, article_id: i32, created: &Dat
author: Option<Author<'a>>, author: Option<Author<'a>>,
} }
let pagination = Pagination::Before(sequence_number + 1); let pagination = Pagination::After(sequence_number - 1);
Template { Template {
created: &created.to_rfc2822(), created: &created.to_rfc2822(),
@ -53,6 +53,7 @@ pub fn timestamp_and_author(sequence_number: i32, article_id: i32, created: &Dat
history: format!("_changes{}", history: format!("_changes{}",
QueryParameters::default() QueryParameters::default()
.pagination(pagination) .pagination(pagination)
.article_id(Some(article_id))
.author(Some(author.to_owned())) .author(Some(author.to_owned()))
.into_link() .into_link()
), ),

View file

@ -202,8 +202,9 @@ impl Resource for ChangesResource {
fn get(self: Box<Self>) -> ResponseFuture { fn get(self: Box<Self>) -> ResponseFuture {
use chrono::{TimeZone, Local}; use chrono::{TimeZone, Local};
struct Row { struct Row<'a> {
sequence_number_plus_one: i32, resource: &'a ChangesResource,
sequence_number: i32,
article_id: i32, article_id: i32,
revision: i32, revision: i32,
@ -216,6 +217,15 @@ impl Resource for ChangesResource {
_latest: bool, _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 { struct NavLinks {
more: String, more: String,
end: String, end: String,
@ -226,7 +236,7 @@ impl Resource for ChangesResource {
struct Template<'a> { struct Template<'a> {
newer: Option<NavLinks>, newer: Option<NavLinks>,
older: Option<NavLinks>, older: Option<NavLinks>,
changes: &'a [Row], changes: &'a [Row<'a>],
} }
let (before, article_id, author, limit) = let (before, article_id, author, limit) =
@ -281,7 +291,8 @@ impl Resource for ChangesResource {
let changes = &data.into_iter().map(|x| { let changes = &data.into_iter().map(|x| {
Row { Row {
sequence_number_plus_one: x.sequence_number + 1, resource: &self,
sequence_number: x.sequence_number,
article_id: x.article_id, article_id: x.article_id,
revision: x.revision, revision: x.revision,
created: Local.from_utc_datetime(&x.created).to_rfc2822(), created: Local.from_utc_datetime(&x.created).to_rfc2822(),

View file

@ -20,7 +20,7 @@
<tr> <tr>
<td><a href="_revisions/{{.article_id}}/{{.revision}}">{{.title}}</a></td> <td><a href="_revisions/{{.article_id}}/{{.revision}}">{{.title}}</a></td>
<td>{{.created}}</td> <td>{{.created}}</td>
<td>{{#.author}}<a href="_changes?before={{..sequence_number_plus_one}}&amp;author={{.}}">{{.}}</a>{{/.author}}{{^.author}}<i>Anonymous</i>{{/.author}}</td> <td>{{#.author}}<a href="{{..author_link()}}">{{.}}</a>{{/.author}}{{^.author}}<i>Anonymous</i>{{/.author}}</td>
</tr> </tr>
{{/changes}} {{/changes}}
</table> </table>