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

View File

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