going somewhere
This commit is contained in:
1 parent
e7cec774d8
commit
8449cf94ee
9 files changed
+106
-24
No files matched your search
+4
-2
@@ -64,8 +64,8 @@ impl FromRequest for MiniJinjaRenderer {
|
||||
async fn print_shit() -> std::io::Result<()>{
|
||||
let mut i = 0;
|
||||
loop {
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
println!("he he! {:?}", i);
|
||||
sleep(Duration::from_millis(10_000)).await;
|
||||
println!("Loop on a different thread {:?}", i);
|
||||
i +=1;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,8 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
|
||||
.service(views::actions)
|
||||
.service(views::overview)
|
||||
.service(views::overview_submit_button)
|
||||
.service(views::actions_partials)
|
||||
.service(views::static_file)
|
||||
.service(views::push_event)
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found))
|
||||
.wrap(Logger::default())
|
||||
|
||||
+51
-2
@@ -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,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user