From ad9ba30ed217ec9907d1faf389c321a1dcf5c13a Mon Sep 17 00:00:00 2001 From: jelemux Date: Sun, 7 Feb 2021 21:43:48 +0100 Subject: add organizational properties --- src/view/address.rs | 11 +++--- src/view/dates.rs | 11 +++--- src/view/main.rs | 66 ++++++++++++++++++++++++++++++++++++ src/view/mod.rs | 12 ++++++- src/view/name.rs | 11 +++--- src/view/organizational.rs | 83 ++++++++++++++++++++++++++++++++++++++++++++++ src/view/telephone.rs | 11 +++--- 7 files changed, 176 insertions(+), 29 deletions(-) create mode 100644 src/view/organizational.rs (limited to 'src/view') diff --git a/src/view/address.rs b/src/view/address.rs index 1aedcbd..a945272 100644 --- a/src/view/address.rs +++ b/src/view/address.rs @@ -1,11 +1,13 @@ +use crate::view::InputProps; use yew::prelude::*; use yewtil::NeqAssign; -use super::WeakComponentLink; use crate::viewmodel::address::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; use crate::viewmodel::Error; +type Props = InputProps; + /// View Component for a `address` field /// /// # Examples @@ -20,6 +22,7 @@ use crate::viewmodel::Error; /// /> /// }; /// ``` +#[derive(Clone,PartialEq)] pub struct AddressView { props: Props, value: Address, @@ -40,12 +43,6 @@ pub enum Msg { Generate, } -#[derive(Clone, PartialEq, Properties)] -pub struct Props { - pub generated: Callback
, - pub weak_link: WeakComponentLink, -} - impl VCardPropertyInputComponent
for AddressView { fn get_input_object(&self) -> Address { self.value.clone() diff --git a/src/view/dates.rs b/src/view/dates.rs index 1c16680..de3d311 100644 --- a/src/view/dates.rs +++ b/src/view/dates.rs @@ -1,11 +1,14 @@ +use crate::view::InputProps; use yew::prelude::*; use yewtil::NeqAssign; use crate::viewmodel::Error; -use crate::view::WeakComponentLink; use crate::viewmodel::dates::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; +type Props = InputProps; + +#[derive(Clone,PartialEq)] pub struct DatesView { props: Props, value: Dates, @@ -19,12 +22,6 @@ pub enum Msg { Generate, } -#[derive(Clone, PartialEq, Properties)] -pub struct Props { - pub generated: Callback, - pub weak_link: WeakComponentLink, -} - impl VCardPropertyInputComponent for DatesView { fn get_input_object(&self) -> Dates { self.value.clone() diff --git a/src/view/main.rs b/src/view/main.rs index 0d2cddb..c2af72a 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -1,3 +1,5 @@ +use crate::viewmodel::organizational::Organizational; +use crate::view::organizational::{self,OrganizationalView}; use crate::viewmodel::dates::Dates; use yew::services::ConsoleService; use crate::viewmodel::vcard::VCardData; @@ -35,6 +37,7 @@ pub struct MainView { address_links: Vec>, telephone_links: Vec>, dates_links: Vec>, + organizational_links: Vec>, answer_count: usize, } @@ -44,6 +47,7 @@ pub enum Msg { AddAddress, AddTelephone, AddDates, + AddOrganizational, ChangeDownloadOption(DownloadOption), @@ -52,6 +56,7 @@ pub enum Msg { GeneratedAddress(Address), GeneratedTelephone(Telephone), GeneratedDates(Dates), + GeneratedOrganizational(Organizational), GenerationComplete, Nope, @@ -73,6 +78,7 @@ impl Component for MainView { address_links: vec![WeakComponentLink::default()], telephone_links: vec![WeakComponentLink::default()], dates_links: vec![WeakComponentLink::default()], + organizational_links: vec![WeakComponentLink::default()], answer_count: 0, } } @@ -98,6 +104,10 @@ impl Component for MainView { self.dates_links.push(WeakComponentLink::default()); shouldrender = true; }, + Msg::AddOrganizational => { + self.organizational_links.push(WeakComponentLink::default()); + shouldrender = true; + }, Msg::ChangeDownloadOption(option) => { self.selected_option = option; shouldrender = false; @@ -125,6 +135,11 @@ impl Component for MainView { let dates_link = dates_link.borrow().clone().unwrap(); dates_link.send_message(dates::Msg::Generate) } + + for organizational_links in self.organizational_links.iter() { + let organizational_link = organizational_links.borrow().clone().unwrap(); + organizational_link.send_message(organizational::Msg::Generate) + } } /* DownloadOption::PDF => { @@ -189,6 +204,16 @@ impl Component for MainView { shouldrender = true; }, + Msg::GeneratedOrganizational(organizational) => { + self.answer_count += 1; + + match self.vcard_data.get_mut() { + Some(vcard_data) => vcard_data.add_organizational(organizational), + None => ConsoleService::info("Error in GeneratedOrganizational: Couldn't get mutable borrow of VCardData"), + }; + + shouldrender = true; + }, Msg::GenerationComplete => { self.answer_count = 0; @@ -345,6 +370,33 @@ impl Component for MainView { ); } } + + for organizational in vcard_data.organizationals { + + if !organizational.org.is_empty() { + builder = builder.with_org(vec![organizational.org]); + } + + if !organizational.logo.is_empty() { + builder = builder.with_logo(organizational.logo); + } + + if !organizational.title.is_empty() { + builder = builder.with_title(organizational.title); + } + + if !organizational.role.is_empty() { + builder = builder.with_role(organizational.role); + } + + if !organizational.member.is_empty() { + builder = builder.with_member(organizational.member); + } + + if !organizational.related.is_empty() { + builder = builder.with_related(organizational.related); + } + } let rev = Local::now(); @@ -498,6 +550,19 @@ impl Component for MainView { ) } + { + for self.organizational_links.iter().map(|link| + html!{ + + } + ) + } +
@@ -641,5 +706,6 @@ impl MainView { + self.address_links.len() + self.telephone_links.len() + self.dates_links.len() + + self.organizational_links.len() } } \ No newline at end of file diff --git a/src/view/mod.rs b/src/view/mod.rs index 65ef06d..0751c53 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -9,9 +9,19 @@ pub mod name; pub mod address; pub mod telephone; pub mod dates; +pub mod organizational; + +#[derive(Clone, PartialEq, Properties)] +pub struct InputProps + where O: VCardPropertyInputObject + Clone, + C: VCardPropertyInputComponent + Clone +{ + pub generated: Callback, + pub weak_link: WeakComponentLink, +} /// Trait for types that represent an input component for a vcard property. -pub trait VCardPropertyInputComponent>: Component { +pub trait VCardPropertyInputComponent>: Component + Clone + PartialEq { /// Returns the object containing the input data. fn get_input_object(&self) -> T; /// Getter function for the title of the component diff --git a/src/view/name.rs b/src/view/name.rs index 27dadf1..4976e7d 100644 --- a/src/view/name.rs +++ b/src/view/name.rs @@ -1,11 +1,13 @@ +use crate::view::InputProps; use yew::prelude::*; use yewtil::NeqAssign; use crate::viewmodel::Error; -use crate::view::WeakComponentLink; use crate::viewmodel::name::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; +type Props = InputProps; + /// View Component for a `name` field /// /// # Examples @@ -20,6 +22,7 @@ use super::VCardPropertyInputComponent; /// /> /// }; /// ``` +#[derive(Clone,PartialEq)] pub struct NameView { props: Props, value: Name, @@ -36,12 +39,6 @@ pub enum Msg { Generate, } -#[derive(Clone, PartialEq, Properties)] -pub struct Props { - pub generated: Callback, - pub weak_link: WeakComponentLink, -} - impl VCardPropertyInputComponent for NameView { fn get_input_object(&self) -> Name { self.value.clone() diff --git a/src/view/organizational.rs b/src/view/organizational.rs new file mode 100644 index 0000000..b11c181 --- /dev/null +++ b/src/view/organizational.rs @@ -0,0 +1,83 @@ +use yew::prelude::*; +use yewtil::NeqAssign; +use crate::viewmodel::Error; +use crate::view::InputProps; +use crate::viewmodel::organizational::*; +use crate::viewmodel::VCardPropertyInputObject; +use super::VCardPropertyInputComponent; + +type Props = InputProps; + +#[derive(Clone,PartialEq)] +pub struct OrganizationalView { + props: Props, + value: Organizational, + error: Option, +} + +pub enum Msg { + UpdateOrg(String), + UpdateLogo(String), + UpdateTitle(String), + UpdateRole(String), + UpdateMember(String), + UpdateRelated(String), + + Generate, +} + +impl VCardPropertyInputComponent for OrganizationalView { + fn get_input_object(&self) -> Organizational { + self.value.clone() + } + fn get_title(&self) -> std::string::String { + "Organizational".to_string() + } + fn get_error(&self) -> std::option::Option { + self.error.clone() + } +} + +impl Component for OrganizationalView { + type Message = Msg; + type Properties = Props; + fn create(props: ::Properties, link: yew::html::Scope) -> Self { + props.weak_link.borrow_mut().replace(link); + Self { + props, + value: Organizational::new(), + error: None, + } + } + fn update(&mut self, msg: ::Message) -> bool { + match msg { + Msg::UpdateOrg(o) => self.value.org = o, + Msg::UpdateLogo(l) => self.value.logo = l, + Msg::UpdateTitle(t) => self.value.title = t, + Msg::UpdateRole(r) => self.value.role = r, + Msg::UpdateMember(m) => self.value.member = m, + Msg::UpdateRelated(r) => self.value.related = r, + Msg::Generate => { + self.props.generated.emit(self.value.clone()); + }, + }; + true + } + fn change(&mut self, props: ::Properties) -> bool { + self.props.neq_assign(props) + } + fn view(&self) -> yew::virtual_dom::VNode { + let link = self.props.weak_link.borrow().clone().unwrap(); + + html!{ +
+ { self.render_error() } + +

{ self.get_title() }

+ + { self.get_input_object().render(&link) } + +
+ } + } +} \ No newline at end of file diff --git a/src/view/telephone.rs b/src/view/telephone.rs index 5db8ae1..dc93632 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,11 +1,13 @@ +use crate::view::InputProps; use yew::prelude::*; use yewtil::NeqAssign; -use crate::view::WeakComponentLink; use crate::viewmodel::Error; use crate::viewmodel::telephone::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; +type Props = InputProps; + /// View Component for a `telephone` field /// /// # Examples @@ -20,6 +22,7 @@ use super::VCardPropertyInputComponent; /// /> /// }; /// ``` +#[derive(Clone,PartialEq)] pub struct TelephoneView { props: Props, value: Telephone, @@ -41,12 +44,6 @@ pub enum Msg { Generate, } -#[derive(Clone, PartialEq, Properties)] -pub struct Props { - pub generated: Callback, - pub weak_link: WeakComponentLink, -} - impl VCardPropertyInputComponent for TelephoneView { fn get_input_object(&self) -> Telephone { self.value.clone() -- cgit v1.2.3