Minor cleanup.

This commit is contained in:
Rasmus Kaj 2020-10-26 22:17:08 +01:00
parent 1f53860403
commit 3a64008980
4 changed files with 27 additions and 23 deletions

View File

@ -16,7 +16,6 @@ pub use self::context::{Context, ContextFilter};
pub use self::photolink::PhotoLink;
use self::render_ructe::BuilderExt;
use self::search::*;
use self::splitlist::*;
use self::views_by_category::*;
use self::views_by_date::*;
use super::{CacheOpt, DbOpt, DirOpt};

View File

@ -1,5 +1,5 @@
use super::RenderRucte;
use super::{links_by_time, Context, ImgRange};
use super::splitlist::links_by_time;
use super::{Context, ImgRange, RenderRucte};
use crate::adm::result::Error;
use crate::models::{Facet, Person, Photo, Place, Tag};
use crate::schema::photo_people::dsl as pp;

View File

@ -30,27 +30,32 @@ pub fn links_by_time<'a>(
.load(&c)
.unwrap();
(
if let Some(groups) = split_to_groups(&photos) {
let path = context.path_without_query();
groups
.iter()
.map(|g| PhotoLink::for_group(g, path, with_date))
.collect()
} else {
photos
.iter()
.map(if with_date {
PhotoLink::date_title
} else {
PhotoLink::no_title
})
.collect()
},
split_to_group_links(&photos, context.path_without_query(), with_date),
get_positions(&photos, &c),
)
}
pub fn get_positions(photos: &[Photo], c: &PgConnection) -> Vec<(Coord, i32)> {
fn split_to_group_links(
photos: &[Photo],
path: &str,
with_date: bool,
) -> Vec<PhotoLink> {
if let Some(groups) = split_to_groups(&photos) {
groups
.iter()
.map(|g| PhotoLink::for_group(g, path, with_date))
.collect()
} else {
let make_link = if with_date {
PhotoLink::date_title
} else {
PhotoLink::no_title
};
photos.iter().map(make_link).collect()
}
}
fn get_positions(photos: &[Photo], c: &PgConnection) -> Vec<(Coord, i32)> {
use crate::schema::positions::dsl::*;
positions
.filter(photo_id.eq_any(photos.iter().map(|p| p.id)))
@ -63,7 +68,7 @@ pub fn get_positions(photos: &[Photo], c: &PgConnection) -> Vec<(Coord, i32)> {
.collect()
}
pub fn split_to_groups(photos: &[Photo]) -> Option<Vec<&[Photo]>> {
fn split_to_groups(photos: &[Photo]) -> Option<Vec<&[Photo]>> {
let wanted_groups = match photos.len() {
l if l <= 18 => return None,
l if l < 120 => 10,

View File

@ -1,6 +1,6 @@
//! Handle photos by tag, person, or place.
use super::RenderRucte;
use super::{links_by_time, not_found, Context, ContextFilter, ImgRange};
use super::splitlist::links_by_time;
use super::{not_found, Context, ContextFilter, ImgRange, RenderRucte};
use crate::models::{Person, Photo, Place, Tag};
use crate::templates;
use diesel::prelude::*;