forked from Plugin-JF-Onkostar/osc-variant
Use traits for catalogues, forms and form entries
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user