2022-06-06 15:25:37 +02:00
|
|
|
use syn::{
|
|
|
|
Visibility, Type
|
|
|
|
};
|
2022-07-27 17:35:45 +02:00
|
|
|
use quote::ToTokens;
|
2022-06-06 15:25:37 +02:00
|
|
|
|
|
|
|
pub struct ModelField {
|
|
|
|
pub visibility: Visibility,
|
|
|
|
pub ident: proc_macro2::Ident,
|
|
|
|
pub ty: Type,
|
|
|
|
pub inner_type: Option<Type>,
|
2022-07-17 22:12:18 +02:00
|
|
|
pub primary_key: bool,
|
2022-07-21 19:01:05 +02:00
|
|
|
pub html_input_type: String,
|
2022-07-31 16:33:02 +02:00
|
|
|
pub select_list: String,
|
2022-08-20 23:31:45 +02:00
|
|
|
pub searchable: bool,
|
2022-12-29 19:56:20 +01:00
|
|
|
pub textarea: bool,
|
|
|
|
pub file_upload: bool,
|
2023-01-15 14:11:23 +01:00
|
|
|
pub not_empty: bool,
|
2023-01-15 14:18:46 +01:00
|
|
|
pub list_sort_position: usize,
|
|
|
|
pub list_hide_column: bool
|
2022-06-06 15:25:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ModelField {
|
|
|
|
pub fn is_option(&self) -> bool {
|
|
|
|
self.inner_type.is_some()
|
|
|
|
}
|
2022-07-27 17:35:45 +02:00
|
|
|
|
|
|
|
pub fn is_string(&self) -> bool {
|
|
|
|
match &self.ty {
|
|
|
|
Type::Path(type_path) if type_path.clone().into_token_stream().to_string() == "String" => {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 17:44:40 +02:00
|
|
|
|
|
|
|
pub fn get_type_path_string(&self) -> String {
|
|
|
|
let type_path_string: String;
|
|
|
|
if self.is_option() {
|
|
|
|
match &self.inner_type.clone().unwrap() {
|
|
|
|
Type::Path(type_path) => type_path_string = type_path.clone().into_token_stream().to_string(),
|
|
|
|
_ => panic!("not a type path")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
match &self.ty {
|
|
|
|
Type::Path(type_path) => type_path_string = type_path.clone().into_token_stream().to_string(),
|
|
|
|
_ => panic!("not a type path")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type_path_string
|
|
|
|
}
|
2022-06-06 15:25:37 +02:00
|
|
|
}
|