From ee348c29cbd87f6480bddb0139316af25216596e Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 25 Oct 2023 10:20:14 -0400 Subject: [PATCH] Render the name and the uploaded date for each file in the gallery --- file-service/src/pages.rs | 33 ++++++++++++++++++++------------ file-service/templates/style.css | 4 ++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/file-service/src/pages.rs b/file-service/src/pages.rs index 18dd832..65997e3 100644 --- a/file-service/src/pages.rs +++ b/file-service/src/pages.rs @@ -1,6 +1,6 @@ use crate::html::*; use build_html::{self, Container, ContainerType, Html, HtmlContainer}; -use file_service::{FileHandle, FileId, ReadFileError}; +use file_service::{FileHandle, FileInfo, ReadFileError}; pub fn auth(_message: Option) -> build_html::HtmlPage { build_html::HtmlPage::new() @@ -49,14 +49,7 @@ pub fn gallery(handles: Vec>) -> build_html::H let mut gallery = Container::new(ContainerType::Div).with_attributes([("class", "gallery")]); for handle in handles { let container = match handle { - Ok(ref handle) => thumbnail(&handle.id).with_html( - Form::new() - .with_path(&format!("/{}", *handle.id)) - .with_method("post") - .with_html(Input::new("hidden", "_method").with_value("delete")) - .with_html(Button::new("Delete")), - ), - + Ok(ref handle) => thumbnail(&handle.info), Err(err) => Container::new(ContainerType::Div) .with_attributes(vec![("class", "file")]) .with_paragraph(format!("{:?}", err)), @@ -88,15 +81,31 @@ pub fn upload_form() -> Form { ) } -pub fn thumbnail(id: &FileId) -> Container { +pub fn thumbnail(info: &FileInfo) -> Container { Container::new(ContainerType::Div) .with_attributes(vec![("class", "card thumbnail")]) .with_html( Container::new(ContainerType::Div).with_link( - format!("/{}", **id), - Image::new(&format!("{}/tn", **id)) + format!("/{}", *info.id), + Image::new(&format!("{}/tn", *info.id)) .with_attributes([("class", "thumbnail__image")]) .to_html_string(), ), ) + .with_html( + Container::new(ContainerType::Div) + .with_html( + UnorderedList::new() + .with_attributes(vec![("class", "thumbnail__metadata")]) + .with_html(info.name.clone()) + .with_html(format!("{}", info.created.format("%Y-%m-%d"))), + ) + .with_html( + Form::new() + .with_path(&format!("/{}", *info.id)) + .with_method("post") + .with_html(Input::new("hidden", "_method").with_value("delete")) + .with_html(Button::new("Delete")), + ), + ) } diff --git a/file-service/templates/style.css b/file-service/templates/style.css index ae81cdf..a423bbf 100644 --- a/file-service/templates/style.css +++ b/file-service/templates/style.css @@ -77,6 +77,10 @@ body { border: none; } +.thumbnail__metadata { + list-style: none; +} + /* [type="submit"] { border-radius: 1em;