more shit.

This commit is contained in:
didier amyot committed 2023-02-05 13:58:47 -05:00
1 parent de51e20181
commit ba7763cbb1
6 files changed
+88 -41

No files matched your search

+2 -1
View File
@@ -69,7 +69,6 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
notifier.watch_path(&tmpl_path, true); notifier.watch_path(&tmpl_path, true);
} }
env.set_source(minijinja::Source::from_path(tmpl_path)); env.set_source(minijinja::Source::from_path(tmpl_path));
println!("boom");
Ok(env) Ok(env)
}); });
@@ -81,6 +80,8 @@ pub async fn web_ui_main(port: u16, enable_template_autoreload: bool) -> std::io
.service(views::index) .service(views::index)
.service(views::actions) .service(views::actions)
.service(views::overview) .service(views::overview)
.service(views::overview_submit_button)
.service(views::push_event)
.wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found)) .wrap(ErrorHandlers::new().handler(StatusCode::NOT_FOUND, not_found))
.wrap(Logger::default()) .wrap(Logger::default())
}) })
+33 -3
View File
@@ -1,8 +1,12 @@
use crate::webui::MiniJinjaRenderer; use actix_web::{HttpRequest, Responder, web};
use actix_web::{web, Responder};
use actix_web::http::header::q; use actix_web::http::header::q;
use clap::builder::TypedValueParser;
use minijinja::context;
use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use crate::webui::MiniJinjaRenderer;
#[actix_web::get("/")] #[actix_web::get("/")]
pub async fn index( pub async fn index(
tmpl_env: MiniJinjaRenderer, tmpl_env: MiniJinjaRenderer,
@@ -19,7 +23,6 @@ pub async fn actions(
tmpl_env.render("actions.html", ()) tmpl_env.render("actions.html", ())
} }
#[actix_web::get("/overview")] #[actix_web::get("/overview")]
pub async fn overview( pub async fn overview(
tmpl_env: MiniJinjaRenderer, tmpl_env: MiniJinjaRenderer,
@@ -27,3 +30,30 @@ pub async fn overview(
) -> actix_web::Result<impl Responder> { ) -> actix_web::Result<impl Responder> {
tmpl_env.render("overview.html", ()) tmpl_env.render("overview.html", ())
} }
#[actix_web::get("/partials/overview/submit_button")]
pub async fn overview_submit_button(
req: HttpRequest,
tmpl_env: MiniJinjaRenderer,
query: web::Query<HashMap<String, String>>
) -> actix_web::Result<impl Responder> {
let ctx = context! {
event_type => query.get("event_type").unwrap_or(&"".to_string()),
};
tmpl_env.render("partials/overview/submit_button.html", ctx)
}
#[actix_web::post("/v1/events/{event_type}")]
pub async fn push_event(
req: HttpRequest,
tmpl_env: MiniJinjaRenderer,
query: web::Query<HashMap<String, String>>,
) -> actix_web::Result<impl Responder> {
println!(">> {:?}", req);
let shit = req.match_info().get("event_type").unwrap();
let event = req.match_info().get("event").unwrap();
let ctx = context! {
event_type => shit,
};
tmpl_env.render("partials/v1/event_processed.html", ctx)
}
+24 -25
View File
@@ -8,40 +8,39 @@
<form> <form>
<fieldset class="uk-fieldset"> <fieldset class="uk-fieldset">
<legend class="uk-legend">Legend</legend> <legend class="uk-legend">Create new item</legend>
<div class="uk-margin"> <div class="uk-margin">
<input class="uk-input" type="text" placeholder="Input" aria-label="Input"> <select name="event_type"
</div> class="uk-select"
aria-label="Select"
<div class="uk-margin"> class="uk-button uk-button-default"
<select class="uk-select" aria-label="Select"> hx-get="/partials/overview/submit_button"
<option>Option 01</option> hx-trigger="change,load"
<option>Option 02</option> hx-target="#submit-button"
hx-swap="outerHTML">>
<option value="create_user">Create User</option>
<option value="create_security">Create Security</option>
</select> </select>
</div> </div>
<div class="uk-margin"> <div class="uk-margin">
<textarea class="uk-textarea" rows="5" placeholder="Textarea" aria-label="Textarea"></textarea> <label class="uk-form-label">Event [JSON5]</label>
<textarea class="uk-textarea"
name="event"
style="font: 0.875rem/1.5 Consolas,monaco,monospace"
rows="5"
placeholder="JSON"></textarea>
</div> </div>
<div id="submit-button"></div>
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid"> <div id="parent-div"></div>
<label><input class="uk-radio" type="radio" name="radio2" checked> A</label>
<label><input class="uk-radio" type="radio" name="radio2"> B</label>
</div>
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid">
<label><input class="uk-checkbox" type="checkbox" checked> A</label>
<label><input class="uk-checkbox" type="checkbox"> B</label>
</div>
<div class="uk-margin">
<input class="uk-range" type="range" value="2" min="0" max="10" step="0.1" aria-label="Range">
</div>
</fieldset> </fieldset>
</form> </form>
<table class="uk-table uk-table-small">
<thead></thead>
<tbody id="event-table-first-row"></tbody>
</table>
</div> </div>
{% endblock %} {% endblock %}
+19 -12
View File
@@ -4,28 +4,35 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ledger</title> <title>ledger</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.5/css/uikit.min.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.15.23/dist/css/uikit.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.27.5/js/uikit.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/uikit@3.15.23/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/uikit@3.15.23/dist/js/uikit-icons.min.js"></script>
<script src="https://unpkg.com/htmx.org@1.8.5"></script> <script src="https://unpkg.com/htmx.org@1.8.5"></script>
</head> </head>
<body> <body>
<nav class="uk-navbar">
<a href="/" class="uk-navbar-brand">Ledger</a>
<ul class="uk-navbar-nav"> <nav class="uk-navbar-container" uk-navbar>
{% set nav_bar_items = [{'id': 'overview', 'label': 'Overview'}, <div class="uk-navbar-left">
{'id': 'actions', 'label': 'Actions'}]%} <a href="/" class="uk-navbar-item uk-logo">Ledger</a>
{% for itm in nav_bar_items %} <ul class="uk-navbar-nav">
<li class="{% if active_navbar_item == itm.id %}uk-active"{% else %} uk-parent {% endif %}"><a href="{{ itm.id }}">{{ itm.label }}</a></li> {% set nav_bar_items = [{'id': 'overview', 'label': 'Overview'},
{% endfor %} {'id': 'actions', 'label': 'Actions'}]%}
</ul> {% for itm in nav_bar_items %}
<li class="{% if active_navbar_item == itm.id %}uk-active"{% endif %}"><a href="{{ itm.id }}">{{ itm.label }}</a></li>
{% endfor %}
</ul>
</div>
</nav> </nav>
<div class="uk-grid"> <div class="uk-grid">
<div class="uk-width-2-3 uk-container-center"> <div class="uk-width-1-6@m"></div>
<div class="uk-width-2-3@m">
{% block body %} {% block body %}
{% endblock %} {% endblock %}
</div> </div>
<div class="uk-width-1-6@m"></div>
</div> </div>
</body> </body>
@@ -0,0 +1,8 @@
<button id="submit-button"
class="uk-button uk-button-default"
hx-post="/v1/events/{{event_type}}"
hx-trigger="click"
hx-target="#event-table-first-row"
hx-swap="outerHTML">
Submit
</button>
@@ -0,0 +1,2 @@
<tbody id="event-table-first-row"></tbody>
<tr><td>une</td><td>{{ event_type }}</td></tr>