2023-10-03 20:18:19 +00:00
|
|
|
use crate::html::*;
|
2023-09-21 03:31:52 +00:00
|
|
|
use build_html::{self, Container, ContainerType, Html, HtmlContainer};
|
2023-10-25 14:20:14 +00:00
|
|
|
use file_service::{FileHandle, FileInfo, ReadFileError};
|
2023-09-21 03:06:34 +00:00
|
|
|
|
2023-10-03 15:10:37 +00:00
|
|
|
pub fn auth(_message: Option<String>) -> build_html::HtmlPage {
|
|
|
|
build_html::HtmlPage::new()
|
2023-10-26 04:03:39 +00:00
|
|
|
.with_title("Sign In")
|
2023-10-06 23:04:31 +00:00
|
|
|
.with_stylesheet("/css")
|
|
|
|
.with_container(
|
|
|
|
Container::new(ContainerType::Div)
|
|
|
|
.with_attributes([("class", "authentication-page")])
|
2023-10-26 04:03:39 +00:00
|
|
|
.with_container(auth_form()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn auth_form() -> Container {
|
|
|
|
Container::default()
|
|
|
|
.with_attributes([("class", "card authentication-form")])
|
|
|
|
.with_html(
|
|
|
|
Form::new()
|
|
|
|
.with_path("/auth")
|
|
|
|
.with_method("post")
|
2023-10-03 15:10:37 +00:00
|
|
|
.with_container(
|
|
|
|
Container::new(ContainerType::Div)
|
2023-10-06 23:04:31 +00:00
|
|
|
.with_html(
|
2023-10-26 04:03:39 +00:00
|
|
|
Input::new("password", "password")
|
|
|
|
.with_id("for-token-input")
|
|
|
|
.with_attributes([
|
|
|
|
("size", "50"),
|
|
|
|
("class", "authentication-form__input"),
|
|
|
|
]),
|
|
|
|
)
|
|
|
|
.with_html(
|
|
|
|
Button::new("Sign In")
|
|
|
|
.with_attributes([("class", "authentication-form__button")]),
|
2023-10-06 23:04:31 +00:00
|
|
|
),
|
2023-10-03 15:10:37 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gallery(handles: Vec<Result<FileHandle, ReadFileError>>) -> build_html::HtmlPage {
|
2023-09-21 03:06:34 +00:00
|
|
|
let mut page = build_html::HtmlPage::new()
|
2023-10-07 00:36:27 +00:00
|
|
|
.with_title("Gallery")
|
2023-10-06 23:04:31 +00:00
|
|
|
.with_stylesheet("/css")
|
2023-10-07 00:36:27 +00:00
|
|
|
.with_container(
|
|
|
|
Container::new(ContainerType::Div)
|
|
|
|
.with_attributes([("class", "gallery-page")])
|
|
|
|
.with_header(1, "Gallery")
|
2023-10-07 01:04:27 +00:00
|
|
|
.with_html(upload_form()),
|
2023-09-21 03:06:34 +00:00
|
|
|
);
|
|
|
|
|
2023-10-07 00:36:27 +00:00
|
|
|
let mut gallery = Container::new(ContainerType::Div).with_attributes([("class", "gallery")]);
|
2023-09-24 16:08:09 +00:00
|
|
|
for handle in handles {
|
|
|
|
let container = match handle {
|
2023-10-25 14:20:14 +00:00
|
|
|
Ok(ref handle) => thumbnail(&handle.info),
|
2023-09-22 04:38:26 +00:00
|
|
|
Err(err) => Container::new(ContainerType::Div)
|
|
|
|
.with_attributes(vec![("class", "file")])
|
|
|
|
.with_paragraph(format!("{:?}", err)),
|
|
|
|
};
|
2023-10-07 00:36:27 +00:00
|
|
|
gallery.add_container(container);
|
2023-09-21 03:06:34 +00:00
|
|
|
}
|
2023-10-07 00:36:27 +00:00
|
|
|
page.add_container(gallery);
|
2023-09-21 03:06:34 +00:00
|
|
|
page
|
|
|
|
}
|
2023-09-22 04:38:26 +00:00
|
|
|
|
2023-10-07 01:04:27 +00:00
|
|
|
pub fn upload_form() -> Form {
|
|
|
|
Form::new()
|
|
|
|
.with_path("/upload")
|
|
|
|
.with_method("post")
|
|
|
|
.with_encoding("multipart/form-data")
|
|
|
|
.with_container(
|
|
|
|
Container::new(ContainerType::Div)
|
|
|
|
.with_attributes([("class", "card upload-form")])
|
2023-10-07 03:51:41 +00:00
|
|
|
.with_html(Input::new("file", "file").with_attributes([
|
|
|
|
("id", "for-selector-input"),
|
|
|
|
("placeholder", "select file"),
|
|
|
|
("class", "upload-form__selector"),
|
|
|
|
]))
|
|
|
|
.with_html(
|
|
|
|
Button::new("Upload file")
|
|
|
|
.with_attributes([("class", "upload-form__button")])
|
|
|
|
.with_type("submit"),
|
|
|
|
),
|
2023-10-07 01:04:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-10-25 14:20:14 +00:00
|
|
|
pub fn thumbnail(info: &FileInfo) -> Container {
|
2023-10-07 01:04:27 +00:00
|
|
|
Container::new(ContainerType::Div)
|
|
|
|
.with_attributes(vec![("class", "card thumbnail")])
|
|
|
|
.with_html(
|
|
|
|
Container::new(ContainerType::Div).with_link(
|
2023-10-25 14:20:14 +00:00
|
|
|
format!("/{}", *info.id),
|
2023-10-26 03:24:41 +00:00
|
|
|
Container::default()
|
|
|
|
.with_attributes([("class", "thumbnail")])
|
2023-10-26 04:19:13 +00:00
|
|
|
.with_image(format!("{}/tn", *info.id), "test data")
|
2023-10-07 01:04:27 +00:00
|
|
|
.to_html_string(),
|
|
|
|
),
|
|
|
|
)
|
2023-10-25 14:20:14 +00:00
|
|
|
.with_html(
|
|
|
|
Container::new(ContainerType::Div)
|
|
|
|
.with_html(
|
2023-10-26 03:08:02 +00:00
|
|
|
Container::new(ContainerType::UnorderedList)
|
2023-10-25 14:20:14 +00:00
|
|
|
.with_attributes(vec![("class", "thumbnail__metadata")])
|
|
|
|
.with_html(info.name.clone())
|
|
|
|
.with_html(format!("{}", info.created.format("%Y-%m-%d"))),
|
|
|
|
)
|
|
|
|
.with_html(
|
|
|
|
Form::new()
|
2023-10-26 02:52:03 +00:00
|
|
|
.with_path(&format!("/delete/{}", *info.id))
|
2023-10-25 14:20:14 +00:00
|
|
|
.with_method("post")
|
|
|
|
.with_html(Button::new("Delete")),
|
|
|
|
),
|
|
|
|
)
|
2023-09-22 04:38:26 +00:00
|
|
|
}
|