remove duplicate methods
This commit is contained in:
parent
bb73f3346e
commit
ef4baa499d
@ -143,21 +143,21 @@ pub fn derive_actix_admin_view_model(input: proc_macro::TokenStream) -> proc_mac
|
|||||||
pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
let fields = get_fields_for_tokenstream(input);
|
let fields = get_fields_for_tokenstream(input);
|
||||||
|
|
||||||
let field_names = get_actix_admin_fields(&fields);
|
let field_names = get_fields_as_tokenstream(&fields, |model_field| -> String { model_field.ident.to_string() });
|
||||||
let field_html_input_type = get_actix_admin_fields_html_input(&fields);
|
let field_html_input_type = get_fields_as_tokenstream(&fields, |model_field| -> String { model_field.html_input_type.to_string() });
|
||||||
let field_select_list = get_actix_admin_fields_select_list(&fields);
|
let field_select_list = get_fields_as_tokenstream(&fields, |model_field| -> String { model_field.select_list.to_string() });
|
||||||
let is_option_list = get_actix_admin_fields_is_option_list(&fields);
|
let is_option_list = get_fields_as_tokenstream(&fields, |model_field| -> bool { model_field.is_option() });
|
||||||
let fields_for_create_model = get_fields_for_create_model(&fields);
|
let fields_for_create_model = get_fields_for_create_model(&fields);
|
||||||
let fields_for_from_model = get_fields_for_from_model(&fields);
|
let fields_for_from_model = get_fields_for_from_model(&fields);
|
||||||
let field_for_primary_key = get_field_for_primary_key(&fields);
|
let field_for_primary_key = get_field_for_primary_key(&fields);
|
||||||
let fields_for_validate_model = get_fields_for_validate_model(&fields);
|
let fields_for_validate_model = get_fields_for_validate_model(&fields);
|
||||||
let fields_searchable = get_actix_admin_fields_searchable(&fields);
|
let fields_type_path = get_fields_as_tokenstream(&fields, |model_field| -> String { model_field.get_type_path_string() });
|
||||||
let fields_type_path = get_actix_admin_fields_type_path_string(&fields);
|
let fields_textarea = get_fields_as_tokenstream(&fields, |model_field| -> bool { model_field.textarea });
|
||||||
let fields_textarea = get_actix_admin_fields_textarea(&fields);
|
let fields_file_upload = get_fields_as_tokenstream(&fields, |model_field| -> bool { model_field.file_upload });
|
||||||
let fields_file_upload = get_actix_admin_fields_file_upload(&fields);
|
|
||||||
let fields_match_name_to_columns = get_match_name_to_column(&fields);
|
let fields_match_name_to_columns = get_match_name_to_column(&fields);
|
||||||
let fields_list_sort_positions = get_fields_list_sort_positions(&fields);
|
let fields_list_sort_positions = get_fields_as_tokenstream(&fields, |model_field| -> usize { model_field.list_sort_position });
|
||||||
let fields_list_hide_column = get_fields_list_hide_column(&fields);
|
let fields_list_hide_column = get_fields_as_tokenstream(&fields, |model_field| -> bool { model_field.list_hide_column });
|
||||||
|
let fields_searchable = get_actix_admin_fields_searchable(&fields);
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
actix_admin::prelude::lazy_static! {
|
actix_admin::prelude::lazy_static! {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::attributes::derive_attr;
|
use crate::attributes::derive_attr;
|
||||||
use crate::model_fields::ModelField;
|
use crate::model_fields::ModelField;
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::quote;
|
use quote::{quote, ToTokens};
|
||||||
use syn::{DeriveInput, Fields, LitStr, Ident};
|
use syn::{DeriveInput, Fields, LitStr, Ident};
|
||||||
|
|
||||||
pub fn get_fields_for_tokenstream(input: proc_macro::TokenStream) -> std::vec::Vec<ModelField> {
|
pub fn get_fields_for_tokenstream(input: proc_macro::TokenStream) -> std::vec::Vec<ModelField> {
|
||||||
@ -144,88 +144,18 @@ fn extract_type_from_option(ty: &syn::Type) -> Option<syn::Type> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_actix_admin_fields(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
pub fn get_fields_as_tokenstream<T: ToTokens>(fields: &Vec<ModelField>, accessor: fn(&ModelField) -> T) -> Vec<TokenStream> {
|
||||||
fields
|
fields
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|model_field| !model_field.primary_key)
|
.filter(|model_field| !model_field.primary_key)
|
||||||
.map(|model_field| {
|
.map(|model_field| {
|
||||||
let ident_name = model_field.ident.to_string();
|
let ident_name = accessor(model_field);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#ident_name
|
#ident_name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_is_option_list(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let is_option = model_field.is_option();
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#is_option
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_type_path_string(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let type_path_string = model_field.get_type_path_string();
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#type_path_string
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_html_input(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let html_input_type = model_field.html_input_type.to_string();
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#html_input_type
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_textarea(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let is_textarea = model_field.textarea;
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#is_textarea
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_file_upload(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let is_fileupload = model_field.file_upload;
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#is_fileupload
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_match_name_to_column(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
pub fn get_match_name_to_column(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
||||||
@ -256,20 +186,6 @@ pub fn get_actix_admin_fields_searchable(fields: &Vec<ModelField>) -> Vec<TokenS
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_actix_admin_fields_select_list(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let select_list = model_field.select_list.to_string();
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#select_list
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_field_for_primary_key(fields: &Vec<ModelField>) -> TokenStream {
|
pub fn get_field_for_primary_key(fields: &Vec<ModelField>) -> TokenStream {
|
||||||
let primary_key_model_field = fields
|
let primary_key_model_field = fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -294,34 +210,6 @@ pub fn get_primary_key_field_name(fields: &Vec<ModelField>) -> String {
|
|||||||
primary_key_model_field.ident.to_string()
|
primary_key_model_field.ident.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_fields_list_sort_positions(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let sort_position = model_field.list_sort_position;
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#sort_position
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_fields_list_hide_column(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
|
||||||
fields
|
|
||||||
.iter()
|
|
||||||
.filter(|model_field| !model_field.primary_key)
|
|
||||||
.map(|model_field| {
|
|
||||||
let list_hide_column = model_field.list_hide_column;
|
|
||||||
|
|
||||||
quote! {
|
|
||||||
#list_hide_column
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_fields_for_from_model(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
pub fn get_fields_for_from_model(fields: &Vec<ModelField>) -> Vec<TokenStream> {
|
||||||
fields
|
fields
|
||||||
.iter()
|
.iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user