use crate::{ html::*, store::{FileHandle, FileId, ReadFileError}, }; use build_html::{self, Container, ContainerType, Html, HtmlContainer}; pub fn index(handles: Vec>) -> build_html::HtmlPage { let mut page = build_html::HtmlPage::new() .with_title("Admin list of files") .with_header(1, "Admin list of files") .with_html( Form::new() .with_method("post") .with_encoding("multipart/form-data") .with_container( Container::new(ContainerType::Div) .with_html(Input::new("file", "file")) .with_html(Label::new("for-selector-input", "Select a file")), ) .with_html(Button::new("Upload file")), ); 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")), ), Err(err) => Container::new(ContainerType::Div) .with_attributes(vec![("class", "file")]) .with_paragraph(format!("{:?}", err)), }; page.add_container(container) } page } pub fn thumbnail(id: &FileId) -> Container { let mut container = Container::new(ContainerType::Div).with_attributes(vec![("class", "file")]); let tn = Container::new(ContainerType::Div) .with_attributes(vec![("class", "thumbnail")]) .with_link( format!("/{}", **id), Image::new(&format!("{}/tn", **id)).to_html_string(), ); container.add_html(tn); container }