2023-09-21 03:06:34 +00:00
|
|
|
use crate::{html::*, File, FileError};
|
2023-09-21 03:31:52 +00:00
|
|
|
use build_html::{self, Container, ContainerType, Html, HtmlContainer};
|
2023-09-21 03:06:34 +00:00
|
|
|
|
|
|
|
pub fn index(files: Vec<Result<File, FileError>>) -> 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)
|
2023-09-22 04:38:26 +00:00
|
|
|
.with_html(Input::new("file", "file"))
|
2023-09-21 03:06:34 +00:00
|
|
|
.with_html(Label::new("for-selector-input", "Select a file")),
|
|
|
|
)
|
2023-09-22 04:38:26 +00:00
|
|
|
.with_html(Button::new("Upload file")),
|
2023-09-21 03:06:34 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
for file in files {
|
2023-09-22 04:38:26 +00:00
|
|
|
let container = match file {
|
|
|
|
Ok(ref file) => thumbnail(file).with_html(
|
|
|
|
Form::new()
|
|
|
|
.with_path(&format!("/{}", file.info().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)
|
2023-09-21 03:06:34 +00:00
|
|
|
}
|
|
|
|
page
|
|
|
|
}
|
2023-09-22 04:38:26 +00:00
|
|
|
|
|
|
|
pub fn thumbnail(file: &File) -> 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!("/{}", file.info().id),
|
|
|
|
Image::new(&format!("{}/tn", file.info().id)).to_html_string(),
|
|
|
|
);
|
|
|
|
container.add_html(tn);
|
|
|
|
container
|
|
|
|
}
|