parent
144f5966dd
commit
fcbaf6eee3
@ -29,13 +29,11 @@ pub struct SearchQuery {
|
|||||||
macro_rules! param_to_query {
|
macro_rules! param_to_query {
|
||||||
( $query:ident, $parsed_query:ident; normal: $($field:ident),*; date: $($date:ident),*) => {
|
( $query:ident, $parsed_query:ident; normal: $($field:ident),*; date: $($date:ident),*) => {
|
||||||
$(
|
$(
|
||||||
if let Some(ref field) = $query.$field {
|
let mut rest = $query.$field.as_ref().map(String::as_str).unwrap_or_default();
|
||||||
let mut rest = field.as_str();
|
while !rest.is_empty() {
|
||||||
while !rest.is_empty() {
|
let (token, r) = Query::get_first_token(rest);
|
||||||
let (token, r) = Query::get_first_token(rest);
|
rest = r;
|
||||||
rest = r;
|
$parsed_query.$field(token, None);
|
||||||
$parsed_query.$field(token, None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
$(
|
$(
|
||||||
|
@ -75,18 +75,36 @@ pub fn tabs(links: &[(&str, &str, bool)]) -> Html<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn paginate(catalog: &Catalog, page: i32, total: i32) -> Html<String> {
|
pub fn paginate(catalog: &Catalog, page: i32, total: i32) -> Html<String> {
|
||||||
|
paginate_param(catalog, page, total, None)
|
||||||
|
}
|
||||||
|
pub fn paginate_param(catalog: &Catalog, page: i32, total: i32, param: Option<String>) -> Html<String> {
|
||||||
let mut res = String::new();
|
let mut res = String::new();
|
||||||
|
let param = param.map(|mut p| {p.push('&'); p}).unwrap_or_default();
|
||||||
res.push_str(r#"<div class="pagination">"#);
|
res.push_str(r#"<div class="pagination">"#);
|
||||||
if page != 1 {
|
if page != 1 {
|
||||||
res.push_str(format!(r#"<a href="?page={}">{}</a>"#, page - 1, catalog.gettext("Previous page")).as_str());
|
res.push_str(format!(r#"<a href="?{}page={}">{}</a>"#, param, page - 1, catalog.gettext("Previous page")).as_str());
|
||||||
}
|
}
|
||||||
if page < total {
|
if page < total {
|
||||||
res.push_str(format!(r#"<a href="?page={}">{}</a>"#, page + 1, catalog.gettext("Next page")).as_str());
|
res.push_str(format!(r#"<a href="?{}page={}">{}</a>"#, param, page + 1, catalog.gettext("Next page")).as_str());
|
||||||
}
|
}
|
||||||
res.push_str("</div>");
|
res.push_str("</div>");
|
||||||
Html(res)
|
Html(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn encode_query_param(param: &str) -> String {
|
||||||
|
param.chars().map(|c| match c {
|
||||||
|
'+' => Ok("%2B"),
|
||||||
|
' ' => Err('+'),
|
||||||
|
c => Err(c),
|
||||||
|
}).fold(String::new(), |mut s,r| {
|
||||||
|
match r {
|
||||||
|
Ok(r) => s.push_str(r),
|
||||||
|
Err(r) => s.push(r),
|
||||||
|
};
|
||||||
|
s
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! icon {
|
macro_rules! icon {
|
||||||
($name:expr) => {
|
($name:expr) => {
|
||||||
|
@ -23,5 +23,5 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@paginate(ctx.1, page, n_pages)
|
@paginate_param(ctx.1, page, n_pages, Some(format!("q={}", encode_query_param(query_str))))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user