]> saetta.ns0.it Git - rust/zakform/commitdiff
Added field property db_type.
authorAndrea Zagli <azagli@libero.it>
Sun, 5 Mar 2023 09:11:21 +0000 (10:11 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 5 Mar 2023 09:11:21 +0000 (10:11 +0100)
src/fields.rs

index c4823ee6d93311db76ee930060968dd355fe680c..3ce50ed29ceca46dacb3b8fbb175b94c6260b238 100644 (file)
@@ -4,6 +4,16 @@ use std::any::Any;
 
 use serde_derive::{Serialize};
 
+#[derive(Default, Clone, Copy)]
+pub enum FieldDbType {
+       #[default]
+       Text,
+       Integer,
+       Float,
+       Date,
+       DateTime,
+}
+
 #[derive(Default)]
 struct Field {
        name: String,
@@ -15,6 +25,7 @@ struct Field {
        to_load: bool,
        to_save: bool,
        to_render: bool,
+       db_type: FieldDbType,
        tmpl: tera::Tera,
        filters: Vec<super::filters::Filter>,
 }
@@ -46,6 +57,9 @@ pub trait TField {
        fn get_to_render(&self) -> bool;
        fn set_to_render(&mut self, to_render: bool);
 
+       fn get_db_type(&self) -> FieldDbType;
+       fn set_db_type(&mut self, db_type: FieldDbType);
+
        fn add_filter(&mut self, filter: super::filters::Filter);
 
        fn filter(&mut self);
@@ -132,6 +146,14 @@ impl TField for FieldText {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }
@@ -280,6 +302,14 @@ impl TField for FieldTextArea {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }
@@ -445,6 +475,14 @@ impl TField for FieldRadio {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }
@@ -626,6 +664,14 @@ impl TField for FieldSelect {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }
@@ -772,6 +818,14 @@ impl TField for FieldCheck {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }
@@ -910,6 +964,14 @@ impl TField for FieldButton {
                self.field.to_render = render;
        }
 
+       fn get_db_type(&self) -> FieldDbType {
+               self.field.db_type
+       }
+
+       fn set_db_type(&mut self, db_type: FieldDbType) {
+               self.field.db_type = db_type;
+       }
+
        fn add_filter(&mut self, filter: super::filters::Filter) {
                self.field.filters.push(filter);
        }