diff --git a/src/web/ui.rs b/src/web/ui.rs index fcb6b5ce..e01d7944 100644 --- a/src/web/ui.rs +++ b/src/web/ui.rs @@ -4,7 +4,7 @@ use std::{sync::Arc, time::Duration}; use futures::{future, Future}; use hyper::{header, service::Service, Body, Method, Request, Response, StatusCode}; -use ritz::html; +use ritz::{html, HtmlContent}; use crate::{ imfs::ImfsFetcher, @@ -34,8 +34,8 @@ impl Service for UiService { (&Method::GET, "/") => self.handle_home(), (&Method::GET, "/logo.png") => self.handle_logo(), (&Method::GET, "/icon.png") => self.handle_icon(), - (&Method::GET, "/visualize/rbx") => self.handle_visualize_rbx(), - (&Method::GET, "/visualize/imfs") => self.handle_visualize_imfs(), + (&Method::GET, "/show-instances") => self.handle_show_instances(), + (&Method::GET, "/show-imfs") => self.handle_show_imfs(), (_method, path) => { return json( ErrorResponse::not_found(format!("Route not found: {}", path)), @@ -80,7 +80,61 @@ impl UiService { humantime::format_duration(elapsed).to_string() }; - let page = html! { + let page = Self::page(html! { +
+
+ +
+ { Self::stat_item("Server Version", SERVER_VERSION) } + { Self::stat_item("Project", project_name) } + { Self::stat_item("Server Uptime", uptime) } +
+
+
+ { Self::button("Rojo Documentation", "https://rojo.space/docs") } + { Self::button("View in-memory filesystem state", "/show-imfs") } + { Self::button("View instance tree state", "/show-instances") } +
+
+ }); + + Response::builder() + .header(header::CONTENT_TYPE, "text/html") + .body(Body::from(format!("{}", page))) + .unwrap() + } + + fn handle_show_instances(&self) -> Response { + Response::builder() + .header(header::CONTENT_TYPE, "text/plain") + .body(Body::from("TODO: /show-instances")) + .unwrap() + } + + fn handle_show_imfs(&self) -> Response { + Response::builder() + .header(header::CONTENT_TYPE, "text/plain") + .body(Body::from("TODO: /show-imfs")) + .unwrap() + } + + fn stat_item>(name: &str, value: S) -> HtmlContent<'_> { + html! { + + { name } ": " + { value.into() } + + } + } + + fn button<'a>(text: &'a str, href: &'a str) -> HtmlContent<'a> { + html! { + { text } + } + } + + fn page(body: HtmlContent<'_>) -> HtmlContent<'_> { + html! { "Rojo Live Server" @@ -91,57 +145,9 @@ impl UiService { -
-
- -
- - "Server Version: " - { SERVER_VERSION } - - - "Project: " - { project_name } - - - "Server Uptime: " - { uptime.to_string() } - -
-
- -
+ { body } - }; - - Response::builder() - .header(header::CONTENT_TYPE, "text/html") - .body(Body::from(format!("{}", page))) - .unwrap() - } - - fn handle_visualize_rbx(&self) -> Response { - Response::builder() - .header(header::CONTENT_TYPE, "text/plain") - .body(Body::from("TODO: /visualize/rbx")) - .unwrap() - } - - fn handle_visualize_imfs(&self) -> Response { - Response::builder() - .header(header::CONTENT_TYPE, "text/plain") - .body(Body::from("TODO: /visualize/imfs")) - .unwrap() + } } }