Add links to newest and oldest changes

This commit is contained in:
Magnus Hoff 2017-10-22 12:36:19 +02:00
parent d918d614b4
commit 6c36e3cb49
3 changed files with 42 additions and 12 deletions

View file

@ -140,6 +140,10 @@ img {
height: auto;
}
nav {
text-align: center;
}
/* Sticky footer */
html, body {

View file

@ -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<String>,
link_older: Option<String>,
newer: Option<NavLinks>,
older: Option<NavLinks>,
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(),

View file

@ -4,7 +4,10 @@
</header>
<article>
{{#link_newer}}<p><a rel="prev" href="{{.}}">Show more recent changes</a></p>{{/link_newer}}
{{#newer}}<nav><ul class="dense"
><li><a rel="prev" href="{{.more}}">More recent changes</a></li
><li><a rel="first" href="{{.end}}">Most recent changes</a></li
></ul></nav>{{/newer}}
<table>
<tr>
<th>Article</th>
@ -19,7 +22,10 @@
</tr>
{{/changes}}
</table>
{{#link_older}}<p><a rel="next" href="{{.}}">Show older changes</a></p>{{/link_older}}
{{#older}}<nav><ul class="dense"
><li><a rel="next" href="{{.more}}">Older changes</a></li
><li><a rel="last" href="{{.end}}">First changes</a></li
></ul></nav>{{/older}}
</article>
</div>