going somewhere
This commit is contained in:
1 parent
e7cec774d8
commit
8449cf94ee
9 files changed
+106
-24
No files matched your search
@@ -26,15 +26,19 @@ The rust source must be `/nix/store/pmih7jv9r5xfaif92bza8w05876qvnvc-rust-src/`
|
||||
nix develop
|
||||
```
|
||||
|
||||
## Workwork
|
||||
## Todos
|
||||
|
||||
#### Architecture
|
||||
|
||||
* [ ] put all the ressources (migrations, templates and statics) into a ressources directory
|
||||
|
||||
#### Backend
|
||||
|
||||
* [ ] Parametrize `CURRENT_TIMESTAMP`
|
||||
|
||||
### Todo
|
||||
|
||||
#### API
|
||||
|
||||
|
||||
#### Front end
|
||||
|
||||
* [ ] return hello world.
|
||||
* [ ] Serve static files using actix
|
||||
* [ ] Hack https://github.com/bigskysoftware/htmx/blob/master/src/ext/json-enc.js to all embedded fields.
|
||||
* [ ] Create UI to create user
|
||||
* [ ] Create UI to create security
|
||||
+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,
|
||||
};
|
||||
|
||||
+6
-12
@@ -14,25 +14,19 @@
|
||||
class="uk-select"
|
||||
aria-label="Select"
|
||||
class="uk-button uk-button-default"
|
||||
hx-get="/partials/overview/submit_button"
|
||||
hx-get="/partials/actions/action-form"
|
||||
hx-trigger="change,load"
|
||||
hx-target="#submit-button"
|
||||
hx-swap="outerHTML">>
|
||||
hx-target="#action-form"
|
||||
hx-swap="innerHTML">>
|
||||
<option value="create_user">Create User</option>
|
||||
<option value="create_security">Create Security</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="uk-margin">
|
||||
<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 id="action-form"></div>
|
||||
|
||||
|
||||
<div id="submit-button"></div>
|
||||
<div id="parent-div"></div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<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/dist/ext/json-enc.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
<label class="uk-label">
|
||||
<input type="text" name="event.name">
|
||||
|
||||
</label>
|
||||
|
||||
{%include "partials/actions/submit_button.html"%}
|
||||
@@ -0,0 +1,10 @@
|
||||
<div class="uk-margin">
|
||||
<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>
|
||||
|
||||
{%include "partials/actions/submit_button.html"%}
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
hx-post="/v1/events/{{event_type}}"
|
||||
hx-trigger="click"
|
||||
hx-target="#event-table-first-row"
|
||||
hx-ext="json-enc"
|
||||
hx-swap="outerHTML">
|
||||
Submit
|
||||
Submit ss
|
||||
</button>
|
||||
@@ -0,0 +1,14 @@
|
||||
(function() {
|
||||
htmx.defineExtension('embedded-json-enc', {
|
||||
onEvent: function (name, evt) {
|
||||
if (name === "htmx:configRequest") {
|
||||
evt.detail.headers['Content-Type'] = "application/json";
|
||||
}
|
||||
},
|
||||
|
||||
encodeParameters : function(xhr, parameters, elt) {
|
||||
xhr.overrideMimeType('text/json');
|
||||
return (JSON.stringify(parameters));
|
||||
}
|
||||
});
|
||||
})()
|
||||
Reference in new issue
Block a user