going somewhere

This commit is contained in:
didier amyot committed 2023-02-08 09:14:27 -05:00
1 parent e7cec774d8
commit 8449cf94ee
9 files changed
+106 -24

No files matched your search

+51 -2
View File
@@ -5,6 +5,8 @@ use minijinja::context;
use serde::Deserialize;
use std::collections::HashMap;
use log::info;
use resource::resource_str;
use crate::webui::MiniJinjaRenderer;
@@ -41,9 +43,55 @@ pub async fn overview_submit_button(
tmpl_env.render("partials/overview/submit_button.html", ctx)
}
#[actix_web::get("/partials/actions/action-form")]
pub async fn actions_partials(
req: HttpRequest,
tmpl_env: MiniJinjaRenderer,
query: web::Query<HashMap<String, String>>,
) -> actix_web::Result<impl Responder> {
let event_type = query.get("event_type").unwrap_or(&"404".to_string()).to_string();
let ctx = context!{event_type => event_type};
let template_location = format!("partials/actions/{:}.html", event_type);
info!("Getting template at: {:?}", template_location);
tmpl_env.render(template_location.as_str(), ctx)
}
#[actix_web::get("/static/{file_name}")]
pub async fn static_file(
req: HttpRequest
) -> actix_web::Result<impl Responder> {
let file_name = req.match_info().get("file_name").unwrap_or(&"404.html".to_string()).to_string();
let template_location = format!("static/{:}", file_name);
info!("Getting static file: {:?}", file_name);
Ok(template_location)
}
#[derive(Deserialize, Debug)]
struct Event1{
name: String,
age: i64,
}
#[derive(Deserialize, Debug)]
struct Event2{
name: String,
score: i64,
}
#[derive(Deserialize, Debug)]
enum Event{
Event1(Event1),
Event2(Event2),
}
#[derive(Deserialize, Debug)]
struct CreateEventPayload {
event: String,
event: Event,
event_type: String,
}
@@ -51,9 +99,10 @@ struct CreateEventPayload {
pub async fn push_event(
req: HttpRequest,
tmpl_env: MiniJinjaRenderer,
web::Form(form): web::Form<CreateEventPayload>,
web::Json(form): web::Json<CreateEventPayload>,
) -> actix_web::Result<impl Responder> {
let shit = req.match_info().get("event_type").unwrap();
println!("payload: {:?}", form);
let ctx = context! {
event_type => shit,
};