mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
Set filter to "false" if form field should be hidden
This commit is contained in:
parent
a2df2650ed
commit
abdef90e90
@ -31,7 +31,7 @@ use crate::model::onkostar_editor::OnkostarEditor;
|
|||||||
use crate::model::requirements::{Requirement, Requires};
|
use crate::model::requirements::{Requirement, Requires};
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry,
|
apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry,
|
||||||
FormEntryContainer, Listable, MenuCategory, PlausibilityRules, Script, Sortable,
|
FormEntryContainer, Listable, MenuCategory, PlausibilityRules, RefEntries, Script, Sortable,
|
||||||
};
|
};
|
||||||
use crate::model::{Haeufigkeiten, Ordner};
|
use crate::model::{Haeufigkeiten, Ordner};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
@ -169,6 +169,13 @@ impl FormEntryContainer for DataForm {
|
|||||||
apply_profile_to_form_entry(entry, form_reference)
|
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| {
|
||||||
|
if entry.name == form_field.name && form_field.hide {
|
||||||
|
entry.hide()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(menu_category) = &profile_form.menu_category {
|
if let Some(menu_category) = &profile_form.menu_category {
|
||||||
self.menu_category = Some(MenuCategory {
|
self.menu_category = Some(MenuCategory {
|
||||||
name: menu_category.name.clone(),
|
name: menu_category.name.clone(),
|
||||||
@ -525,6 +532,14 @@ impl FormEntry for Entry {
|
|||||||
valid: true,
|
valid: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hide(&mut self) {
|
||||||
|
self.filter = Some(Filter {
|
||||||
|
condition: "false".into(),
|
||||||
|
valid: true,
|
||||||
|
ref_entries: Some(RefEntries { ref_entry: None }),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sortable for Entry {
|
impl Sortable for Entry {
|
||||||
|
@ -267,6 +267,7 @@ pub trait FormEntry {
|
|||||||
fn update_anzeige(&mut self, value: String);
|
fn update_anzeige(&mut self, value: String);
|
||||||
fn update_anzeige_auswahl(&mut self, value: String);
|
fn update_anzeige_auswahl(&mut self, value: String);
|
||||||
fn update_scripts_code(&mut self, value: String);
|
fn update_scripts_code(&mut self, value: String);
|
||||||
|
fn hide(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FolderContent {
|
pub trait FolderContent {
|
||||||
|
@ -31,7 +31,7 @@ use crate::model::onkostar_editor::OnkostarEditor;
|
|||||||
use crate::model::requirements::{Requirement, Requires};
|
use crate::model::requirements::{Requirement, Requires};
|
||||||
use crate::model::{
|
use crate::model::{
|
||||||
apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry,
|
apply_profile_to_form_entry, Ansichten, Comparable, Entries, Filter, FolderContent, FormEntry,
|
||||||
FormEntryContainer, Listable, MenuCategory, PlausibilityRules, Script, Sortable,
|
FormEntryContainer, Listable, MenuCategory, PlausibilityRules, RefEntries, Script, Sortable,
|
||||||
};
|
};
|
||||||
use crate::model::{Haeufigkeiten, Ordner};
|
use crate::model::{Haeufigkeiten, Ordner};
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
@ -180,6 +180,13 @@ impl FormEntryContainer for Unterformular {
|
|||||||
apply_profile_to_form_entry(entry, form_reference)
|
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| {
|
||||||
|
if entry.name == form_field.name && form_field.hide {
|
||||||
|
entry.hide()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if let Some(menu_category) = &profile_form.menu_category {
|
if let Some(menu_category) = &profile_form.menu_category {
|
||||||
self.menu_category = Some(MenuCategory {
|
self.menu_category = Some(MenuCategory {
|
||||||
name: menu_category.name.clone(),
|
name: menu_category.name.clone(),
|
||||||
@ -548,6 +555,14 @@ impl FormEntry for Entry {
|
|||||||
valid: true,
|
valid: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hide(&mut self) {
|
||||||
|
self.filter = Some(Filter {
|
||||||
|
condition: "false".into(),
|
||||||
|
valid: true,
|
||||||
|
ref_entries: Some(RefEntries { ref_entry: None }),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sortable for Entry {
|
impl Sortable for Entry {
|
||||||
|
@ -50,6 +50,8 @@ pub struct Form {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub form_references: Vec<FormReference>,
|
pub form_references: Vec<FormReference>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub form_fields: Vec<FormField>,
|
||||||
pub menu_category: Option<MenuCategory>,
|
pub menu_category: Option<MenuCategory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +70,13 @@ impl FormReference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct FormField {
|
||||||
|
pub name: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub hide: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct MenuCategory {
|
pub struct MenuCategory {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -93,6 +102,9 @@ mod tests {
|
|||||||
referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW'
|
referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW'
|
||||||
anzeige: 'Datum: {Datum}'
|
anzeige: 'Datum: {Datum}'
|
||||||
anzeige_auswahl: 'TK vom {Datum}'
|
anzeige_auswahl: 'TK vom {Datum}'
|
||||||
|
form_fields:
|
||||||
|
- name: eingabefeld
|
||||||
|
hide: true
|
||||||
";
|
";
|
||||||
|
|
||||||
match Profile::from_str(content) {
|
match Profile::from_str(content) {
|
||||||
@ -101,6 +113,7 @@ mod tests {
|
|||||||
assert_eq!(profile.forms[0].name, "DNPM Therapieplan");
|
assert_eq!(profile.forms[0].name, "DNPM Therapieplan");
|
||||||
assert!(profile.forms[0].menu_category.is_some());
|
assert!(profile.forms[0].menu_category.is_some());
|
||||||
assert_eq!(profile.forms[0].form_references.len(), 1);
|
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),
|
Err(e) => panic!("Cannot deserialize profile: {}", e),
|
||||||
}
|
}
|
||||||
@ -212,4 +225,29 @@ mod tests {
|
|||||||
let actual = Profile::from_str(content);
|
let actual = Profile::from_str(content);
|
||||||
assert!(actual.is_err());
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user