wip: further development
This commit is contained in:
parent
15e60e6325
commit
dcde768fb6
5
rear/src/depot/constants.rs
Normal file
5
rear/src/depot/constants.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub(crate) struct TemplateFiles {
|
||||||
|
base_hx: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static TPL: TemplateFiles = TemplateFiles { base_hx: "" };
|
@ -1,5 +1,6 @@
|
|||||||
use axum::{routing::get, Router};
|
use axum::{routing::get, Router};
|
||||||
|
|
||||||
|
mod constants;
|
||||||
mod context;
|
mod context;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod registry;
|
mod registry;
|
||||||
@ -8,7 +9,9 @@ pub mod state;
|
|||||||
pub mod views;
|
pub mod views;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
|
||||||
pub fn routes<S: state::DepotState + Clone + Send + Sync + 'static>() -> Router<S> {
|
use state::DepotFn;
|
||||||
|
|
||||||
|
pub fn routes<S: DepotFn>() -> Router<S> {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/", get(views::index::<S>).post(views::index_action::<S>))
|
.route("/", get(views::index::<S>).post(views::index_action::<S>))
|
||||||
.route("/:section", get(views::list_section::<S>))
|
.route("/:section", get(views::list_section::<S>))
|
||||||
|
@ -9,3 +9,5 @@ pub trait DepotState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub type SharedDepotRegistry = Arc<DepotRegistry>;
|
pub type SharedDepotRegistry = Arc<DepotRegistry>;
|
||||||
|
|
||||||
|
pub trait DepotFn = DepotState + Clone + Send + Sync + 'static;
|
||||||
|
@ -6,7 +6,7 @@ use log::info;
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::context::DepotContext;
|
use super::context::DepotContext;
|
||||||
use super::state::DepotState;
|
use super::state::{DepotFn, DepotState};
|
||||||
|
|
||||||
pub fn base_template(headers: &HeaderMap) -> Option<String> {
|
pub fn base_template(headers: &HeaderMap) -> Option<String> {
|
||||||
let hx_request = headers.get("HX-Request").is_some();
|
let hx_request = headers.get("HX-Request").is_some();
|
||||||
@ -17,10 +17,7 @@ pub fn base_template(headers: &HeaderMap) -> Option<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn index<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn index<S: DepotFn>(depot: State<S>, headers: HeaderMap) -> impl IntoResponse {
|
||||||
depot: State<S>,
|
|
||||||
headers: HeaderMap,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let templates = depot.get_templates();
|
let templates = depot.get_templates();
|
||||||
let registry = depot.get_registry();
|
let registry = depot.get_registry();
|
||||||
templates.render_html(
|
templates.render_html(
|
||||||
@ -34,13 +31,11 @@ pub async fn index<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Index Action is POST to the index site. We can anchor some general business code here.
|
// Index Action is POST to the index site. We can anchor some general business code here.
|
||||||
pub async fn index_action<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn index_action<S: DepotFn>(depot: State<S>) -> impl IntoResponse {
|
||||||
depot: State<S>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
"There is your answer!".to_owned()
|
"There is your answer!".to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_section<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn list_section<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
Path(depot_key): Path<String>,
|
Path(depot_key): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
@ -49,7 +44,7 @@ pub async fn list_section<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List Items renders the entire list item page.
|
// List Items renders the entire list item page.
|
||||||
pub async fn list_item_collection<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn list_item_collection<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key)): Path<(String, String)>,
|
Path((depot_key, model_key)): Path<(String, String)>,
|
||||||
@ -81,7 +76,7 @@ pub async fn list_item_collection<S: DepotState + Clone + Send + Sync + 'static>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Items Action is a POST to an item list. By default these are actions, that work on a list of items as input.
|
// Items Action is a POST to an item list. By default these are actions, that work on a list of items as input.
|
||||||
pub async fn item_collection_action<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn item_collection_action<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
Path((depot_key, model_key)): Path<(String, String)>,
|
Path((depot_key, model_key)): Path<(String, String)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
@ -89,7 +84,7 @@ pub async fn item_collection_action<S: DepotState + Clone + Send + Sync + 'stati
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Item Details shows one single dataset.
|
// Item Details shows one single dataset.
|
||||||
pub async fn view_item_details<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn view_item_details<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
||||||
@ -128,7 +123,7 @@ pub async fn view_item_details<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
templates.render_html("depot/items/item_detail.jinja", context)
|
templates.render_html("depot/items/item_detail.jinja", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_item<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn new_item<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key)): Path<(String, String)>,
|
Path((depot_key, model_key)): Path<(String, String)>,
|
||||||
@ -158,7 +153,7 @@ pub async fn new_item<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
templates.render_html("depot/items/item_create.jinja", context)
|
templates.render_html("depot/items/item_create.jinja", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_item<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn create_item<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key)): Path<(String, String)>,
|
Path((depot_key, model_key)): Path<(String, String)>,
|
||||||
@ -196,7 +191,7 @@ pub async fn create_item<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Change is the GET version.
|
/// Change is the GET version.
|
||||||
pub async fn change_item<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn change_item<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
||||||
@ -237,7 +232,7 @@ pub async fn change_item<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
templates.render_html("depot/items/item_change.jinja", context)
|
templates.render_html("depot/items/item_change.jinja", context)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_item<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn update_item<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
Path((depot_key, model_key, id)): Path<(String, String, String)>,
|
||||||
@ -280,14 +275,14 @@ pub async fn update_item<S: DepotState + Clone + Send + Sync + 'static>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Item Action allows running an action on one single dataset.
|
// Item Action allows running an action on one single dataset.
|
||||||
pub async fn item_action<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn item_action<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
Path((depot_key, model_key, model_id)): Path<(String, String, String)>,
|
Path((depot_key, model_key, model_id)): Path<(String, String, String)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
"There is your answer!".to_owned()
|
"There is your answer!".to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn debug_view<S: DepotState + Clone + Send + Sync + 'static>(
|
pub async fn debug_view<S: DepotFn>(
|
||||||
depot: State<S>,
|
depot: State<S>,
|
||||||
Path(data): Path<String>,
|
Path(data): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
|
#![feature(trait_alias)]
|
||||||
pub mod depot;
|
pub mod depot;
|
||||||
pub mod service;
|
pub mod service;
|
||||||
|
@ -38,7 +38,7 @@ impl DepotRepository for UserRepository {
|
|||||||
.build()
|
.build()
|
||||||
.set_widget(
|
.set_widget(
|
||||||
"password",
|
"password",
|
||||||
Widget::widget("/admin/widgets/password_change.jinja").as_password(),
|
Widget::widget("/depot/widgets/password_change.jinja").as_password(),
|
||||||
)
|
)
|
||||||
.set_widget("is_staff", Widget::checkbox())
|
.set_widget("is_staff", Widget::checkbox())
|
||||||
.set_widget("is_active", Widget::checkbox())
|
.set_widget("is_active", Widget::checkbox())
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
{% from "/depot/items/items.jinja" import field_widget %}
|
{% from "/depot/items/items.jinja" import field_widget %}
|
||||||
{% for field_name, field_defs in fields %}
|
{% for field_name, field_defs in fields %}
|
||||||
{% if item %}
|
{% if item %}
|
||||||
{% set field_value = item.fields[field_name]|none("") %}
|
{% set field_value = item.fields[field_name]|none("") %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set field_value = "" %}
|
{% set field_value = "" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
{{ field_widget(field_name, field_defs, field_value) }}
|
{{ field_widget(field_name, field_defs, field_value) }}
|
||||||
|
Loading…
Reference in New Issue
Block a user