|
|
|
@@ -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 {
|
|
|
|
|