1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-07-03 09:12:54 +00:00

Add optional sorted listing of file contents

This commit is contained in:
2023-06-15 23:27:21 +02:00
parent 0f584997f7
commit 11b233b642
9 changed files with 68 additions and 8 deletions

View File

@ -24,7 +24,7 @@
use serde::{Deserialize, Serialize};
use crate::model::{Listable, Ordner};
use crate::model::{Listable, Ordner, Sortable};
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
@ -64,6 +64,12 @@ impl Listable for DataCatalogue {
}
}
impl Sortable for DataCatalogue {
fn sorting_key(&self) -> String {
self.name.clone()
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Entries {

View File

@ -26,7 +26,7 @@ use serde::{Deserialize, Serialize};
use crate::model::{
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
Listable, MenuCategory, PlausibilityRules, Script,
Listable, MenuCategory, PlausibilityRules, Script, Sortable,
};
use crate::model::{Haeufigkeiten, Ordner};
use crate::profile::Profile;
@ -183,6 +183,12 @@ impl Listable for DataForm {
}
}
impl Sortable for DataForm {
fn sorting_key(&self) -> String {
self.name.clone()
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DataCatalogues {

View File

@ -234,6 +234,10 @@ pub trait Listable {
fn to_listed_string(&self) -> String;
}
pub trait Sortable {
fn sorting_key(&self) -> String;
}
pub trait FormEntry {
fn get_name(&self) -> String;
fn get_type(&self) -> String;

View File

@ -31,7 +31,7 @@ use crate::model::data_catalogue::DataCatalogue;
use crate::model::data_form::DataForm;
use crate::model::property_catalogue::PropertyCatalogue;
use crate::model::unterformular::Unterformular;
use crate::model::{FormEntryContainer, Listable};
use crate::model::{FormEntryContainer, Listable, Sortable};
use crate::profile::Profile;
#[derive(Serialize, Deserialize, Debug)]
@ -71,6 +71,24 @@ impl OnkostarEditor {
list.iter()
.for_each(|entry| println!("{}", entry.to_listed_string()));
}
pub fn sorted(&mut self) {
self.editor
.property_catalogue
.sort_unstable_by_key(|e| e.sorting_key());
self.editor
.data_catalogue
.sort_unstable_by_key(|e| e.sorting_key());
self.editor
.data_form
.sort_unstable_by_key(|e| e.sorting_key());
self.editor
.unterformular
.sort_unstable_by_key(|e| e.sorting_key());
}
}
impl FromStr for OnkostarEditor {

View File

@ -24,7 +24,7 @@
use serde::{Deserialize, Serialize};
use crate::model::{Listable, Ordner};
use crate::model::{Listable, Ordner, Sortable};
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
@ -61,6 +61,12 @@ impl Listable for PropertyCatalogue {
}
}
impl Sortable for PropertyCatalogue {
fn sorting_key(&self) -> String {
self.name.clone()
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Versions {

View File

@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
use crate::model::{
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
Listable, MenuCategory, PlausibilityRules, Script,
Listable, MenuCategory, PlausibilityRules, Script, Sortable,
};
use crate::model::{Haeufigkeiten, Ordner};
use crate::profile::Profile;
@ -206,6 +206,12 @@ impl Listable for Unterformular {
}
}
impl Sortable for Unterformular {
fn sorting_key(&self) -> String {
self.name.clone()
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct DataCatalogues {