Fix field name

This commit is contained in:
Adrian Woźniak 2023-07-31 17:03:05 +02:00
parent ae072d1812
commit c473e35566
10 changed files with 34 additions and 25 deletions

View File

@ -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) {
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 mut list_regex_mask_regex = None;
if list_regex_mask != "" {
@ -261,8 +261,8 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
};
vec.push(ActixAdminViewModelField {
field_name: field_name,
html_input_type: html_input_type,
field_name,
html_input_type,
select_list: select_list.clone(),
is_option: is_option_list,
list_sort_position: list_sort_position,

View File

@ -37,7 +37,7 @@ impl ModelField {
pub fn get_type_path_string(&self) -> String {
let type_path_string: String;
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(),
_ => panic!("not a type path")
}
@ -50,4 +50,4 @@ impl ModelField {
type_path_string
}
}
}

View File

@ -87,17 +87,17 @@ pub fn filter_fields(fields: &Fields) -> Vec<ModelField> {
visibility: field_vis,
ident: field_ident,
ty: field_ty,
inner_type: inner_type,
inner_type,
primary_key: is_primary_key,
html_input_type: html_input_type,
select_list: select_list,
html_input_type,
select_list,
searchable: is_searchable,
textarea: is_textarea,
file_upload: is_file_upload,
not_empty: is_not_empty,
list_sort_position: list_sort_position,
list_sort_position,
list_hide_column: is_list_hide_column,
list_regex_mask: list_regex_mask
list_regex_mask,
};
Some(model_field)
} else {

View File

@ -106,13 +106,14 @@ fn get_regex_val<S: BuildHasher>(
let field = try_get_value!("get_regex_val", "value", ActixAdminViewModelField, value);
let s = args.get("values");
let field_val = s.unwrap().get(&field.field_name);
let field_val = s.unwrap().get(field.field_name());
println!(
"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)) => {
let val_str = val.to_string();
let is_match = r.is_match(&val_str);
@ -123,7 +124,7 @@ fn get_regex_val<S: BuildHasher>(
(Some(val), None) => {
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 {
entity_names: HashMap::new(),
view_models: HashMap::new(),
configuration: configuration,
tera: crate::tera_templates::get_tera()
configuration,
},
custom_routes: Vec::new(),
scopes: HashMap::new(),
@ -261,11 +262,9 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
match category {
Some(entity_list) => entity_list.push(menu_element),
None => {
let mut entity_list = Vec::new();
entity_list.push(menu_element);
self.actix_admin
.entity_names
.insert(category_name.to_string(), entity_list);
.insert(category_name.to_string(), vec![menu_element]);
}
}

View File

@ -101,7 +101,11 @@ impl ActixAdminModel {
while let Some(item) = payload.next().await {
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();
while let Some(chunk) = field.next().await {

View File

@ -35,7 +35,7 @@ pub async fn delete<E: ActixAdminViewModelTrait>(
for field in view_model.fields {
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
let file_name = model
.get_value::<String>(&field.field_name, true, true)
.get_value::<String>(field.field_name(), true, true)
.unwrap_or_default();
if file_name.is_some() {
let file_path = format!(
@ -93,7 +93,7 @@ pub async fn delete_many<E: ActixAdminViewModelTrait>(
for field in view_model.fields {
if field.field_type == ActixAdminViewModelFieldType::FileUpload {
let file_name = model
.get_value::<String>(&field.field_name, true, true)
.get_value::<String>(field.field_name(), true, true)
.unwrap_or_default();
if file_name.is_some() {
let file_path = format!(

View File

@ -99,7 +99,7 @@ pub async fn delete_file<E: ActixAdminViewModelTrait>(
let view_model_field = &view_model
.fields
.iter()
.find(|field| field.field_name == column_name)
.find(|field| field.field_name() == column_name)
.unwrap();
ctx.insert("model_field", view_model_field);
ctx.insert("base_path", &E::get_base_path(&entity_name));

View File

@ -39,8 +39,8 @@ pub fn replace_regex(view_model: &ActixAdminViewModel, models: &mut Vec<ActixAdm
models.into_iter().for_each(|m| {
let regex = f.list_regex_mask.as_ref().unwrap();
let field = f;
let vals = &mut m.values;
vals.entry(field.field_name.to_string())
m.values
.entry(field.field_name().to_string())
.and_modify(|f| *f = regex.replace_all(f, "****").to_string());
})
});

View File

@ -268,4 +268,4 @@
</nav>
</div>
{% endblock content %}
{% endblock content %}

View File

@ -116,6 +116,12 @@ pub struct ActixAdminViewModelField {
pub list_regex_mask: Option<Regex>,
}
impl ActixAdminViewModelField {
pub fn field_name(&self) -> &str {
self.field_name.trim()
}
}
impl ActixAdminViewModelFieldType {
pub fn get_field_type(
type_path: &str,