1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

feat: add profile option 'remove_filter' to remove filter for form entries

This commit is contained in:
Paul-Christian Volkmer 2024-05-23 15:04:19 +02:00
parent 3ed38ca817
commit 218e6aff15
6 changed files with 281 additions and 14 deletions

View File

@ -203,6 +203,7 @@ forms:
hide: true hide: true
- name: "otherformfield" - name: "otherformfield"
default_value: "T" default_value: "T"
remove_filter: true
scripts_code: | scripts_code: |
// Beispielcode // Beispielcode
console.log(getFieldValue('ref_first_mtb')); console.log(getFieldValue('ref_first_mtb'));
@ -238,11 +239,12 @@ wird.
Dadurch wird das Formularfeld nie angezeigt. Dadurch wird das Formularfeld nie angezeigt.
Ein zuvor bestehender Filter wird ersetzt. Ein zuvor bestehender Filter wird ersetzt.
Weiterhin wird die Eigenschaft "Speichern" des Formularfelds auf "Immer speichern" gesetzt um sicherzustellen, dass Weiterhin wird die Eigenschaft "Speichern" des Formularfelds auf "Immer speichern" gesetzt um sicherzustellen, dass
zuvor zuvor enthaltene Daten weiterhin gespeichert bleiben und werden, auch wenn das Formularfeld nicht sichtbar ist.
enthaltene Daten weiterhin gespeichert bleiben und werden, auch wenn das Formularfeld nicht sichtbar ist.
Der Standardwert des Feldes `otherformfield` ist nun auf `T` gesetzt. Der Standardwert des Feldes `otherformfield` ist nun auf `T` gesetzt.
Zum Löschen eines Standardwerts ist `""` anzugeben. Zum Löschen eines Standardwerts ist `""` anzugeben.
Das Formularfeld wird dabei nun immer angezeigt, auch wenn zuvor ein (Anzeige)-Filter gesetzt war.
Dieser wird mir `remove_filter: true` entfernt.
**Achtung!** Diese Anwendung überprüft keine Scripts und verwendet angegebene Scripts als "valid" im resultierenden **Achtung!** Diese Anwendung überprüft keine Scripts und verwendet angegebene Scripts als "valid" im resultierenden
OSC-File. OSC-File.

View File

@ -662,6 +662,10 @@ impl FormEntry for Entry {
}); });
self.speichern = "0".into() self.speichern = "0".into()
} }
fn remove_filter(&mut self) {
self.filter = None;
}
} }
impl Sortable for Entry { impl Sortable for Entry {
@ -696,7 +700,7 @@ mod tests {
use std::str::FromStr; use std::str::FromStr;
use crate::model::onkostar_editor::OnkostarEditor; use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::Script; use crate::model::{Filter, RefEntries, Script};
use crate::profile::Profile; use crate::profile::Profile;
#[test] #[test]
@ -895,4 +899,140 @@ mod tests {
}) })
); );
} }
#[test]
fn should_remove_dataform_entry_filter_with_form_fields() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok());
let mut onkostar_editor = onkostar_editor.unwrap();
let profile = "forms:
- name: 'Hauptformular'
form_fields:
- name: Auswahl
remove_filter: true
scripts_code: |-
// Example code
console.log(42);
";
let profile = Profile::from_str(profile);
assert!(profile.is_ok());
let profile = profile.unwrap();
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[1].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].filter,
Some(Filter {
condition: "getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'".into(),
valid: true,
ref_entries: Some(RefEntries { ref_entry: None })
})
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[3].filter,
None
);
onkostar_editor.apply_profile(&profile);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[1].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[3].filter,
None
);
}
#[test]
fn should_remove_dataform_entry_filter_with_form_references() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok());
let mut onkostar_editor = onkostar_editor.unwrap();
let profile = "forms:
- name: 'Hauptformular'
form_fields:
- name: Auswahl
remove_filter: true
scripts_code: |-
// Example code
console.log(42);
";
let profile = Profile::from_str(profile);
assert!(profile.is_ok());
let profile = profile.unwrap();
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[1].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].filter,
Some(Filter {
condition: "getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'".into(),
valid: true,
ref_entries: Some(RefEntries { ref_entry: None })
})
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[3].filter,
None
);
onkostar_editor.apply_profile(&profile);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[1].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].filter,
None
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[3].filter,
None
);
}
} }

View File

