From 67df3bee9e91267eeafb1c75b90e08c90237457a Mon Sep 17 00:00:00 2001 From: blelump Date: Tue, 17 Dec 2024 18:49:11 +0100 Subject: [PATCH] fix: cleanup form&cred layouts --- semantics/oca-bundle/src/state/oca.rs | 180 ------------------ semantics/oca-bundle/src/state/oca/layout.rs | 2 - .../src/state/oca/layout/credential.rs | 77 -------- .../oca-bundle/src/state/oca/layout/form.rs | 58 ------ semantics/oca-bundle/src/state/oca/overlay.rs | 4 - .../state/oca/overlay/credential_layout.rs | 72 ------- .../src/state/oca/overlay/form_layout.rs | 72 ------- semantics/oca-bundle/tests/create_oca_test.rs | 16 -- 8 files changed, 481 deletions(-) delete mode 100644 semantics/oca-bundle/src/state/oca/layout.rs delete mode 100644 semantics/oca-bundle/src/state/oca/layout/credential.rs delete mode 100644 semantics/oca-bundle/src/state/oca/layout/form.rs delete mode 100644 semantics/oca-bundle/src/state/oca/overlay/credential_layout.rs delete mode 100644 semantics/oca-bundle/src/state/oca/overlay/form_layout.rs diff --git a/semantics/oca-bundle/src/state/oca.rs b/semantics/oca-bundle/src/state/oca.rs index 23abf6c1..5a331ece 100644 --- a/semantics/oca-bundle/src/state/oca.rs +++ b/semantics/oca-bundle/src/state/oca.rs @@ -1,5 +1,3 @@ -use crate::state::oca::layout::credential::Layout as CredentialLayout; -use crate::state::oca::layout::form::Layout as FormLayout; use crate::state::oca::overlay::cardinality::Cardinalitys; use crate::state::oca::overlay::character_encoding::CharacterEncodings; use crate::state::oca::overlay::conditional::Conditionals; @@ -19,7 +17,6 @@ use said::version::SerializationInfo; use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer}; use std::collections::HashMap; pub mod capture_base; -mod layout; pub mod overlay; use crate::state::{ attribute::Attribute, @@ -53,8 +50,6 @@ use oca_ast_semantics::ast::{ #[derive(Clone)] pub struct OCABox { pub attributes: HashMap, - pub credential_layouts: Option>, - pub form_layouts: Option>, pub mappings: Option>, pub meta: Option>>, pub classification: Option, @@ -70,8 +65,6 @@ impl OCABox { pub fn new() -> Self { OCABox { attributes: HashMap::new(), - credential_layouts: None, - form_layouts: None, mappings: None, meta: None, classification: None, @@ -143,18 +136,6 @@ impl OCABox { overlays.push(Box::new(meta_ov)); } } - if let Some(layouts) = &self.form_layouts { - for layout in layouts { - let layout_ov = overlay::FormLayout::new(layout.clone()); - overlays.push(Box::new(layout_ov)); - } - } - if let Some(layouts) = &self.credential_layouts { - for layout in layouts { - let layout_ov = overlay::CredentialLayout::new(layout.clone()); - overlays.push(Box::new(layout_ov)); - } - } for attribute in self.attributes.values() { if attribute.encoding.is_some() { @@ -1415,166 +1396,5 @@ mod tests { assert_eq!(oca.capture_base.attributes.len(), 0); assert_eq!(oca.capture_base.classification, "GICS:35102020"); } - /* - #[test] - fn build_oca_with_attributes() { - let oca_builder = OCABuilder::new(Encoding::Utf8) - .add_form_layout( - " - config: - css: - style: >- - form { background-color: white; } - elements: - - type: meta - config: - css: - style: >- - justify-content: space-between; - parts: - - name: language - - name: name - - name: description - - type: category - id: _cat-1_ - - type: attribute - name: n1 - parts: - - name: label - - name: input - - name: information - - type: attribute - name: n2 - parts: - - name: label - - name: input - - name: information - " - .to_string(), - ) - .add_credential_layout( - " - version: beta-1 - config: - css: - width: 200px - height: 100px - style: >- - @import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic:wght@700&display=swap'); - pages: - - config: - name: Page 0 - elements: - - type: row - config: - css: - style: >- - height: 32px; - elements: - - type: row - elements: - - type: col - size: 4 - config: - css: - style: >- - padding-right: 0; - elements: - - type: row - elements: - - type: col - size: 8 - elements: - - type: row - elements: - - type: col - elements: - - type: attribute - name: n1 - labels: - passport: - en: Passport - fr: Passeport - " - .to_string(), - ) - .add_name(hashmap! { - "En".to_string() => "Driving Licence".to_string(), - "Pl".to_string() => "Prawo Jazdy".to_string(), - }) - .add_description(hashmap! { - "En".to_string() => "DL desc".to_string(), - "Pl".to_string() => "PJ desc".to_string(), - }); - - let attr1 = AttributeBuilder::new(String::from("n1"), AttributeType::Text) - .set_flagged() - .add_label(hashmap! { - "En".to_string() => "Name: ".to_string(), - "Pl".to_string() => "ImiÄ™: ".to_string(), - }) - .add_entry_codes(EntryCodes::Array(vec![ - "op1".to_string(), - "op2".to_string(), - ])) - .add_entries(Entries::Object(vec![ - Entry::new( - "op1".to_string(), - hashmap! { - "En".to_string() => "Option 1".to_string(), - "Pl".to_string() => "Opcja 1".to_string(), - }, - ), - Entry::new( - "op2".to_string(), - hashmap! { - "En".to_string() => "Option 2".to_string(), - "Pl".to_string() => "Opcja 2".to_string(), - }, - ), - ])) - .add_information(hashmap! { - "En".to_string() => "info en".to_string(), - "Pl".to_string() => "info pl".to_string(), - }) - .add_unit("SI".to_string(), "cm".to_string()) - .build(); - - let attr2 = AttributeBuilder::new(String::from("n2"), AttributeType::DateTime) - .add_label(hashmap! { - "En".to_string() => "Date: ".to_string(), - "Pl".to_string() => "Data: ".to_string(), - }) - .add_condition("${0} == 'op1'".to_string(), vec!["n1".to_string()]) - .add_encoding(Encoding::Iso8859_1) - .add_format("DD/MM/YYYY".to_string()) - .build(); - - let attr3 = AttributeBuilder::new(String::from("n3"), AttributeType::Reference) - .add_sai("sai".to_string()) - .add_label(hashmap! { - "En".to_string() => "Reference: ".to_string(), - "Pl".to_string() => "Referecja: ".to_string(), - }) - .build(); - - let oca = oca_builder - .add_attribute(attr1) - .add_attribute(attr2) - .add_attribute(attr3) - .finalize(); - - // println!( - // "{}", - // serde_json::to_string_pretty(&serde_json::to_value(&oca).unwrap()).unwrap() - // ); - - assert_eq!( - oca.capture_base.attributes.get(&"n3".to_string()), - Some(&"Reference:sai".to_string()) - ); - assert_eq!(oca.capture_base.attributes.len(), 3); - assert_eq!(oca.capture_base.flagged_attributes.len(), 1); - } */ } */ diff --git a/semantics/oca-bundle/src/state/oca/layout.rs b/semantics/oca-bundle/src/state/oca/layout.rs deleted file mode 100644 index 630f7642..00000000 --- a/semantics/oca-bundle/src/state/oca/layout.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod credential; -pub mod form; diff --git a/semantics/oca-bundle/src/state/oca/layout/credential.rs b/semantics/oca-bundle/src/state/oca/layout/credential.rs deleted file mode 100644 index 485f550a..00000000 --- a/semantics/oca-bundle/src/state/oca/layout/credential.rs +++ /dev/null @@ -1,77 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; - -#[derive(Debug, Clone, Serialize, Deserialize)] -struct LayoutConfigCss { - #[serde(skip_serializing_if = "Option::is_none")] - width: Option, - #[serde(skip_serializing_if = "Option::is_none")] - height: Option, - #[serde(skip_serializing_if = "Option::is_none")] - style: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct LayoutConfig { - #[serde(skip_serializing_if = "Option::is_none")] - css: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct PageConfigCss { - #[serde(skip_serializing_if = "Option::is_none")] - style: Option, - #[serde(skip_serializing_if = "Option::is_none")] - classes: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - background_image: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct PageConfig { - #[serde(skip_serializing_if = "Option::is_none")] - css: Option, - name: String, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct ElementConfigCss { - #[serde(skip_serializing_if = "Option::is_none")] - style: Option, - #[serde(skip_serializing_if = "Option::is_none")] - classes: Option>, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct ElementConfig { - #[serde(skip_serializing_if = "Option::is_none")] - css: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct Element { - #[serde(rename = "type")] - element_type: String, - #[serde(skip_serializing_if = "Option::is_none")] - size: Option, - #[serde(skip_serializing_if = "Option::is_none")] - name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - content: Option, - #[serde(skip_serializing_if = "Option::is_none")] - layout: Option, - #[serde(skip_serializing_if = "Option::is_none")] - config: Option, - #[serde(skip_serializing_if = "Option::is_none")] - elements: Option>, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct Page { - config: PageConfig, - elements: Vec, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Layout { - version: String, - #[serde(skip_serializing_if = "Option::is_none")] - config: Option, - pages: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - labels: Option>>, - #[serde(skip_serializing_if = "Option::is_none")] - reference_layouts: Option>, -} diff --git a/semantics/oca-bundle/src/state/oca/layout/form.rs b/semantics/oca-bundle/src/state/oca/layout/form.rs deleted file mode 100644 index b57f69b0..00000000 --- a/semantics/oca-bundle/src/state/oca/layout/form.rs +++ /dev/null @@ -1,58 +0,0 @@ -use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; - -#[derive(Debug, Clone, Serialize, Deserialize)] -struct LayoutConfigCss { - #[serde(skip_serializing_if = "Option::is_none")] - style: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct LayoutConfig { - #[serde(skip_serializing_if = "Option::is_none")] - css: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -struct ElementConfigCss { - #[serde(skip_serializing_if = "Option::is_none")] - style: Option, - #[serde(skip_serializing_if = "Option::is_none")] - classes: Option>, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct ElementConfig { - #[serde(skip_serializing_if = "Option::is_none")] - css: Option, - #[serde(skip_serializing_if = "Option::is_none")] - widget: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -struct Part { - name: String, - #[serde(skip_serializing_if = "Option::is_none")] - layout: Option, - #[serde(skip_serializing_if = "Option::is_none")] - config: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -struct Element { - #[serde(rename = "type")] - element_type: String, - #[serde(skip_serializing_if = "Option::is_none")] - config: Option, - #[serde(skip_serializing_if = "Option::is_none")] - id: Option, - #[serde(skip_serializing_if = "Option::is_none")] - name: Option, - #[serde(skip_serializing_if = "Option::is_none")] - parts: Option>, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Layout { - #[serde(skip_serializing_if = "Option::is_none")] - config: Option, - elements: Vec, - #[serde(skip_serializing_if = "Option::is_none")] - reference_layouts: Option>, -} diff --git a/semantics/oca-bundle/src/state/oca/overlay.rs b/semantics/oca-bundle/src/state/oca/overlay.rs index 6c9166fb..ec3319d1 100644 --- a/semantics/oca-bundle/src/state/oca/overlay.rs +++ b/semantics/oca-bundle/src/state/oca/overlay.rs @@ -3,11 +3,9 @@ pub mod cardinality; pub mod character_encoding; pub mod conditional; pub mod conformance; -pub mod credential_layout; pub mod entry; pub mod entry_code; pub mod entry_code_mapping; -pub mod form_layout; #[cfg(feature = "format_overlay")] pub mod format; pub mod information; @@ -22,11 +20,9 @@ pub use self::cardinality::CardinalityOverlay as Cardinality; pub use self::character_encoding::CharacterEncodingOverlay as CharacterEncoding; pub use self::conditional::ConditionalOverlay as Conditional; pub use self::conformance::ConformanceOverlay as Conformance; -pub use self::credential_layout::CredentialLayoutOverlay as CredentialLayout; pub use self::entry::EntryOverlay as Entry; pub use self::entry_code::EntryCodeOverlay as EntryCode; pub use self::entry_code_mapping::EntryCodeMappingOverlay as EntryCodeMapping; -pub use self::form_layout::FormLayoutOverlay as FormLayout; #[cfg(feature = "format_overlay")] pub use self::format::FormatOverlay as Format; pub use self::information::InformationOverlay as Information; diff --git a/semantics/oca-bundle/src/state/oca/overlay/credential_layout.rs b/semantics/oca-bundle/src/state/oca/overlay/credential_layout.rs deleted file mode 100644 index f5244248..00000000 --- a/semantics/oca-bundle/src/state/oca/overlay/credential_layout.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::state::oca::OCABox; -use crate::state::{attribute::Attribute, oca::layout::credential::Layout, oca::Overlay}; -use oca_ast_semantics::ast::OverlayType; -use said::derivation::HashFunctionCode; -use said::{sad::SerializationFormats, sad::SAD}; -use serde::{Deserialize, Serialize}; -use std::any::Any; - -pub trait CredentialLayouts { - fn add_credential_layout(&mut self, layout_str: String); -} - -impl CredentialLayouts for OCABox { - fn add_credential_layout(&mut self, layout_str: String) { - let yaml: Result = serde_yaml::from_str(&layout_str); - match yaml { - Ok(layout) => { - if let Some(layouts) = self.credential_layouts.as_mut() { - layouts.push(layout); - } else { - self.credential_layouts = Some(vec![layout]); - } - } - Err(e) => panic!("{:#?}", e), - } - } -} - -#[derive(SAD, Serialize, Deserialize, Clone, Debug)] -pub struct CredentialLayoutOverlay { - #[said] - #[serde(rename = "d")] - said: Option, - capture_base: Option, - #[serde(rename = "type")] - overlay_type: OverlayType, - pub layout: Layout, -} - -impl Overlay for CredentialLayoutOverlay { - fn as_any(&self) -> &dyn Any { - self - } - fn capture_base(&self) -> &Option { - &self.capture_base - } - fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) { - self.capture_base = Some(said.clone()); - } - fn said(&self) -> &Option { - &self.said - } - fn overlay_type(&self) -> &OverlayType { - &self.overlay_type - } - fn attributes(&self) -> Vec<&String> { - vec![] - } - - fn add(&mut self, _attribute: &Attribute) {} -} - -impl CredentialLayoutOverlay { - pub fn new(layout: Layout) -> Self { - Self { - capture_base: None, - said: None, - overlay_type: OverlayType::Layout, - layout, - } - } -} diff --git a/semantics/oca-bundle/src/state/oca/overlay/form_layout.rs b/semantics/oca-bundle/src/state/oca/overlay/form_layout.rs deleted file mode 100644 index be2353d7..00000000 --- a/semantics/oca-bundle/src/state/oca/overlay/form_layout.rs +++ /dev/null @@ -1,72 +0,0 @@ -use crate::state::oca::OCABox; -use crate::state::{attribute::Attribute, oca::layout::form::Layout, oca::Overlay}; -use oca_ast_semantics::ast::OverlayType; -use said::derivation::HashFunctionCode; -use said::{sad::SerializationFormats, sad::SAD}; -use serde::{Deserialize, Serialize}; -use std::any::Any; - -pub trait FormLayouts { - fn add_form_layout(&mut self, layout_str: String); -} - -impl FormLayouts for OCABox { - fn add_form_layout(&mut self, layout_str: String) { - let yaml: Result = serde_yaml::from_str(&layout_str); - match yaml { - Ok(layout) => { - if let Some(layouts) = self.form_layouts.as_mut() { - layouts.push(layout); - } else { - self.form_layouts = Some(vec![layout]); - } - } - Err(e) => panic!("{:#?}", e), - } - } -} - -#[derive(SAD, Serialize, Deserialize, Clone, Debug)] -pub struct FormLayoutOverlay { - #[said] - #[serde(rename = "d")] - said: Option, - capture_base: Option, - #[serde(rename = "type")] - overlay_type: OverlayType, - pub layout: Layout, -} - -impl Overlay for FormLayoutOverlay { - fn as_any(&self) -> &dyn Any { - self - } - fn capture_base(&self) -> &Option { - &self.capture_base - } - fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) { - self.capture_base = Some(said.clone()); - } - fn overlay_type(&self) -> &OverlayType { - &self.overlay_type - } - fn said(&self) -> &Option { - &self.said - } - fn attributes(&self) -> Vec<&String> { - vec![] - } - - fn add(&mut self, _attribute: &Attribute) {} -} - -impl FormLayoutOverlay { - pub fn new(layout: Layout) -> Self { - Self { - capture_base: None, - said: None, - overlay_type: OverlayType::Layout, - layout, - } - } -} diff --git a/semantics/oca-bundle/tests/create_oca_test.rs b/semantics/oca-bundle/tests/create_oca_test.rs index 2a1c8af2..ddb21f03 100644 --- a/semantics/oca-bundle/tests/create_oca_test.rs +++ b/semantics/oca-bundle/tests/create_oca_test.rs @@ -14,8 +14,6 @@ use oca_bundle_semantics::state::{ oca::overlay::label::Labels, oca::overlay::meta::Metas, oca::overlay::unit::Units, - /* oca::overlay::form_layout::FormLayouts, - oca::overlay::credential_layout::CredentialLayouts; */ oca::OCABox, }; @@ -27,24 +25,10 @@ use maplit::hashmap; #[test] fn create_oca() { - /* let form_layout = r#" - elements: - - type: "test" - "#; - let credential_layout = r#" - version: "1.0" - pages: - - config: - name: "test" - elements: - - type: "test" - "#; */ let mut oca = cascade! { OCABox::new(); ..add_meta(Language::Eng, "name".to_string(), "Test".to_string()); ..add_meta(Language::Eng, "description".to_string(), "Test case OCA".to_string()); - /* ..add_form_layout(form_layout.to_string()); - ..add_credential_layout(credential_layout.to_string()); */ }; let mut attribute = cascade! {