monorepo/file-service/src/pages.rs

41 lines
1.5 KiB
Rust
Raw Normal View History

use crate::{html::*, File, FileError};
2023-09-21 03:31:52 +00:00
use build_html::{self, Container, ContainerType, Html, HtmlContainer};
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)
.with_html(Input::new("file", "file", "file-selector-input"))
.with_html(Label::new("for-selector-input", "Select a file")),
)
.with_html(Button::new("upload", "Upload file")),
);
for file in files {
let mut container =
Container::new(ContainerType::Div).with_attributes(vec![("class", "file")]);
match file {
Ok(file) => {
let tn = Container::new(ContainerType::Div)
.with_attributes(vec![("class", "thumbnail")])
.with_link(
2023-09-21 04:00:09 +00:00
format!("/{}", file.info().id),
2023-09-21 03:31:52 +00:00
Image::new(&format!("{}/tn", file.info().id)).to_html_string(),
);
container.add_html(tn);
}
Err(err) => {
container.add_paragraph(format!("{:?}", err));
}
}
page.add_container(container);
}
page
}