mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 11:46:50 +00:00
Apply exported sorting to items itself and nested items
This commit is contained in:
parent
376bfb2852
commit
e84a39b7c4
@ -70,6 +70,16 @@ impl Sortable for DataCatalogue {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn sorted(&mut self) -> &Self {
|
||||
self.entries
|
||||
.entry
|
||||
.sort_unstable_by_key(|item| item.sorting_key());
|
||||
self.entries.entry.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Comparable for DataCatalogue {
|
||||
@ -151,6 +161,23 @@ pub struct Entry {
|
||||
revision: u16,
|
||||
}
|
||||
|
||||
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 use_) = self.use_ {
|
||||
use_.program_module
|
||||
.sort_unstable_by_key(|item| item.sorting_key())
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Use {
|
||||
@ -166,3 +193,9 @@ pub struct ProgramModule {
|
||||
#[serde(rename = "@name")]
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Sortable for ProgramModule {
|
||||
fn sorting_key(&self) -> String {
|
||||
format!("{}-{}", self.program, self.name)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -239,6 +239,12 @@ pub trait Listable {
|
||||
|
||||
pub trait Sortable {
|
||||
fn sorting_key(&self) -> String;
|
||||
fn sorted(&mut self) -> &Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Comparable: Debug {
|
||||
|
@ -79,17 +79,33 @@ impl OnkostarEditor {
|
||||
.property_catalogue
|
||||
.sort_unstable_by_key(|e| e.sorting_key());
|
||||
|
||||
self.editor.property_catalogue.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self.editor
|
||||
.data_catalogue
|
||||
.sort_unstable_by_key(|e| e.sorting_key());
|
||||
|
||||
self.editor.data_catalogue.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self.editor
|
||||
.data_form
|
||||
.sort_unstable_by_key(|e| e.sorting_key());
|
||||
|
||||
self.editor.data_form.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self.editor
|
||||
.unterformular
|
||||
.sort_unstable_by_key(|e| e.sorting_key());
|
||||
|
||||
self.editor.unterformular.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn print_diff(&mut self, other: &mut Self, strict: bool) {
|
||||
@ -182,7 +198,7 @@ impl OnkostarEditor {
|
||||
_ => {
|
||||
if strict && entry_a.get_hash() != entry_b.get_hash() {
|
||||
println!(
|
||||
"{}: {} (z.B. Reihenfolge von Unterelementen)",
|
||||
"{}: {} (z.B. GUID oder Reihenfolge von Unterelementen)",
|
||||
entry_a.get_name(),
|
||||
style("Inhaltlich verschieden").yellow()
|
||||
);
|
||||
|
@ -67,6 +67,16 @@ impl Sortable for PropertyCatalogue {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn sorted(&mut self) -> &Self {
|
||||
if let Some(ref mut versions) = self.versions.entry {
|
||||
versions.sort_unstable_by_key(|item| item.version_number);
|
||||
versions.iter_mut().for_each(|version| {
|
||||
version.sorted();
|
||||
});
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Comparable for PropertyCatalogue {
|
||||
@ -115,6 +125,40 @@ pub struct Version {
|
||||
categories: Categories,
|
||||
}
|
||||
|
||||
impl Sortable for Version {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.oid.clone()
|
||||
}
|
||||
|
||||
fn sorted(&mut self) -> &Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if let Some(ref mut abbildung) = self.abbildung {
|
||||
abbildung.sort_unstable_by_key(|item| item.sorting_key());
|
||||
abbildung.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
}
|
||||
|
||||
self.entries
|
||||
.content
|
||||
.sort_unstable_by_key(|item| item.sorting_key());
|
||||
self.entries.content.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self.categories
|
||||
.content
|
||||
.sort_unstable_by_key(|item| item.sorting_key());
|
||||
self.categories.content.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct VersionEntries {
|
||||
@ -141,6 +185,12 @@ pub struct VersionEntry {
|
||||
position: String,
|
||||
}
|
||||
|
||||
impl Sortable for VersionEntry {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.code.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Categories {
|
||||
@ -165,6 +215,26 @@ pub struct Category {
|
||||
category_entries: CategoryEntries,
|
||||
}
|
||||
|
||||
impl Sortable for Category {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn sorted(&mut self) -> &Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.category_entries
|
||||
.content
|
||||
.sort_unstable_by_key(|item| item.sorting_key());
|
||||
self.category_entries.content.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CategoryEntries {
|
||||
@ -191,6 +261,12 @@ pub struct CategoryEntry {
|
||||
note: Option<String>,
|
||||
}
|
||||
|
||||
impl Sortable for CategoryEntry {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.code.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Abbildung {
|
||||
@ -200,6 +276,24 @@ pub struct Abbildung {
|
||||
content: Vec<AbbildungEintrag>,
|
||||
}
|
||||
|
||||
impl Sortable for Abbildung {
|
||||
fn sorting_key(&self) -> String {
|
||||
self.ziel_mk_version_oid.clone()
|
||||
}
|
||||
|
||||
fn sorted(&mut self) -> &Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
self.content.sort_unstable_by_key(|item| item.sorting_key());
|
||||
self.content.iter_mut().for_each(|item| {
|
||||
item.sorted();
|
||||
});
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct AbbildungEintrag {
|
||||
@ -209,6 +303,12 @@ pub struct AbbildungEintrag {
|
||||
entry_to: AbbildungEntry,
|
||||
}
|
||||
|
||||
impl Sortable for AbbildungEintrag {
|
||||
fn sorting_key(&self) -> String {
|
||||
format!("{}-{}", self.entry_from.code, self.entry_to.code)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct AbbildungEntry {
|
||||
|
@ -211,6 +211,29 @@ impl Sortable for Unterformular {
|
||||
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 Unterformular {
|
||||
@ -453,6 +476,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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user