diff options
author | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-02-25 19:22:58 +0000 |
---|---|---|
committer | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-02-25 19:22:58 +0000 |
commit | 6e95f942f1ae6c9c120c95eeb8b1aae1379bcd54 (patch) | |
tree | f7f742418ebc0b64a821a5204abe5889343ab751 /src/renderer.rs | |
parent | Use rust nightly (diff) | |
download | miniserve-6e95f942f1ae6c9c120c95eeb8b1aae1379bcd54.tar.gz miniserve-6e95f942f1ae6c9c120c95eeb8b1aae1379bcd54.zip |
Removed sorting from CLI + added sorting from HTML
Diffstat (limited to 'src/renderer.rs')
-rw-r--r-- | src/renderer.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 82937ab..2f25cad 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -11,6 +11,8 @@ pub fn page( entries: Vec<listing::Entry>, is_root: bool, page_parent: Option<String>, + sort_method: Option<listing::SortingMethod>, + sort_order: Option<listing::SortingOrder>, ) -> Markup { html! { (page_header(page_title)) @@ -18,9 +20,9 @@ pub fn page( h1 { (page_title) } table { thead { - th { "Name" } - th { "Size" } - th { "Last modification" } + th { (build_link("name", "Name", &sort_method, &sort_order)) } + th { (build_link("size", "Size", &sort_method, &sort_order)) } + th { (build_link("date", "Last modification", &sort_method, &sort_order)) } } tbody { @if !is_root { @@ -43,6 +45,32 @@ pub fn page( } } +/// Partial: table header link +fn build_link( + name: &str, + title: &str, + sort_method: &Option<listing::SortingMethod>, + sort_order: &Option<listing::SortingOrder>, +) -> Markup { + let mut link = format!("?sort={}&order=asc", name); + let mut help = format!("Sort by {} in ascending order", name); + + if let Some(method) = sort_method { + if method.to_string() == name { + if let Some(order) = sort_order { + if order.to_string() == "asc" { + link = format!("?sort={}&order=desc", name); + help = format!("Sort by {} in descending order", name); + } + } + } + }; + + html! { + a href=(link) title=(help) { (title) } + } +} + /// Partial: page header fn page_header(page_title: &str) -> Markup { html! { |