@ -197,7 +197,7 @@ pub struct FeldWert {
punkte: String, punkte: String,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct Filter { pub struct Filter {
#[serde(rename = "Condition")] #[serde(rename = "Condition")]
@ -209,7 +209,7 @@ pub struct Filter {
ref_entries: Option<RefEntries>, ref_entries: Option<RefEntries>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct RefEntries { pub struct RefEntries {
#[serde(rename = "RefEntry")] #[serde(rename = "RefEntry")]
@ -327,6 +327,9 @@ where
if let Some(scripts_code) = &form_reference.escaped_scripts_code() { if let Some(scripts_code) = &form_reference.escaped_scripts_code() {
entry.update_scripts_code(scripts_code.clone()); entry.update_scripts_code(scripts_code.clone());
} }
if form_reference.remove_filter {
entry.remove_filter()
}
} }
} }
@ -334,16 +337,19 @@ fn apply_profile_to_form_field<E>(entry: &mut E, form_field: &FormField)
where where
E: FormEntry, E: FormEntry,
{ {
if entry.get_name() == form_field.name && form_field.hide {
entry.hide()
}
if entry.get_name() == form_field.name { if entry.get_name() == form_field.name {
if form_field.hide {
entry.hide()
}
if let Some(new_default_value) = &form_field.default_value { if let Some(new_default_value) = &form_field.default_value {
entry.update_default_value(new_default_value.to_string()) entry.update_default_value(new_default_value.to_string())
} }
} if let Some(scripts_code) = &form_field.escaped_scripts_code() {
if let Some(scripts_code) = &form_field.escaped_scripts_code() { entry.update_scripts_code(scripts_code.clone());
entry.update_scripts_code(scripts_code.clone()); }
if form_field.remove_filter {
entry.remove_filter()
}
} }
} }
@ -391,6 +397,7 @@ pub trait FormEntry {
fn update_scripts_code(&mut self, value: String); fn update_scripts_code(&mut self, value: String);
fn update_default_value(&mut self, value: String); fn update_default_value(&mut self, value: String);
fn hide(&mut self); fn hide(&mut self);
fn remove_filter(&mut self);
} }
pub trait FolderContent { pub trait FolderContent {

View File

@ -657,6 +657,10 @@ impl FormEntry for Entry {
}); });
self.speichern = "0".into() self.speichern = "0".into()
} }
fn remove_filter(&mut self) {
self.filter = None;
}
} }
impl Sortable for Entry { impl Sortable for Entry {
@ -692,7 +696,7 @@ mod tests {
use std::str::FromStr; use std::str::FromStr;
use crate::model::onkostar_editor::OnkostarEditor; use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::Script; use crate::model::{Filter, RefEntries, Script};
use crate::profile::Profile; use crate::profile::Profile;
#[test] #[test]
@ -793,7 +797,7 @@ mod tests {
} }
#[test] #[test]
fn should_change_dataform_entry_scripts_code_with_form_fields() { fn should_change_unterformular_entry_scripts_code_with_form_fields() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc")); let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok()); assert!(onkostar_editor.is_ok());
@ -829,7 +833,7 @@ mod tests {
} }
#[test] #[test]
fn should_change_dataform_entry_scripts_code_with_form_references() { fn should_change_unterformular_entry_scripts_code_with_form_references() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc")); let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok()); assert!(onkostar_editor.is_ok());
@ -863,4 +867,100 @@ mod tests {
}) })
); );
} }
#[test]
fn should_remove_unterformular_entry_filter_with_form_fields() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok());
let mut onkostar_editor = onkostar_editor.unwrap();
let profile = "forms:
- name: 'Unterformular'
form_fields:
- name: Termin
remove_filter: true
scripts_code: |-
// Example code
console.log(42);
";
let profile = Profile::from_str(profile);
assert!(profile.is_ok());
let profile = profile.unwrap();
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].filter,
Some(Filter {
condition: "getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'".into(),
valid: true,
ref_entries: Some(RefEntries { ref_entry: None })
})
);
onkostar_editor.apply_profile(&profile);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].filter,
None
);
}
#[test]
fn should_remove_unterformular_entry_filter_with_form_references() {
let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc"));
assert!(onkostar_editor.is_ok());
let mut onkostar_editor = onkostar_editor.unwrap();
let profile = "forms:
- name: 'Unterformular'
form_fields:
- name: Termin
remove_filter: true
scripts_code: |-
// Example code
console.log(42);
";
let profile = Profile::from_str(profile);
assert!(profile.is_ok());
let profile = profile.unwrap();
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].filter,
Some(Filter {
condition: "getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'".into(),
valid: true,
ref_entries: Some(RefEntries { ref_entry: None })
})
);
onkostar_editor.apply_profile(&profile);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[0].filter,
None
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].filter,
None
);
}
} }

