From 6c36e3cb493cb47697cd33363c0218d7f0f74fa2 Mon Sep 17 00:00:00 2001 From: Magnus Hoff Date: Sun, 22 Oct 2017 12:36:19 +0200 Subject: [PATCH] Add links to newest and oldest changes --- assets/style.css | 4 ++++ src/resources/changes_resource.rs | 40 +++++++++++++++++++++++-------- templates/changes.html | 10 ++++++-- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/assets/style.css b/assets/style.css index 27d2c8a..613a3d8 100644 --- a/assets/style.css +++ b/assets/style.css @@ -140,6 +140,10 @@ img { height: auto; } +nav { + text-align: center; +} + /* Sticky footer */ html, body { diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index f8b464a..9d729a1 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -50,11 +50,16 @@ impl Resource for ChangesResource { _latest: bool, } + struct NavLinks { + more: String, + end: String, + } + #[derive(BartDisplay)] #[template="templates/changes.html"] struct Template<'a> { - link_newer: Option, - link_older: Option, + newer: Option, + older: Option, changes: &'a [Row], } @@ -92,21 +97,36 @@ impl Resource for ChangesResource { None }; - let (link_newer, link_older) = match self.pagination { + let (newer, older) = match self.pagination { Pagination::After(x) => { data.reverse(); ( - extra_element.map(|_| format!("?after={}", data.first().unwrap().sequence_number)), - Some(format!("?before={}", x + 1)) + extra_element.map(|_| NavLinks { + more: format!("?after={}", data.first().unwrap().sequence_number), + end: format!("_changes"), + }), + Some(NavLinks { + more: format!("?before={}", x + 1), + end: format!("?after=0"), + }) ) }, Pagination::Before(x) => ( - Some(format!("?after={}", x - 1)), - extra_element.map(|_| format!("?before={}", data.last().unwrap().sequence_number)), + Some(NavLinks { + more: format!("?after={}", x - 1), + end: format!("_changes"), + }), + extra_element.map(|_| NavLinks { + more: format!("?before={}", data.last().unwrap().sequence_number), + end: format!("?after=0"), + }) ), Pagination::None => ( None, - extra_element.map(|_| format!("?before={}", data.last().unwrap().sequence_number)), + extra_element.map(|_| NavLinks { + more: format!("?before={}", data.last().unwrap().sequence_number), + end: format!("?after=0"), + }), ), }; @@ -127,8 +147,8 @@ impl Resource for ChangesResource { base: None, // Hmm, should perhaps accept `base` as argument title: "Changes", body: &Template { - link_newer, - link_older, + newer, + older, changes }, style_css_checksum: StyleCss::checksum(), diff --git a/templates/changes.html b/templates/changes.html index 0f15518..4adabc1 100644 --- a/templates/changes.html +++ b/templates/changes.html @@ -4,7 +4,10 @@