Add links in footer to article and author history
This commit is contained in:
parent
d7d555d4d5
commit
f097313e53
4 changed files with 26 additions and 11 deletions
|
@ -13,6 +13,8 @@ use site::Layout;
|
|||
use state::State;
|
||||
use web::{Resource, ResponseFuture};
|
||||
|
||||
use super::changes_resource::QueryParameters;
|
||||
|
||||
pub struct ArticleResource {
|
||||
state: State,
|
||||
article_id: i32,
|
||||
|
@ -26,17 +28,27 @@ impl ArticleResource {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn last_updated(created: &DateTime<Local>, author: Option<&str>) -> String {
|
||||
pub fn last_updated(article_id: i32, created: &DateTime<Local>, author: Option<&str>) -> String {
|
||||
struct Author<'a> {
|
||||
author: &'a str,
|
||||
history: String,
|
||||
}
|
||||
|
||||
#[derive(BartDisplay)]
|
||||
#[template_string = "Last updated {{created}}{{#author}} by {{.}}{{/author}}"]
|
||||
#[template_string = "Last updated <a href=\"{{article_history}}\">{{created}}</a>{{#author}} by <a href=\"{{.history}}\">{{.author}}</a>{{/author}}"]
|
||||
struct Template<'a> {
|
||||
created: &'a str,
|
||||
author: Option<&'a str>,
|
||||
article_history: &'a str,
|
||||
author: Option<Author<'a>>,
|
||||
}
|
||||
|
||||
Template {
|
||||
created: &created.to_rfc2822(),
|
||||
author
|
||||
article_history: &format!("_changes{}", QueryParameters::default().article_id(Some(article_id)).into_link()),
|
||||
author: author.map(|author| Author {
|
||||
author: &author,
|
||||
history: format!("_changes{}", QueryParameters::default().author(Some(author.to_owned())).into_link()),
|
||||
}),
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
|
@ -82,6 +94,7 @@ impl Resource for ArticleResource {
|
|||
body: &Template {
|
||||
revision: data.revision,
|
||||
last_updated: Some(&last_updated(
|
||||
data.article_id,
|
||||
&Local.from_utc_datetime(&data.created),
|
||||
data.author.as_ref().map(|x| &**x)
|
||||
)),
|
||||
|
@ -148,6 +161,7 @@ impl Resource for ArticleResource {
|
|||
rendered: render_markdown(&updated.body),
|
||||
}.to_string(),
|
||||
last_updated: &last_updated(
|
||||
updated.article_id,
|
||||
&Local.from_utc_datetime(&updated.created),
|
||||
updated.author.as_ref().map(|x| &**x)
|
||||
),
|
||||
|
|
|
@ -26,7 +26,7 @@ pub struct ChangesLookup {
|
|||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct QueryParameters {
|
||||
pub struct QueryParameters {
|
||||
after: Option<i32>,
|
||||
before: Option<i32>,
|
||||
|
||||
|
@ -37,7 +37,7 @@ struct QueryParameters {
|
|||
}
|
||||
|
||||
impl QueryParameters {
|
||||
fn pagination(self, pagination: Pagination<i32>) -> Self {
|
||||
pub fn pagination(self, pagination: Pagination<i32>) -> Self {
|
||||
Self {
|
||||
after: if let Pagination::After(x) = pagination { Some(x) } else { None },
|
||||
before: if let Pagination::Before(x) = pagination { Some(x) } else { None },
|
||||
|
@ -45,22 +45,22 @@ impl QueryParameters {
|
|||
}
|
||||
}
|
||||
|
||||
fn article_id(self, article_id: Option<i32>) -> Self {
|
||||
pub fn article_id(self, article_id: Option<i32>) -> Self {
|
||||
Self { article_id, ..self }
|
||||
}
|
||||
|
||||
fn author(self, author: Option<String>) -> Self {
|
||||
pub fn author(self, author: Option<String>) -> Self {
|
||||
Self { author, ..self }
|
||||
}
|
||||
|
||||
fn limit(self, limit: i32) -> Self {
|
||||
pub fn limit(self, limit: i32) -> Self {
|
||||
Self {
|
||||
limit: if limit != DEFAULT_LIMIT { Some(limit) } else { None },
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
fn into_link(self) -> String {
|
||||
pub fn into_link(self) -> String {
|
||||
let args = serde_urlencoded::to_string(self).expect("Serializing to String cannot fail");
|
||||
if args.len() > 0 {
|
||||
format!("?{}", args)
|
||||
|
|
|
@ -150,6 +150,7 @@ impl Resource for NewArticleResource {
|
|||
rendered: render_markdown(&updated.body),
|
||||
}.to_string(),
|
||||
last_updated: &super::article_resource::last_updated(
|
||||
updated.article_id,
|
||||
&Local.from_utc_datetime(&updated.created),
|
||||
updated.author.as_ref().map(|x| &**x)
|
||||
),
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
<footer>
|
||||
<ul class="dense"
|
||||
><li class="last-updated {{^last_updated}}missing{{/last_updated}}">{{#last_updated}}{{.}}{{/last_updated}}</li
|
||||
><li class="last-updated {{^last_updated}}missing{{/last_updated}}">{{#last_updated}}{{{.}}}{{/last_updated}}</li
|
||||
><li><a id="openEditor" href="?edit">Edit</a></li
|
||||
></ul>
|
||||
{{>footer/items.html}}
|
||||
|
|
Loading…
Reference in a new issue