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,8 +220,9 @@ 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| { entries.entry.iter_mut().for_each(|entry| {
profile_form profile_form
.form_references .form_references
@@ -245,7 +246,6 @@ impl<Type: 'static> FormEntryContainer for Form<Type> {
} }
}); });
} }
}
}); });
} }
} }
@@ -288,8 +288,9 @@ 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 {
@@ -298,7 +299,6 @@ impl<Type: 'static> Sortable for Form<Type> {
} }
} }
} }
}
self self
} }
@@ -996,9 +996,11 @@ mod tests {
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert!(&onkostar_editor.editor.unterformular[0] assert!(
&onkostar_editor.editor.unterformular[0]
.menu_category .menu_category
.is_none()); .is_none()
);
} }
#[test] #[test]

View File

@@ -522,8 +522,8 @@ 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)
@@ -534,7 +534,6 @@ impl FormEntry for Entry {
.push(Form::new_form_reference(&value)); .push(Form::new_form_reference(&value));
} }
} }
}
fn update_anzeige(&mut self, value: String) { fn update_anzeige(&mut self, value: String) {
self.anzeige = value; self.anzeige = 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
} }
} }