Apply exported sorting to items itself and nested items

This commit is contained in:
2023-08-07 14:16:44 +02:00
parent 376bfb2852
commit e84a39b7c4
6 changed files with 242 additions and 1 deletions

View File

@@ -192,6 +192,29 @@ impl Sortable for DataForm {
fn sorting_key(&self) -> String {
self.name.clone()
}
fn sorted(&mut self) -> &Self {
self.data_catalogues.data_catalogue.sort_unstable();
self.entries
.entry
.sort_unstable_by_key(|item| item.sorting_key());
self.entries.entry.iter_mut().for_each(|item| {
item.sorted();
});
if let Some(ref mut plausibility_rule) = self.plausibility_rules.plausibility_rule {
plausibility_rule.sort_unstable_by_key(|item| item.bezeichnung.clone());
plausibility_rule.iter_mut().for_each(|item| {
if let Some(ref mut data_form_entry_names) = item.data_form_entries.entry_name {
data_form_entry_names.sort_unstable();
}
});
}
self
}
}
impl Comparable for DataForm {
@@ -433,6 +456,26 @@ impl FormEntry for Entry {
}
}
impl Sortable for Entry {
fn sorting_key(&self) -> String {
self.name.clone()
}
fn sorted(&mut self) -> &Self
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()
}
}
}
self
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DataFormEntries {