]> saetta.ns0.it Git - rust/zakform/commitdiff
Filters' support.
authorAndrea Zagli <azagli@libero.it>
Sat, 4 Mar 2023 11:53:59 +0000 (12:53 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 4 Mar 2023 11:53:59 +0000 (12:53 +0100)
src/fields.rs

index 20a138df1138462fdcc51459a5f52cd162625ad5..38f16b14c363f025fb4849ef4ac93125a92ae987 100644 (file)
@@ -34,6 +34,10 @@ pub trait TField {
        fn get_value(&self) -> String;
        fn set_value(&mut self, value: &str);
 
+       fn add_filter(&mut self, filter: super::filters::Filter);
+
+       fn filter(&mut self);
+
        fn render(&self) -> String;
 
        fn any(&mut self) -> &mut dyn Any;
@@ -90,6 +94,16 @@ impl TField for FieldText {
                self.field.value = String::from(value);
        }
 
+       fn add_filter(&mut self, filter: super::filters::Filter) {
+               self.field.filters.push(filter);
+       }
+
+       fn filter(&mut self) {
+               for f in &self.field.filters {
+                       self.field.value = (f)(&self.field.value);
+               }
+       }
+
        fn render(&self) -> String {
                let mut s = String::new();
 
@@ -191,6 +205,16 @@ impl TField for FieldTextArea {
                self.field.value = String::from(value);
        }
 
+       fn add_filter(&mut self, filter: super::filters::Filter) {
+               self.field.filters.push(filter);
+       }
+
+       fn filter(&mut self) {
+               for f in &self.field.filters {
+                       self.field.value = (f)(&self.field.value);
+               }
+       }
+
        fn render(&self) -> String {
                let mut s = String::new();
 
@@ -309,6 +333,16 @@ impl TField for FieldRadio {
                self.field.value = String::from(value);
        }
 
+       fn add_filter(&mut self, filter: super::filters::Filter) {
+               self.field.filters.push(filter);
+       }
+
+       fn filter(&mut self) {
+               for f in &self.field.filters {
+                       self.field.value = (f)(&self.field.value);
+               }
+       }
+
        fn render(&self) -> String {
                let mut s = String::new();
 
@@ -443,6 +477,16 @@ impl TField for FieldSelect {
                self.field.value = String::from(value);
        }
 
+       fn add_filter(&mut self, filter: super::filters::Filter) {
+               self.field.filters.push(filter);
+       }
+
+       fn filter(&mut self) {
+               for f in &self.field.filters {
+                       self.field.value = (f)(&self.field.value);
+               }
+       }
+
        fn render(&self) -> String {
                let mut s = String::new();
 
@@ -542,6 +586,16 @@ impl TField for FieldCheck {
                self.field.value = String::from(value);
        }
 
+       fn add_filter(&mut self, filter: super::filters::Filter) {
+               self.field.filters.push(filter);
+       }
+
+       fn filter(&mut self) {
+               for f in &self.field.filters {
+                       self.field.value = (f)(&self.field.value);
+               }
+       }
+
        fn render(&self) -> String {
                let mut s = String::new();