1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-21 23:17:45 +00:00

Begin work on HTML templates for future web panel functionality

This commit is contained in:
Joshua Goins 2024-05-11 13:58:58 -04:00
parent bd9782a868
commit 3278452ac3
5 changed files with 26 additions and 2 deletions

10
Cargo.lock generated
View file

@ -334,6 +334,7 @@ name = "kawari"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"minijinja",
"rand", "rand",
"serde", "serde",
"serde_json", "serde_json",
@ -372,6 +373,15 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "minijinja"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7165d0e94806d52ad5295e4b54a95176d831814840bc067298ca647e1c956338"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.2" version = "0.7.2"

View file

@ -30,3 +30,4 @@ tracing = { version = "0.1", default-features = false }
serde = { version = "1.0", features = ["derive"], default-features = false } serde = { version = "1.0", features = ["derive"], default-features = false }
tracing-subscriber = { version = "0.3", features = ["fmt"], default-features = false } tracing-subscriber = { version = "0.3", features = ["fmt"], default-features = false }
rand = "0.8" rand = "0.8"
minijinja = "2.0"

View file

@ -9,6 +9,8 @@ use serde::{Deserialize, Serialize};
use axum::response::{Html, Redirect}; use axum::response::{Html, Redirect};
use axum::routing::post; use axum::routing::post;
use kawari::config::{Config, get_config}; use kawari::config::{Config, get_config};
use minijinja::{Environment, context};
use kawari::setup_default_environment;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
struct GateStatus { struct GateStatus {
@ -20,7 +22,9 @@ async fn root() -> Html<String> {
let config = get_config(); let config = get_config();
Html(format!("<p>Gate open:{}</p><form action='apply' method='post'><input type='checkbox' id='gate_open' name='gate_open' checked /><button type='submit'>Apply</button></form>", config.gate_open)) let environment = setup_default_environment();
let template = environment.get_template("admin.html").unwrap();
Html(template.render(context! { gate_open => config.gate_open }).unwrap())
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]

View file

@ -1,3 +1,4 @@
use minijinja::Environment;
use rand::distributions::Alphanumeric; use rand::distributions::Alphanumeric;
use rand::Rng; use rand::Rng;
@ -11,3 +12,10 @@ pub fn generate_sid() -> String {
.collect(); .collect();
random_id.to_lowercase() random_id.to_lowercase()
} }
pub fn setup_default_environment() -> Environment<'static> {
let mut env = Environment::new();
env.add_template("admin.html", include_str!("../templates/admin.html")).unwrap();
env
}

1
templates/admin.html Normal file
View file

@ -0,0 +1 @@
<p>Gate open:{{ gate_open }}</p><form action='apply' method='post'><input type='checkbox' id='gate_open' name='gate_open' checked /><button type='submit'>Apply</button></form>