From b7875dc4072abeec26f93b3d322d00cecff23cfb Mon Sep 17 00:00:00 2001 From: jelemux Date: Fri, 26 Feb 2021 16:46:50 +0100 Subject: add communication property --- src/view/main.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 6 deletions(-) (limited to 'src/view/main.rs') diff --git a/src/view/main.rs b/src/view/main.rs index dd32e33..9ce032a 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -1,4 +1,5 @@ use crate::model::property_groups::address::*; +use crate::model::property_groups::communication::*; use crate::model::property_groups::name::*; use crate::model::property_groups::organizational::*; use crate::model::property_groups::other_identification::*; @@ -28,6 +29,7 @@ type OtherIdentificationView = PropertyGroupInputComponent; type OrganizationalView = PropertyGroupInputComponent; type TelephoneView = PropertyGroupInputComponent; +type CommunicationView = PropertyGroupInputComponent; pub struct MainView { link: ComponentLink, @@ -39,6 +41,7 @@ pub struct MainView { name_links: Vec>, address_links: Vec>, telephone_links: Vec>, + communcation_links: Vec>, other_identifications_links: Vec>, organizational_links: Vec>, @@ -56,6 +59,8 @@ pub enum Msg { DelOtherIdentification(usize), AddOrganizational, DelOrganizational(usize), + AddCommunication, + DelCommunication(usize), ChangeDownloadOption(DownloadOption), @@ -65,6 +70,7 @@ pub enum Msg { GeneratedAddress(Address), GeneratedTelephone(Telephone), GeneratedOrganizational(Organizational), + GeneratedCommunication(Communication), GenerationComplete, Nope, @@ -85,6 +91,7 @@ impl Component for MainView { name_links: vec![WeakComponentLink::default()], address_links: vec![WeakComponentLink::default()], telephone_links: vec![WeakComponentLink::default()], + communcation_links: vec![WeakComponentLink::default()], other_identifications_links: vec![WeakComponentLink::default()], organizational_links: vec![WeakComponentLink::default()], answer_count: 0, @@ -136,6 +143,14 @@ impl Component for MainView { self.organizational_links.remove(idx); true } + Msg::AddCommunication => { + self.communcation_links.push(WeakComponentLink::default()); + true + } + Msg::DelCommunication(idx) => { + self.communcation_links.remove(idx); + true + } Msg::ChangeDownloadOption(option) => { self.selected_option = option; false @@ -159,15 +174,20 @@ impl Component for MainView { telephone_link.send_message(TelephoneMsg::Generate); } - for dates_link in self.other_identifications_links.iter() { - let dates_link = dates_link.borrow().clone().unwrap(); - dates_link.send_message(OtherIdentificationMsg::Generate) + for other_identifications_link in self.other_identifications_links.iter() { + let other_identifications_link = other_identifications_link.borrow().clone().unwrap(); + other_identifications_link.send_message(OtherIdentificationMsg::Generate) } - for organizational_links in self.organizational_links.iter() { - let organizational_link = organizational_links.borrow().clone().unwrap(); + for organizational_link in self.organizational_links.iter() { + let organizational_link = organizational_link.borrow().clone().unwrap(); organizational_link.send_message(OrganizationalMsg::Generate) } + + for communcation_link in self.communcation_links.iter() { + let communcation_link = communcation_link.borrow().clone().unwrap(); + communcation_link.send_message(CommunicationMsg::Generate) + } } /* DownloadOption::PDF => { @@ -235,6 +255,18 @@ impl Component for MainView { true } + Msg::GeneratedCommunication(communication) => { + self.answer_count += 1; + + match self.vcard_data.get_mut() { + Some(vcard_data) => vcard_data.add_communication(communication), + None => ConsoleService::info( + "Error in GeneratedCommunication: Couldn't get mutable borrow of VCardData", + ), + }; + + true + } Msg::GeneratedOrganizational(organizational) => { self.answer_count += 1; @@ -363,6 +395,15 @@ impl Component for MainView { } } + for communication in vcard_data.communications { + if !communication.email_address.is_empty() { + builder = builder.with_email(communication.email_address.clone()); + } + if !communication.impp.is_empty() { + builder = builder.with_impp(communication.impp.clone()); + } + } + for other_identification in vcard_data.other_identifications { if !other_identification.nickname.is_empty() { builder = @@ -469,7 +510,7 @@ impl Component for MainView { true } - Msg::Nope => false + Msg::Nope => false, }; if self.answer_count >= self.get_subcomponent_count() { @@ -614,6 +655,31 @@ impl Component for MainView { ) } +
+
+
+

{ "Communication" }

+
+
+ +
+
+
+ + { + for self.communcation_links.iter().enumerate().map(move |(idx, link)| + html!{ + + } + ) + } +
@@ -801,5 +867,6 @@ impl MainView { + self.telephone_links.len() + self.other_identifications_links.len() + self.organizational_links.len() + + self.communcation_links.len() } } -- cgit v1.2.3