finally another commit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use core::fmt;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use egui::ScrollArea;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -16,7 +17,7 @@ pub enum FieldType {
|
||||
MultiLine,
|
||||
Date,
|
||||
Number,
|
||||
Link,
|
||||
Link { template_id: Option<String> },
|
||||
Links,
|
||||
}
|
||||
|
||||
@@ -34,17 +35,54 @@ impl FieldType {
|
||||
FieldType::MultiLine,
|
||||
FieldType::Date,
|
||||
FieldType::Number,
|
||||
FieldType::Link,
|
||||
FieldType::Link { template_id: None },
|
||||
FieldType::Links,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum FieldValue {
|
||||
Image(String),
|
||||
SingleLine(String),
|
||||
MultiLine(String),
|
||||
Date(NaiveDate),
|
||||
Number(f64),
|
||||
Link(String),
|
||||
Links(Vec<String>),
|
||||
}
|
||||
|
||||
impl FieldValue {
|
||||
pub fn from_type(_type: &FieldType) -> Self {
|
||||
match _type {
|
||||
FieldType::Image => Self::Image(String::new()),
|
||||
FieldType::SingleLine => Self::SingleLine(String::new()),
|
||||
FieldType::MultiLine => Self::MultiLine(String::new()),
|
||||
FieldType::Date => Self::Date(NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()),
|
||||
FieldType::Number => Self::Number(0.0),
|
||||
FieldType::Link { template_id: None } => Self::Link(String::new()),
|
||||
FieldType::Link {
|
||||
template_id: Some(template_id),
|
||||
} => Self::Link(template_id.clone()),
|
||||
FieldType::Links => Self::Links(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FieldValue {
|
||||
fn default() -> Self {
|
||||
Self::SingleLine(String::new())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FieldDefinition {
|
||||
pub name: String,
|
||||
pub field_type: FieldType,
|
||||
pub required: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub on_preview: bool,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
@@ -73,6 +111,9 @@ pub struct Template {
|
||||
|
||||
#[serde(skip)]
|
||||
pub new_field_description: String,
|
||||
|
||||
#[serde(skip)]
|
||||
pub new_field_on_preview: bool,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Template {
|
||||
@@ -105,6 +146,7 @@ impl Clone for Template {
|
||||
new_field_type: FieldType::default(),
|
||||
new_field_required: false,
|
||||
new_field_description: "".to_string(),
|
||||
new_field_on_preview: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,6 +165,7 @@ impl Default for Template {
|
||||
new_field_type: FieldType::default(),
|
||||
new_field_required: false,
|
||||
new_field_description: "".to_string(),
|
||||
new_field_on_preview: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,6 +368,12 @@ impl Template {
|
||||
}
|
||||
ui.end_row();
|
||||
|
||||
ui.label("On Preview:");
|
||||
if ui.checkbox(&mut field.on_preview, "").clicked() {
|
||||
self.saved = false;
|
||||
}
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Description:");
|
||||
if ui
|
||||
.text_edit_singleline(
|
||||
@@ -377,6 +426,10 @@ impl Template {
|
||||
ui.checkbox(&mut self.new_field_required, "");
|
||||
ui.end_row();
|
||||
|
||||
ui.label("On Preview:");
|
||||
ui.checkbox(&mut self.new_field_on_preview, "");
|
||||
ui.end_row();
|
||||
|
||||
ui.label("Description:");
|
||||
ui.text_edit_singleline(&mut self.new_field_description);
|
||||
ui.end_row();
|
||||
@@ -385,6 +438,7 @@ impl Template {
|
||||
self.fields.push(FieldDefinition {
|
||||
name: self.new_field_name.clone(),
|
||||
field_type: self.new_field_type.clone(),
|
||||
on_preview: self.new_field_on_preview,
|
||||
required: self.new_field_required,
|
||||
description: if self.new_field_description.is_empty() {
|
||||
None
|
||||
@@ -404,10 +458,3 @@ impl Template {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct FieldValue {
|
||||
pub value: String,
|
||||
#[serde(skip)]
|
||||
pub modified: bool,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user