diff options
Diffstat (limited to 'src/frontend.rs')
-rw-r--r-- | src/frontend.rs | 133 |
1 files changed, 74 insertions, 59 deletions
diff --git a/src/frontend.rs b/src/frontend.rs index 964367e..386bb95 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -6,25 +6,27 @@ use actix_web::HttpRequest; use actix_web::HttpResponse; use actix_web::Error; +// TODO: This is not how you do it +#[get("/style.css")] +pub async fn css() -> &'static str { + std::include_str!("../static/bulma.css") +} + #[get("/")] pub async fn index() -> Result<maud::Markup> { - Ok(maud::html! { - html { - body { - h1 { "Waterlevels" } - - p { "Please note that the application is resource-constrained to 25 MB RAM and 100 Landscape elements or 1000 hours of rain!" } - p { "The application will fail with bigger numbers or if OOM." } + Ok(make_body(maud::html! { + small { + p { "Please note that the application is resource-constrained to 25 MB RAM and 100 Landscape elements or 1000 hours of rain!" } + p { "The application will fail with bigger numbers or if OOM." } + } - form action="/make_landscape" method="post" { - label { "Elements" } - input type="number" name="elements" checked; + form action="/make_landscape" method="post" { + label for="elements" { "Elements" } + input type="number" name="elements" checked; - input type="submit"; - } - } + input type="submit"; } - }) + })) } @@ -36,36 +38,26 @@ pub struct LandscapeSize { #[post("/make_landscape")] pub async fn make_landscape(form: web::Form<LandscapeSize>) -> Result<maud::Markup> { if form.elements > 100 { - return Ok(maud::html! { - html { - body { - p { "For runtime reasons, this application only supports landscapes up to 100 elements" } - } - } - }) + return Ok(make_body(maud::html! { + p { "For runtime reasons, this application only supports landscapes up to 100 elements" } + })) } - Ok(maud::html! { - html { - body { - h1 { "Hello World!" } - - p { "Please fill in the landscape values" } - form action="/calculate" method="get" { - @for _n in 0..form.elements { - p { - input type="number" name="levels[]" checked; - } - } - - input type="number" name="hours" checked; - label for="hours" { "Hours of Rain" } - - input type="submit"; + Ok(make_body(maud::html! { + p { "Please fill in the landscape values" } + form action="/calculate" method="get" { + @for _n in 0..form.elements { + p { + input type="number" name="levels[]" checked; } } + + input type="number" name="hours" checked; + label for="hours" { "Hours of Rain" } + + input type="submit"; } - }) + })) } #[derive(serde::Deserialize)] @@ -94,37 +86,60 @@ pub async fn calculate(req: HttpRequest) -> Result<maud::Markup> { // TODO: We should propably error with 500 here, I'm not sure. // This is just "good enough" for now. if ls.hours > 1000 { - return Ok(maud::html! { - html { - body { - h1 { "Landscape error" } - - p { "Not gonna do that. Calculating " (ls.hours) " is way too resource intensive, please use a value below 1000" } - } - } - }) + return Ok(make_body(maud::html! { + h2 class="title is-2" { "Landscape error" } + p { "Not gonna do that. Calculating " (ls.hours) " is way too resource intensive, please use a value below 1000" } + })) } let calculated_landscape = crate::backend::landscape::Landscape::new(ls.levels.clone()).rain(ls.hours); - Ok(maud::html! { - html { - body { - h1 { "Landscape!" } + Ok(make_body(maud::html! { + h2 class="title is-2" { "Landscape" } - p { "Filling in " (ls.hours) " hours" } + p { "Filling in " (ls.hours) " hours" } - @for value in &ls.levels { - p { (value) } + table class="table" { + tbody { + tr { + @for value in &ls.levels { + td { (value) } + } } + } + } - h2 { "Filled" } + h2 class="title is-2" { "Filled" } - @for val in calculated_landscape.into_inner() { - p { (val.0) " + " (val.1) } + table class="table" { + tbody { + tr { + @for val in calculated_landscape.into_inner() { + td { (val.0) " + " (val.1) } + } } } } - }) + })) } +fn make_body(inner: maud::Markup) -> maud::Markup { + maud::html! { + link rel="stylesheet" href="style.css"; + html { + body { + center { + h1 class="title is-1" { "Water Levels Application" } + } + div class="columns" { + div class="column is-one-fifth" { + } + div class="column" { + (inner) + } + } + } + } + } +} + |