mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-22 23:27:46 +00:00
Begin work on HTML templates for future web panel functionality
This commit is contained in:
parent
bd9782a868
commit
3278452ac3
5 changed files with 26 additions and 2 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -334,6 +334,7 @@ name = "kawari"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"minijinja",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -372,6 +373,15 @@ version = "0.3.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "minijinja"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7165d0e94806d52ad5295e4b54a95176d831814840bc067298ca647e1c956338"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.7.2"
|
||||
|
|
|
@ -30,3 +30,4 @@ tracing = { version = "0.1", default-features = false }
|
|||
serde = { version = "1.0", features = ["derive"], default-features = false }
|
||||
tracing-subscriber = { version = "0.3", features = ["fmt"], default-features = false }
|
||||
rand = "0.8"
|
||||
minijinja = "2.0"
|
|
@ -9,6 +9,8 @@ use serde::{Deserialize, Serialize};
|
|||
use axum::response::{Html, Redirect};
|
||||
use axum::routing::post;
|
||||
use kawari::config::{Config, get_config};
|
||||
use minijinja::{Environment, context};
|
||||
use kawari::setup_default_environment;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct GateStatus {
|
||||
|
@ -20,7 +22,9 @@ async fn root() -> Html<String> {
|
|||
|
||||
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)]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use minijinja::Environment;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::Rng;
|
||||
|
||||
|
@ -11,3 +12,10 @@ pub fn generate_sid() -> String {
|
|||
.collect();
|
||||
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
1
templates/admin.html
Normal 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>
|
Loading…
Add table
Reference in a new issue