Fix field name
This commit is contained in:
parent
ae072d1812
commit
c473e35566
@ -253,7 +253,7 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
|
|||||||
for (field_name, html_input_type, select_list, is_option_list, fields_type_path, is_textarea, is_file_upload, list_sort_position, list_hide_column, list_regex_mask) in actix_admin::prelude::izip!(&field_names, &html_input_types, &field_select_lists, is_option_lists, fields_type_paths, fields_textareas, fields_fileupload, list_sort_positions, list_hide_columns, list_regex_masks) {
|
for (field_name, html_input_type, select_list, is_option_list, fields_type_path, is_textarea, is_file_upload, list_sort_position, list_hide_column, list_regex_mask) in actix_admin::prelude::izip!(&field_names, &html_input_types, &field_select_lists, is_option_lists, fields_type_paths, fields_textareas, fields_fileupload, list_sort_positions, list_hide_columns, list_regex_masks) {
|
||||||
|
|
||||||
let select_list = select_list.replace('"', "").replace(' ', "").to_string();
|
let select_list = select_list.replace('"', "").replace(' ', "").to_string();
|
||||||
let field_name = field_name.replace('"', "").replace(' ', "").to_string();
|
let field_name = field_name.replace('"', "").replace(' ', "").trim().to_string();
|
||||||
let html_input_type = html_input_type.replace('"', "").replace(' ', "").to_string();
|
let html_input_type = html_input_type.replace('"', "").replace(' ', "").to_string();
|
||||||
let mut list_regex_mask_regex = None;
|
let mut list_regex_mask_regex = None;
|
||||||
if list_regex_mask != "" {
|
if list_regex_mask != "" {
|
||||||
@ -261,8 +261,8 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
|
|||||||
};
|
};
|
||||||
|
|
||||||
vec.push(ActixAdminViewModelField {
|
vec.push(ActixAdminViewModelField {
|
||||||
field_name: field_name,
|
field_name,
|
||||||
html_input_type: html_input_type,
|
html_input_type,
|
||||||
select_list: select_list.clone(),
|
select_list: select_list.clone(),
|
||||||
is_option: is_option_list,
|
is_option: is_option_list,
|
||||||
list_sort_position: list_sort_position,
|
list_sort_position: list_sort_position,
|
||||||
|
@ -37,7 +37,7 @@ impl ModelField {
|
|||||||
pub fn get_type_path_string(&self) -> String {
|
pub fn get_type_path_string(&self) -> String {
|
||||||
let type_path_string: String;
|
let type_path_string: String;
|
||||||
if self.is_option() {
|
if self.is_option() {
|
||||||
match &self.inner_type.clone().unwrap() {
|
match &self.inner_type.as_ref().unwrap() {
|
||||||
Type::Path(type_path) => type_path_string = type_path.clone().into_token_stream().to_string(),
|
Type::Path(type_path) => type_path_string = type_path.clone().into_token_stream().to_string(),
|
||||||
_ => panic!("not a type path")
|
_ => panic!("not a type path")
|
||||||
}
|
}
|
||||||
@ -50,4 +50,4 @@ impl ModelField {
|
|||||||
|
|
||||||
type_path_string
|
type_path_string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,17 +87,17 @@ pub fn filter_fields(fields: &Fields) -> Vec<ModelField> {
|
|||||||
visibility: field_vis,
|
visibility: field_vis,
|
||||||
ident: field_ident,
|
ident: field_ident,
|
||||||
ty: field_ty,
|
ty: field_ty,
|
||||||
inner_type: inner_type,
|
inner_type,
|
||||||
primary_key: is_primary_key,
|
primary_key: is_primary_key,
|
||||||
html_input_type: html_input_type,
|
html_input_type,
|
||||||
select_list: select_list,
|
select_list,
|
||||||
searchable: is_searchable,
|
searchable: is_searchable,
|
||||||
textarea: is_textarea,
|
textarea: is_textarea,
|
||||||
file_upload: is_file_upload,
|
file_upload: is_file_upload,
|
||||||
not_empty: is_not_empty,
|
not_empty: is_not_empty,
|
||||||
list_sort_position: list_sort_position,
|
list_sort_position,
|
||||||
list_hide_column: is_list_hide_column,
|
list_hide_column: is_list_hide_column,
|
||||||
list_regex_mask: list_regex_mask
|
list_regex_mask,
|
||||||
};
|
};
|
||||||
Some(model_field)
|
Some(model_field)
|
||||||
} else {
|
} else {
|
||||||
|
@ -106,13 +106,14 @@ fn get_regex_val<S: BuildHasher>(
|
|||||||
let field = try_get_value!("get_regex_val", "value", ActixAdminViewModelField, value);
|
let field = try_get_value!("get_regex_val", "value", ActixAdminViewModelField, value);
|
||||||
|
|
||||||
let s = args.get("values");
|
let s = args.get("values");
|
||||||
let field_val = s.unwrap().get(&field.field_name);
|
let field_val = s.unwrap().get(field.field_name());
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"field {} regex {:?}",
|
"field {} regex {:?}",
|
||||||
field.field_name, field.list_regex_mask
|
field.field_name(),
|
||||||
|
field.list_regex_mask
|
||||||
);
|
);
|
||||||
match (field_val, field.list_regex_mask) {
|
match (field_val, &field.list_regex_mask) {
|
||||||
(Some(val), Some(r)) => {
|
(Some(val), Some(r)) => {
|
||||||
let val_str = val.to_string();
|
let val_str = val.to_string();
|
||||||
let is_match = r.is_match(&val_str);
|
let is_match = r.is_match(&val_str);
|
||||||
@ -123,7 +124,7 @@ fn get_regex_val<S: BuildHasher>(
|
|||||||
(Some(val), None) => {
|
(Some(val), None) => {
|
||||||
return Ok(to_value(val).unwrap());
|
return Ok(to_value(val).unwrap());
|
||||||
}
|
}
|
||||||
(_, _) => panic!("key {} not found in model values", &field.field_name),
|
(_, _) => panic!("key {} not found in model values", field.field_name()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +206,8 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
|
|||||||
actix_admin: ActixAdmin {
|
actix_admin: ActixAdmin {
|
||||||
entity_names: HashMap::new(),
|
entity_names: HashMap::new(),
|
||||||
view_models: HashMap::new(),
|
view_models: HashMap::new(),
|
||||||
configuration: configuration,
|
|
||||||
tera: crate::tera_templates::get_tera()
|
tera: crate::tera_templates::get_tera()
|
||||||
|
configuration,
|
||||||
},
|
},
|
||||||
custom_routes: Vec::new(),
|
custom_routes: Vec::new(),
|
||||||
scopes: HashMap::new(),
|
scopes: HashMap::new(),
|
||||||
@ -261,11 +262,9 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
|
|||||||
match category {
|
match category {
|
||||||
Some(entity_list) => entity_list.push(menu_element),
|
Some(entity_list) => entity_list.push(menu_element),
|
||||||
None => {
|
None => {
|
||||||
let mut entity_list = Vec::new();
|
|
||||||
entity_list.push(menu_element);
|
|
||||||
self.actix_admin
|
self.actix_admin
|
||||||
.entity_names
|
.entity_names
|
||||||
.insert(category_name.to_string(), entity_list);
|
.insert(category_name.to_string(), vec![menu_element]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,11 @@ impl ActixAdminModel {
|
|||||||
while let Some(item) = payload.next().await {
|
while let Some(item) = payload.next().await {
|
||||||
let mut field = item?;
|
let mut field = item?;
|
||||||
|
|
||||||
eprintln!("FIELD NAME {:?}, FILENAME {:?}", field.name(), field.content_disposition().get_filename());
|
eprintln!(
|
||||||
|
"FIELD NAME {:?}, FILENAME {:?}",
|
||||||
|
field.name(),
|
||||||
|
field.content_disposition().get_filename()
|
||||||
|
);
|
||||||
|
|
||||||
let mut binary_data: Vec<Bytes> = Vec::new();
|
let mut binary_data: Vec<Bytes> = Vec::new();
|
||||||
while let Some(chunk) = field.next().await {
|
while let Some(chunk) = field.next().await {
|
||||||
|
@ -35,7 +35,7 @@ pub async fn delete<E: ActixAdminViewModelTrait>(
|
|||||||
for field in view_model.fields {
|
for field in view_model.fields {
|
||||||
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
|
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
|
||||||
let file_name = model
|
let file_name = model
|
||||||
.get_value::<String>(&field.field_name, true, true)
|
.get_value::<String>(field.field_name(), true, true)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if file_name.is_some() {
|
if file_name.is_some() {
|
||||||
let file_path = format!(
|
let file_path = format!(
|
||||||
@ -93,7 +93,7 @@ pub async fn delete_many<E: ActixAdminViewModelTrait>(
|
|||||||
for field in view_model.fields {
|
for field in view_model.fields {
|
||||||
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
|
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
|
||||||
let file_name = model
|
let file_name = model
|
||||||
.get_value::<String>(&field.field_name, true, true)
|
.get_value::<String>(field.field_name(), true, true)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
if file_name.is_some() {
|
if file_name.is_some() {
|
||||||
let file_path = format!(
|
let file_path = format!(
|
||||||
|
@ -99,7 +99,7 @@ pub async fn delete_file<E: ActixAdminViewModelTrait>(
|
|||||||
let view_model_field = &view_model
|
let view_model_field = &view_model
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.find(|field| field.field_name == column_name)
|
.find(|field| field.field_name() == column_name)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ctx.insert("model_field", view_model_field);
|
ctx.insert("model_field", view_model_field);
|
||||||
ctx.insert("base_path", &E::get_base_path(&entity_name));
|
ctx.insert("base_path", &E::get_base_path(&entity_name));
|
||||||
|
@ -39,8 +39,8 @@ pub fn replace_regex(view_model: &ActixAdminViewModel, models: &mut Vec<ActixAdm
|
|||||||
models.into_iter().for_each(|m| {
|
models.into_iter().for_each(|m| {
|
||||||
let regex = f.list_regex_mask.as_ref().unwrap();
|
let regex = f.list_regex_mask.as_ref().unwrap();
|
||||||
let field = f;
|
let field = f;
|
||||||
let vals = &mut m.values;
|
m.values
|
||||||
vals.entry(field.field_name.to_string())
|
.entry(field.field_name().to_string())
|
||||||
.and_modify(|f| *f = regex.replace_all(f, "****").to_string());
|
.and_modify(|f| *f = regex.replace_all(f, "****").to_string());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -268,4 +268,4 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -116,6 +116,12 @@ pub struct ActixAdminViewModelField {
|
|||||||
pub list_regex_mask: Option<Regex>,
|
pub list_regex_mask: Option<Regex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ActixAdminViewModelField {
|
||||||
|
pub fn field_name(&self) -> &str {
|
||||||
|
self.field_name.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActixAdminViewModelFieldType {
|
impl ActixAdminViewModelFieldType {
|
||||||
pub fn get_field_type(
|
pub fn get_field_type(
|
||||||
type_path: &str,
|
type_path: &str,
|
||||||
|
Loading…
Reference in New Issue
Block a user