1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-10-28 23:42:16 +00:00

refactor: collapse nested if

This commit is contained in:
2025-09-14 13:28:14 +02:00
parent 766a354677
commit 9d7131341f
2 changed files with 49 additions and 48 deletions

View File

@@ -23,9 +23,9 @@ use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::other::Entry;
use crate::model::requirements::{Requirement, Requires};
use crate::model::{
apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries,
FolderContent, FormEntry, FormEntryContainer, Kennzahlen, Listable, MenuCategory,
PlausibilityRules, PunkteKategorien, Script, Sortable,
apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries, FolderContent, FormEntry,
FormEntryContainer, Kennzahlen, Listable, MenuCategory, PlausibilityRules, PunkteKategorien,
Script, Sortable,
};
use crate::model::{Haeufigkeiten, Ordner};
use crate::profile::Profile;
@@ -220,31 +220,31 @@ pub struct Form<Type> {
impl<Type: 'static> FormEntryContainer for Form<Type> {
fn apply_profile(&mut self, profile: &Profile) {
profile.forms.iter().for_each(|profile_form| {
if self.name == profile_form.name {
if let Some(ref mut entries) = self.entries {
entries.entry.iter_mut().for_each(|entry| {
profile_form
.form_references
.iter()
.for_each(|form_reference| {
apply_profile_to_form_entry(entry, form_reference);
});
if self.name == profile_form.name
&& let Some(ref mut entries) = self.entries
{
entries.entry.iter_mut().for_each(|entry| {
profile_form
.form_references
.iter()
.for_each(|form_reference| {
apply_profile_to_form_entry(entry, form_reference);
});
// Hide form field using filter set to "false" if requested and change default value
profile_form
.form_fields
.iter()
.for_each(|form_field| apply_profile_to_form_field(entry, form_field));
// Hide form field using filter set to "false" if requested and change default value
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(),
position: menu_category.position.clone(),
column: menu_category.column.clone(),
});
}
});
}
if let Some(menu_category) = &profile_form.menu_category {
self.menu_category = Some(MenuCategory {
name: menu_category.name.clone(),
position: menu_category.position.clone(),
column: menu_category.column.clone(),
});
}
});
}
});
}
@@ -288,14 +288,14 @@ impl<Type: 'static> Sortable for Form<Type> {
});
}
if let Some(ref mut plausibility_rules) = self.plausibility_rules {
if let Some(ref mut plausibility_rule) = plausibility_rules.plausibility_rule {
plausibility_rule.sort_unstable_by_key(|item| item.bezeichnung.clone());
if let Some(ref mut plausibility_rules) = self.plausibility_rules
&& let Some(ref mut plausibility_rule) = plausibility_rules.plausibility_rule
{
plausibility_rule.sort_unstable_by_key(|item| item.bezeichnung.clone());
for item in plausibility_rule {
if let Some(ref mut data_form_entry_names) = item.data_form_entries.entry_name {
data_form_entry_names.sort_unstable();
}
for item in plausibility_rule {
if let Some(ref mut data_form_entry_names) = item.data_form_entries.entry_name {
data_form_entry_names.sort_unstable();
}
}
}
@@ -996,9 +996,11 @@ mod tests {
onkostar_editor.apply_profile(&profile);
assert!(&onkostar_editor.editor.unterformular[0]
.menu_category
.is_none());
assert!(
&onkostar_editor.editor.unterformular[0]
.menu_category
.is_none()
);
}
#[test]

View File

@@ -522,17 +522,16 @@ impl FormEntry for Entry {
self.referenced_data_form = Some(value.to_string());
// Add new minimal form reference if not already present
if let Some(ref mut form) = self.data_form_references {
if !form
if let Some(ref mut form) = self.data_form_references
&& !form
.referenced_data_form
.iter()
.map(super::Comparable::get_name)
.collect::<Vec<String>>()
.contains(&value)
{
form.referenced_data_form
.push(Form::new_form_reference(&value));
}
{
form.referenced_data_form
.push(Form::new_form_reference(&value));
}
}
@@ -578,13 +577,13 @@ impl Sortable for Entry {
where
Self: Sized,
{
if let Some(ref mut filter) = self.filter {
if let Some(ref mut ref_entries) = filter.ref_entries {
if let Some(ref mut ref_entry) = ref_entries.ref_entry {
ref_entry.sort_unstable();
}
}
if let Some(ref mut filter) = self.filter
&& let Some(ref mut ref_entries) = filter.ref_entries
&& let Some(ref mut ref_entry) = ref_entries.ref_entry
{
ref_entry.sort_unstable();
}
self
}
}