Compare commits
10 Commits
bd24116e50
...
67c35a4b4a
Author | SHA1 | Date | |
---|---|---|---|
67c35a4b4a | |||
4c13fbe0eb | |||
72b10d8994 | |||
4653c4dac0 | |||
164c1a5b8e | |||
60549bd227 | |||
a7548208c9 | |||
6bc688012c | |||
0c5ad2496f | |||
a55bea9d34 |
@ -19,7 +19,7 @@ name = "actix_admin"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ['enable-tracing']
|
||||
enable-tracing = ['tracing']
|
||||
|
||||
[dependencies]
|
||||
|
@ -13,7 +13,7 @@ use actix_web::{
|
||||
use async_trait::async_trait;
|
||||
use derive_more::{Display, Error};
|
||||
use sea_orm::DatabaseConnection;
|
||||
use serde_derive::{Serialize};
|
||||
use serde_derive::Serialize;
|
||||
use tera::Tera;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -116,6 +116,8 @@ pub enum ActixAdminError {
|
||||
|
||||
impl error::ResponseError for ActixAdminError {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::debug!("{self:#?}");
|
||||
HttpResponse::build(self.status_code())
|
||||
.insert_header(ContentType::html())
|
||||
.body(self.to_string())
|
||||
@ -123,6 +125,7 @@ impl error::ResponseError for ActixAdminError {
|
||||
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
Self::ValidationErrors => StatusCode::BAD_REQUEST,
|
||||
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
||||
model = res;
|
||||
},
|
||||
Err(e) => {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{e}");
|
||||
errors.push(e);
|
||||
model = ActixAdminModel::create_empty();
|
||||
}
|
||||
@ -69,7 +71,7 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
||||
false => HttpResponse::InternalServerError(),
|
||||
};
|
||||
let notifications: Vec<ActixAdminNotification> = errors.into_iter()
|
||||
.map(|err| ActixAdminNotification::from(err))
|
||||
.map(ActixAdminNotification::from)
|
||||
.collect();
|
||||
|
||||
let params = web::Query::<Params>::from_query(req.query_string()).unwrap();
|
||||
@ -97,6 +99,10 @@ async fn create_or_edit_get<E: ActixAdminViewModelTrait>(session: &Session, req:
|
||||
|
||||
let body = actix_admin.tera
|
||||
.render("create_or_edit.html", &ctx)
|
||||
.map_err(|err| error::ErrorInternalServerError(err))?;
|
||||
.map_err(|err| {
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
error::ErrorInternalServerError(err)
|
||||
})?;
|
||||
Ok(http_response_code.content_type("text/html").body(body))
|
||||
}
|
@ -82,10 +82,19 @@ pub async fn create_or_edit_post<E: ActixAdminViewModelTrait>(
|
||||
let db = db.get_ref();
|
||||
|
||||
let mut model = model_res.unwrap();
|
||||
#[cfg(feature="enable-tracing")]
|
||||
{
|
||||
tracing::debug!("Entity model: {:#?}", model);
|
||||
}
|
||||
E::validate_entity(&mut model);
|
||||
|
||||
if model.has_errors() {
|
||||
errors.push(ActixAdminError::ValidationErrors);
|
||||
#[cfg(feature="enable-tracing")]
|
||||
{
|
||||
tracing::error!("OP errors: {errors:#?}");
|
||||
tracing::debug!("Model errors: {:#?}", model.errors);
|
||||
}
|
||||
render_form::<E>(
|
||||
req,
|
||||
actix_admin,
|
||||
@ -125,7 +134,7 @@ pub async fn create_or_edit_post<E: ActixAdminViewModelTrait>(
|
||||
.finish())
|
||||
}
|
||||
Err(e) => {
|
||||
#[cfg(enable_tracing)]
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{e}");
|
||||
errors.push(e);
|
||||
render_form::<E>(
|
||||
@ -175,6 +184,7 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
ctx.insert("sort_order", &sort_order);
|
||||
ctx.insert("page", &page);
|
||||
|
||||
ctx.insert("navbar_title", &actix_admin.configuration.navbar_title);
|
||||
ctx.insert("entity_names", &actix_admin.entity_names);
|
||||
ctx.insert(
|
||||
"view_model",
|
||||
@ -187,8 +197,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
let notifications: Vec<ActixAdminNotification> = errors
|
||||
.into_iter()
|
||||
.map(|err| {
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::error!("{e}");
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
ActixAdminNotification::from(err)
|
||||
})
|
||||
.collect();
|
||||
@ -197,8 +207,8 @@ async fn render_form<E: ActixAdminViewModelTrait>(
|
||||
let body = actix_admin.tera
|
||||
.render("create_or_edit.html", &ctx)
|
||||
.map_err(|err| {
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::error!("{e}");
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{err}");
|
||||
error::ErrorInternalServerError(err)
|
||||
})?;
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
||||
|
@ -30,8 +30,8 @@ pub async fn index(session: Session, data: web::Data<ActixAdmin>) -> Result<Http
|
||||
let body = actix_admin.tera
|
||||
.render("index.html", &ctx)
|
||||
.map_err(|e| {
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::warn!("{}", e);
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{}", e);
|
||||
error::ErrorInternalServerError("Template error")
|
||||
})?;
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(body))
|
||||
@ -41,8 +41,8 @@ pub async fn not_found(data: web::Data<ActixAdmin>) -> Result<HttpResponse, Erro
|
||||
let body = data.get_ref().tera
|
||||
.render("not_found.html", &Context::new())
|
||||
.map_err(|e| {
|
||||
#[cfg(enable_tracing)]
|
||||
tracing::warn!("{}", e);
|
||||
#[cfg(feature="enable-tracing")]
|
||||
tracing::error!("{}", e);
|
||||
error::ErrorInternalServerError("Template error")
|
||||
})?;
|
||||
Ok(HttpResponse::NotFound().content_type("text/html").body(body))
|
||||
|
@ -7,7 +7,7 @@
|
||||
model.custom_errors | get(key=model_field.field_name, default="" ) !=""
|
||||
%}is-danger{% else %}is-success{% endif %}
|
||||
{% endif %}
|
||||
" type="{{ model_field | get_html_input_type }}" name="{{ model_field.field_name }}"
|
||||
" type="{{ model_field | get_html_input_type }}" name="{{ model_field.field_name | trim }}"
|
||||
placeholder="{{ model_field.field_name }}"
|
||||
aria-label="{{ model_field.field_name }}">{{ model.values | get(key=model_field.field_name, default="") }}</textarea>
|
||||
{% elif model_field.field_type == "FileUpload" and model.values | get(key=model_field.field_name, default="") != "" %}
|
||||
|
Loading…
Reference in New Issue
Block a user