Date links in page header.
This commit is contained in:
parent
8131e3fd01
commit
d1f5044466
@ -7,11 +7,11 @@ header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
& > * {
|
||||
& > span {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
span {
|
||||
span.user {
|
||||
flex-grow: 5;
|
||||
padding-left: 1em;
|
||||
text-align: right;
|
||||
|
29
src/main.rs
29
src/main.rs
@ -30,6 +30,7 @@ use rustorm::query::{Query, Filter};
|
||||
use time::Duration;
|
||||
use nickel::status::StatusCode;
|
||||
use std::io::Read;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod models;
|
||||
use models::{Entity, Photo, PhotoQuery, Tag, Person, Place, query_for};
|
||||
@ -294,6 +295,9 @@ fn photo_details<'mw>(req: &mut Request,
|
||||
if req.authorized_user().is_some() || photo.is_public() {
|
||||
return render!(res, "templates/details.tpl", {
|
||||
user: Option<String> = req.authorized_user(),
|
||||
monthlink: HashMap<String, String> =
|
||||
photo.date.map(|d| month_link(d.year(), d.month() as u8))
|
||||
.unwrap_or_else(|| HashMap::new()),
|
||||
people: Vec<Person> =
|
||||
req.orm_get_related(&photo, "photo_person").unwrap(),
|
||||
places: Vec<Place> =
|
||||
@ -304,18 +308,9 @@ fn photo_details<'mw>(req: &mut Request,
|
||||
Some(d) => d.format("%T").to_string(),
|
||||
None => "".to_string()
|
||||
},
|
||||
year: i32 = match photo.date {
|
||||
Some(d) => d.year(),
|
||||
None => 0
|
||||
},
|
||||
month: u32 = match photo.date {
|
||||
Some(d) => d.month(),
|
||||
None => 0
|
||||
},
|
||||
day: u32 = match photo.date {
|
||||
Some(d) => d.day(),
|
||||
None => 0
|
||||
},
|
||||
year: Option<i32> = photo.date.map(|d| d.year()),
|
||||
month: Option<u32> = photo.date.map(|d| d.month()),
|
||||
day: Option<u32> = photo.date.map(|d| d.day()),
|
||||
photo: Photo = photo
|
||||
});
|
||||
}
|
||||
@ -400,6 +395,7 @@ fn days_in_month<'mw>(req: &mut Request,
|
||||
if let Ok(month) = req.param("month").unwrap().parse::<u8>() {
|
||||
return render!(res, "templates/groups.tpl", {
|
||||
user: Option<String> = req.authorized_user(),
|
||||
year: Option<i32> = Some(year),
|
||||
title: String = format!("Photos from {} {}", monthname(month),
|
||||
year),
|
||||
groups: Vec<Group> = query_for::<Photo>()
|
||||
@ -443,6 +439,8 @@ fn all_for_day<'mw>(req: &mut Request,
|
||||
let date = UTC.ymd(year, month as u32, day).and_hms(0, 0, 0);
|
||||
return render!(res, "templates/index.tpl", {
|
||||
user: Option<String> = req.authorized_user(),
|
||||
year: Option<i32> = Some(year),
|
||||
monthlink: HashMap<String, String> = month_link(year, month),
|
||||
title: String = format!("Photos from {} {} {}",
|
||||
day, monthname(month), year),
|
||||
photos: Vec<Photo> = query_for::<Photo>()
|
||||
@ -458,3 +456,10 @@ fn all_for_day<'mw>(req: &mut Request,
|
||||
}
|
||||
res.error(StatusCode::NotFound, "Not a day")
|
||||
}
|
||||
|
||||
fn month_link(year: i32, month: u8) -> HashMap<String, String> {
|
||||
let mut ml = HashMap::new();
|
||||
ml.insert("url".to_string(), format!("/{}/{}/", year, month));
|
||||
ml.insert("name".to_string(), format!("{}", month));
|
||||
ml
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
<header>
|
||||
<a href="/">/</a>
|
||||
· <a href="/tag/">Taggar</a>
|
||||
· <a href="/person/">Personer</a>
|
||||
· <a href="/place/">Platser</a>
|
||||
{{#user}}<span>{{.}}
|
||||
<span><a href="/">Bilder</a>
|
||||
{{#year}}/<a href="/{{.}}/">{{.}}</a>{{/year}}
|
||||
{{#monthlink}}- <a href="{{url}}">{{name}}</a>{{/monthlink}}
|
||||
</span>
|
||||
<span>· <a href="/tag/">Taggar</a></span>
|
||||
<span>· <a href="/person/">Personer</a></span>
|
||||
<span>· <a href="/place/">Platser</a></span>
|
||||
{{#user}}<span class="user">{{.}}
|
||||
(<a href="/logout">log out</a>)
|
||||
</span>{{/user}}
|
||||
{{^user}}<span>(<a href="/login">log in</a>)</span>{{/user}}
|
||||
{{^user}}<span class="user">(<a href="/login">log in</a>)</span>{{/user}}
|
||||
</header>
|
||||
|
Loading…
Reference in New Issue
Block a user