use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModelInfo {
pub name: String,
pub list_url: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldInfo {
pub name: String,
pub label: String,
pub field_type: FieldType,
pub required: bool,
pub readonly: bool,
pub help_text: Option<String>,
pub placeholder: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", content = "options")]
pub enum FieldType {
Text,
TextArea,
Number,
Boolean,
Email,
Date,
DateTime,
Select {
choices: Vec<(String, String)>,
},
MultiSelect {
choices: Vec<(String, String)>,
},
File,
Hidden,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", content = "data")]
pub enum FormFieldSpec {
Input {
html_type: String,
},
TextArea,
Select {
choices: Vec<(String, String)>,
},
MultiSelect {
choices: Vec<(String, String)>,
},
File,
Hidden,
}
impl From<&FieldType> for FormFieldSpec {
fn from(field_type: &FieldType) -> Self {
match field_type {
FieldType::Text => FormFieldSpec::Input {
html_type: "text".to_string(),
},
FieldType::Number => FormFieldSpec::Input {
html_type: "number".to_string(),
},
FieldType::Boolean => FormFieldSpec::Input {
html_type: "checkbox".to_string(),
},
FieldType::Email => FormFieldSpec::Input {
html_type: "email".to_string(),
},
FieldType::Date => FormFieldSpec::Input {
html_type: "date".to_string(),
},
FieldType::DateTime => FormFieldSpec::Input {
html_type: "datetime-local".to_string(),
},
FieldType::TextArea => FormFieldSpec::TextArea,
FieldType::Select { choices } => FormFieldSpec::Select {
choices: choices.clone(),
},
FieldType::MultiSelect { choices } => FormFieldSpec::MultiSelect {
choices: choices.clone(),
},
FieldType::File => FormFieldSpec::File,
FieldType::Hidden => FormFieldSpec::Hidden,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", content = "options")]
pub enum FilterType {
Boolean,
Choice {
choices: Vec<FilterChoice>,
},
DateRange {
ranges: Vec<FilterChoice>,
},
NumberRange {
ranges: Vec<FilterChoice>,
},
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FilterChoice {
pub value: String,
pub label: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterInfo {
pub field: String,
pub title: String,
pub filter_type: FilterType,
pub current_value: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnInfo {
pub field: String,
pub label: String,
pub sortable: bool,
}