mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-04-19 19:56:50 +00:00
Use traits for catalogues, forms and form entries
This commit is contained in:
parent
2c11690edf
commit
13f1126619
@ -111,7 +111,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
match cli.command {
|
||||
Command::List { inputfile } => {
|
||||
let data = read_inputfile(inputfile)?;
|
||||
data.list_forms();
|
||||
data.print_list();
|
||||
}
|
||||
Command::Modify {
|
||||
inputfile,
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::model::Ordner;
|
||||
use crate::model::{Listable, Ordner};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@ -55,8 +55,8 @@ pub struct DataCatalogue {
|
||||
ordner: Ordner,
|
||||
}
|
||||
|
||||
impl DataCatalogue {
|
||||
pub fn to_listed_string(&self) -> String {
|
||||
impl Listable for DataCatalogue {
|
||||
fn to_listed_string(&self) -> String {
|
||||
format!(
|
||||
"Datenkatalog '{}' in Revision '{}'",
|
||||
self.name, self.revision
|
||||
|
@ -24,7 +24,10 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::model::{Ansichten, Entries, Filter, MenuCategory, PlausibilityRules, Script};
|
||||
use crate::model::{
|
||||
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
||||
Listable, MenuCategory, PlausibilityRules, Script,
|
||||
};
|
||||
use crate::model::{Haeufigkeiten, Ordner};
|
||||
use crate::profile::Profile;
|
||||
|
||||
@ -149,8 +152,8 @@ pub struct DataForm {
|
||||
ansichten: Option<Ansichten>,
|
||||
}
|
||||
|
||||
impl DataForm {
|
||||
pub fn apply_profile(&mut self, profile: &Profile) {
|
||||
impl FormEntryContainer for DataForm {
|
||||
fn apply_profile(&mut self, profile: &Profile) {
|
||||
profile.forms.iter().for_each(|profile_form| {
|
||||
if self.name == profile_form.name {
|
||||
self.entries.entry.iter_mut().for_each(|entry| {
|
||||
@ -158,28 +161,7 @@ impl DataForm {
|
||||
.form_references
|
||||
.iter()
|
||||
.for_each(|form_reference| {
|
||||
if entry.type_ == "formReference" && entry.name == form_reference.name {
|
||||
if let Some(profile_referenced_data_form) =
|
||||
&form_reference.referenced_data_form
|
||||
{
|
||||
entry.referenced_data_form =
|
||||
Some(profile_referenced_data_form.clone())
|
||||
}
|
||||
if let Some(profile_anzeige) = &form_reference.anzeige {
|
||||
entry.anzeige = profile_anzeige.clone()
|
||||
}
|
||||
if let Some(profile_anzeige_auswahl) =
|
||||
&form_reference.anzeige_auswahl
|
||||
{
|
||||
entry.anzeige_auswahl = Some(profile_anzeige_auswahl.clone())
|
||||
}
|
||||
if let Some(scripts_code) = &form_reference.escaped_scripts_code() {
|
||||
entry.scripts = Some(Script {
|
||||
code: scripts_code.clone(),
|
||||
valid: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
apply_profile_to_form_entry(entry, form_reference)
|
||||
});
|
||||
|
||||
if let Some(menu_category) = &profile_form.menu_category {
|
||||
@ -193,8 +175,10 @@ impl DataForm {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_listed_string(&self) -> String {
|
||||
impl Listable for DataForm {
|
||||
fn to_listed_string(&self) -> String {
|
||||
format!("Formular '{}' in Revision '{}'", self.name, self.revision)
|
||||
}
|
||||
}
|
||||
@ -399,6 +383,35 @@ pub struct Entry {
|
||||
einfuegen_verhindern: Option<String>,
|
||||
}
|
||||
|
||||
impl FormEntry for Entry {
|
||||
fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn get_type(&self) -> String {
|
||||
self.type_.clone()
|
||||
}
|
||||
|
||||
fn update_referenced_data_form(&mut self, value: String) {
|
||||
self.referenced_data_form = Some(value);
|
||||
}
|
||||
|
||||
fn update_anzeige(&mut self, value: String) {
|
||||
self.anzeige = value;
|
||||
}
|
||||
|
||||
fn update_anzeige_auswahl(&mut self, value: String) {
|
||||
self.anzeige_auswahl = Some(value);
|
||||
}
|
||||
|
||||
fn update_scripts_code(&mut self, value: String) {
|
||||
self.scripts = Some(Script {
|
||||
code: value,
|
||||
valid: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DataFormEntries {
|
||||
|
@ -22,6 +22,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
use crate::profile::{FormReference, Profile};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod data_catalogue;
|
||||
@ -204,3 +205,40 @@ pub struct Ordner {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
parent_order: Option<Box<Ordner>>,
|
||||
}
|
||||
|
||||
fn apply_profile_to_form_entry<E>(entry: &mut E, form_reference: &FormReference)
|
||||
where
|
||||
E: FormEntry,
|
||||
{
|
||||
if entry.get_type() == "formReference" && entry.get_name() == form_reference.name {
|
||||
if let Some(profile_referenced_data_form) = &form_reference.referenced_data_form {
|
||||
entry.update_referenced_data_form(profile_referenced_data_form.clone());
|
||||
}
|
||||
if let Some(profile_anzeige) = &form_reference.anzeige {
|
||||
entry.update_anzeige(profile_anzeige.clone());
|
||||
}
|
||||
if let Some(profile_anzeige_auswahl) = &form_reference.anzeige_auswahl {
|
||||
entry.update_anzeige_auswahl(profile_anzeige_auswahl.clone());
|
||||
}
|
||||
if let Some(scripts_code) = &form_reference.escaped_scripts_code() {
|
||||
entry.update_scripts_code(scripts_code.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FormEntryContainer {
|
||||
fn apply_profile(&mut self, profile: &Profile);
|
||||
}
|
||||
|
||||
pub trait Listable {
|
||||
fn to_listed_string(&self) -> String;
|
||||
}
|
||||
|
||||
pub trait FormEntry {
|
||||
fn get_name(&self) -> String;
|
||||
fn get_type(&self) -> String;
|
||||
fn update_referenced_data_form(&mut self, value: String);
|
||||
fn update_anzeige(&mut self, value: String);
|
||||
fn update_anzeige_auswahl(&mut self, value: String);
|
||||
fn update_scripts_code(&mut self, value: String);
|
||||
}
|
||||
|
@ -31,6 +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::profile::Profile;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@ -52,7 +53,7 @@ impl OnkostarEditor {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn list_forms(&self) {
|
||||
pub fn print_list(&self) {
|
||||
println!(
|
||||
"Die Datei wurde am {} mit {} in Version {} erstellt.\n\nFolgende Inhalte sind gespeichert\n",
|
||||
style(&self.info_xml.datum_xml).yellow(),
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::model::Ordner;
|
||||
use crate::model::{Listable, Ordner};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
@ -52,8 +52,8 @@ pub struct PropertyCatalogue {
|
||||
ordner: Ordner,
|
||||
}
|
||||
|
||||
impl PropertyCatalogue {
|
||||
pub fn to_listed_string(&self) -> String {
|
||||
impl Listable for PropertyCatalogue {
|
||||
fn to_listed_string(&self) -> String {
|
||||
format!(
|
||||
"Merkmalskatalog '{}' in Revision '{}'",
|
||||
self.name, self.revision
|
||||
|
@ -25,7 +25,10 @@
|
||||
use console::style;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::model::{Ansichten, Entries, Filter, MenuCategory, PlausibilityRules, Script};
|
||||
use crate::model::{
|
||||
apply_profile_to_form_entry, Ansichten, Entries, Filter, FormEntry, FormEntryContainer,
|
||||
Listable, MenuCategory, PlausibilityRules, Script,
|
||||
};
|
||||
use crate::model::{Haeufigkeiten, Ordner};
|
||||
use crate::profile::Profile;
|
||||
|
||||
@ -161,8 +164,8 @@ pub struct Unterformular {
|
||||
ansichten: Option<Ansichten>,
|
||||
}
|
||||
|
||||
impl Unterformular {
|
||||
pub fn apply_profile(&mut self, profile: &Profile) {
|
||||
impl FormEntryContainer for Unterformular {
|
||||
fn apply_profile(&mut self, profile: &Profile) {
|
||||
profile.forms.iter().for_each(|profile_form| {
|
||||
if self.name == profile_form.name {
|
||||
self.entries.entry.iter_mut().for_each(|entry| {
|
||||
@ -170,28 +173,7 @@ impl Unterformular {
|
||||
.form_references
|
||||
.iter()
|
||||
.for_each(|form_reference| {
|
||||
if entry.type_ == "formReference" && entry.name == form_reference.name {
|
||||
if let Some(profile_referenced_data_form) =
|
||||
&form_reference.referenced_data_form
|
||||
{
|
||||
entry.referenced_data_form =
|
||||
Some(profile_referenced_data_form.clone())
|
||||
}
|
||||
if let Some(profile_anzeige) = &form_reference.anzeige {
|
||||
entry.anzeige = profile_anzeige.clone()
|
||||
}
|
||||
if let Some(profile_anzeige_auswahl) =
|
||||
&form_reference.anzeige_auswahl
|
||||
{
|
||||
entry.anzeige_auswahl = Some(profile_anzeige_auswahl.clone())
|
||||
}
|
||||
if let Some(scripts_code) = &form_reference.escaped_scripts_code() {
|
||||
entry.scripts = Some(Script {
|
||||
code: scripts_code.clone(),
|
||||
valid: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
apply_profile_to_form_entry(entry, form_reference)
|
||||
});
|
||||
|
||||
if let Some(menu_category) = &profile_form.menu_category {
|
||||
@ -205,8 +187,10 @@ impl Unterformular {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_listed_string(&self) -> String {
|
||||
impl Listable for Unterformular {
|
||||
fn to_listed_string(&self) -> String {
|
||||
if self.hat_unterformulare {
|
||||
return format!(
|
||||
"Unterformular '{}' in Revision '{}' {}",
|
||||
@ -423,6 +407,35 @@ pub struct Entry {
|
||||
einfuegen_verhindern: Option<String>,
|
||||
}
|
||||
|
||||
impl FormEntry for Entry {
|
||||
fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn get_type(&self) -> String {
|
||||
self.type_.clone()
|
||||
}
|
||||
|
||||
fn update_referenced_data_form(&mut self, value: String) {
|
||||
self.referenced_data_form = Some(value);
|
||||
}
|
||||
|
||||
fn update_anzeige(&mut self, value: String) {
|
||||
self.anzeige = value;
|
||||
}
|
||||
|
||||
fn update_anzeige_auswahl(&mut self, value: String) {
|
||||
self.anzeige_auswahl = Some(value);
|
||||
}
|
||||
|
||||
fn update_scripts_code(&mut self, value: String) {
|
||||
self.scripts = Some(Script {
|
||||
code: value,
|
||||
valid: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DataFormEntries {
|
||||
|
Loading…
x
Reference in New Issue
Block a user