View File

@ -79,6 +79,8 @@ pub struct FormReference {
pub referenced_data_form: Option<String>, pub referenced_data_form: Option<String>,
pub anzeige: Option<String>, pub anzeige: Option<String>,
pub anzeige_auswahl: Option<String>, pub anzeige_auswahl: Option<String>,
#[serde(default)]
pub remove_filter: bool,
scripts_code: Option<String>, scripts_code: Option<String>,
} }
@ -94,6 +96,8 @@ pub struct FormField {
#[serde(default)] #[serde(default)]
pub hide: bool, pub hide: bool,
pub default_value: Option<String>, pub default_value: Option<String>,
#[serde(default)]
pub remove_filter: bool,
scripts_code: Option<String>, scripts_code: Option<String>,
} }
@ -154,6 +158,7 @@ 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}'
remove_filter: true
scripts_code: |- scripts_code: |-
// Example code // Example code
console.log(42); console.log(42);
@ -177,6 +182,7 @@ mod tests {
profile.forms[0].form_references[0].anzeige_auswahl, profile.forms[0].form_references[0].anzeige_auswahl,
Some("TK vom {Datum}".to_string()) Some("TK vom {Datum}".to_string())
); );
assert!(profile.forms[0].form_references[0].remove_filter);
assert_eq!( assert_eq!(
profile.forms[0].form_references[0].escaped_scripts_code(), profile.forms[0].form_references[0].escaped_scripts_code(),
Some("// Example code&#10;console.log(42);".to_string()) Some("// Example code&#10;console.log(42);".to_string())
@ -262,6 +268,7 @@ mod tests {
- name: formularfeld_to_hide - name: formularfeld_to_hide
hide: true hide: true
- name: formularfeld_to_mod - name: formularfeld_to_mod
remove_filter: true
scripts_code: |- scripts_code: |-
// Example code // Example code
console.log(42); console.log(42);
@ -278,6 +285,7 @@ mod tests {
assert!(profile.forms[0].form_fields[1].hide); assert!(profile.forms[0].form_fields[1].hide);
assert_eq!(profile.forms[0].form_fields[2].name, "formularfeld_to_mod"); assert_eq!(profile.forms[0].form_fields[2].name, "formularfeld_to_mod");
assert!(!profile.forms[0].form_fields[2].hide); assert!(!profile.forms[0].form_fields[2].hide);
assert!(profile.forms[0].form_fields[2].remove_filter);
assert_eq!( assert_eq!(
profile.forms[0].form_fields[2].escaped_scripts_code(), profile.forms[0].form_fields[2].escaped_scripts_code(),
Some("// Example code&#10;console.log(42);".to_string()) Some("// Example code&#10;console.log(42);".to_string())

View File

@ -300,6 +300,11 @@
<ZuordnungErkrankung>0</ZuordnungErkrankung> <ZuordnungErkrankung>0</ZuordnungErkrankung>
<GrafikAusrichtung>0</GrafikAusrichtung> <GrafikAusrichtung>0</GrafikAusrichtung>
<Mandatory>false</Mandatory> <Mandatory>false</Mandatory>
<Filter>
<Condition>getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'</Condition>
<Valid>true</Valid>
<RefEntries/>
</Filter>
<NotSpecified>false</NotSpecified> <NotSpecified>false</NotSpecified>
<ReferencedDataFormField/> <ReferencedDataFormField/>
<Anzeige/> <Anzeige/>
@ -545,6 +550,11 @@
<ZuordnungErkrankung>0</ZuordnungErkrankung> <ZuordnungErkrankung>0</ZuordnungErkrankung>
<GrafikAusrichtung>0</GrafikAusrichtung> <GrafikAusrichtung>0</GrafikAusrichtung>
<Mandatory>mandatory</Mandatory> <Mandatory>mandatory</Mandatory>
<Filter>
<Condition>getGlobalSetting('mehrere_mtb_in_mtbepisode') = 'true'</Condition>
<Valid>true</Valid>
<RefEntries/>
</Filter>
<NotSpecified>false</NotSpecified> <NotSpecified>false</NotSpecified>
<ReferencedDataFormField/> <ReferencedDataFormField/>
<Anzeige/> <Anzeige/>