diff --git a/README.md b/README.md index e992455..c6b6268 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ In ihr sind die durchzuführenden Änderungen definiert. Eine Profildatei hat di ``` forms: - name: "ExampleForm" + form_field: + - name: "formularfeld" + hide: true form_references: - name: "ref_first_mtb" referenced_data_form: "Formularverweis.Variante" @@ -119,6 +122,12 @@ und dabei die vorhandenen Angaben für den Formularverweis zu ersetzen. Die Angaben für `referenced_data_form`, `anzeige_auswahl`, `anzeige` und `scripts_code` sind optional. Wird keine Angabe gemacht, wird der bestehende Wert beibehalten. +Zudem wird im Formular "ExampleForm" das Formularfeld "formularfeld" ausgeblendet, indem der Filter auf "false" gesetzt wird. +Dadurch wird das Formularfeld nie angezeigt. +Ein zuvor bestehender Filter wird ersetzt. +Weiterhin wird die Eigenschaft "Speichern" des Formularfelds auf "Immer speichern" gesetzt um sicherzustellen, dass zuvor +enthaltene Daten weiterhin gespeichert bleiben und werden, auch wenn das Formularfeld nicht sichtbar ist. + **Achtung!** Diese Anwendung überprüft keine Scripts und verwendet angegebene Scripts als "valid" im resultierenden OSC-File. Zudem kann die Menükategorie angepasst werden. diff --git a/src/model/data_form.rs b/src/model/data_form.rs index 5fd2ffa..027ce15 100644 --- a/src/model/data_form.rs +++ b/src/model/data_form.rs @@ -30,8 +30,9 @@ use serde::{Deserialize, Serialize}; use crate::model::onkostar_editor::OnkostarEditor; use crate::model::requirements::{Requirement, Requires}; use crate::model::{ - apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry, - FormEntryContainer, Listable, MenuCategory, PlausibilityRules, Script, Sortable, + apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries, + Filter, FolderContent, FormEntry, FormEntryContainer, Listable, MenuCategory, + PlausibilityRules, RefEntries, Script, Sortable, }; use crate::model::{Haeufigkeiten, Ordner}; use crate::profile::Profile; @@ -169,6 +170,12 @@ impl FormEntryContainer for DataForm { apply_profile_to_form_entry(entry, form_reference) }); + // Hide form field using filter set to "false" if requested + profile_form + .form_fields + .iter() + .for_each(|form_field| apply_profile_to_form_field(entry, form_field)); + if let Some(menu_category) = &profile_form.menu_category { self.menu_category = Some(MenuCategory { name: menu_category.name.clone(), @@ -525,6 +532,15 @@ impl FormEntry for Entry { valid: true, }); } + + fn hide(&mut self) { + self.filter = Some(Filter { + condition: "false".into(), + valid: true, + ref_entries: Some(RefEntries { ref_entry: None }), + }); + self.speichern = "0".into() + } } impl Sortable for Entry { diff --git a/src/model/mod.rs b/src/model/mod.rs index 18f8094..6026157 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -28,7 +28,7 @@ use std::hash::{Hash, Hasher}; use serde::{Deserialize, Serialize}; -use crate::profile::{FormReference, Profile}; +use crate::profile::{FormField, FormReference, Profile}; pub mod data_catalogue; pub mod data_form; @@ -232,6 +232,15 @@ where } } +fn apply_profile_to_form_field(entry: &mut E, form_field: &FormField) +where + E: FormEntry, +{ + if entry.get_name() == form_field.name && form_field.hide { + entry.hide() + } +} + pub trait FormEntryContainer { fn apply_profile(&mut self, profile: &Profile); } @@ -267,6 +276,7 @@ pub trait FormEntry { fn update_anzeige(&mut self, value: String); fn update_anzeige_auswahl(&mut self, value: String); fn update_scripts_code(&mut self, value: String); + fn hide(&mut self); } pub trait FolderContent { diff --git a/src/model/unterformular.rs b/src/model/unterformular.rs index f3a7509..d83cfce 100644 --- a/src/model/unterformular.rs +++ b/src/model/unterformular.rs @@ -30,8 +30,9 @@ use serde::{Deserialize, Serialize}; use crate::model::onkostar_editor::OnkostarEditor; use crate::model::requirements::{Requirement, Requires}; use crate::model::{ - apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry, - FormEntryContainer, Listable, MenuCategory, PlausibilityRules, Script, Sortable, + apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries, + Filter, FolderContent, FormEntry, FormEntryContainer, Listable, MenuCategory, + PlausibilityRules, RefEntries, Script, Sortable, }; use crate::model::{Haeufigkeiten, Ordner}; use crate::profile::Profile; @@ -180,6 +181,12 @@ impl FormEntryContainer for Unterformular { apply_profile_to_form_entry(entry, form_reference) }); + // Hide form field using filter set to "false" if requested + profile_form + .form_fields + .iter() + .for_each(|form_field| apply_profile_to_form_field(entry, form_field)); + if let Some(menu_category) = &profile_form.menu_category { self.menu_category = Some(MenuCategory { name: menu_category.name.clone(), @@ -548,6 +555,15 @@ impl FormEntry for Entry { valid: true, }); } + + fn hide(&mut self) { + self.filter = Some(Filter { + condition: "false".into(), + valid: true, + ref_entries: Some(RefEntries { ref_entry: None }), + }); + self.speichern = "0".into() + } } impl Sortable for Entry { diff --git a/src/profile.rs b/src/profile.rs index d5db16f..8171331 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -50,6 +50,8 @@ pub struct Form { pub name: String, #[serde(default)] pub form_references: Vec, + #[serde(default)] + pub form_fields: Vec, pub menu_category: Option, } @@ -68,6 +70,13 @@ impl FormReference { } } +#[derive(Deserialize)] +pub struct FormField { + pub name: String, + #[serde(default)] + pub hide: bool, +} + #[derive(Deserialize)] pub struct MenuCategory { pub name: String, @@ -93,6 +102,9 @@ mod tests { referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' anzeige: 'Datum: {Datum}' anzeige_auswahl: 'TK vom {Datum}' + form_fields: + - name: eingabefeld + hide: true "; match Profile::from_str(content) { @@ -101,6 +113,7 @@ mod tests { assert_eq!(profile.forms[0].name, "DNPM Therapieplan"); assert!(profile.forms[0].menu_category.is_some()); assert_eq!(profile.forms[0].form_references.len(), 1); + assert_eq!(profile.forms[0].form_fields.len(), 1) } Err(e) => panic!("Cannot deserialize profile: {}", e), } @@ -212,4 +225,29 @@ mod tests { let actual = Profile::from_str(content); assert!(actual.is_err()); } + + #[test] + fn should_deserialize_form_fields() { + let content = "forms: + - name: 'DNPM Therapieplan' + form_fields: + - name: formularfeld_to_keep + hide: false + - name: formularfeld_to_hide + hide: true + "; + + match Profile::from_str(content) { + Ok(profile) => { + assert_eq!(profile.forms.len(), 1); + assert_eq!(profile.forms[0].name, "DNPM Therapieplan"); + assert_eq!(profile.forms[0].form_fields.len(), 2); + assert_eq!(profile.forms[0].form_fields[0].name, "formularfeld_to_keep"); + assert!(!profile.forms[0].form_fields[0].hide); + assert_eq!(profile.forms[0].form_fields[1].name, "formularfeld_to_hide"); + assert!(profile.forms[0].form_fields[1].hide); + } + Err(e) => panic!("Cannot deserialize profile: {}", e), + } + } }