diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-07 21:43:48 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-07 21:43:48 +0100 |
commit | ad9ba30ed217ec9907d1faf389c321a1dcf5c13a (patch) | |
tree | 7fdadcde26842e4806881492b993b948c1f2032c /src/view/main.rs | |
parent | f88f8d7c7dc87cdf47de95b54cc6e9f8429820a4 (diff) | |
download | wasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.gz wasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.bz2 |
add organizational properties
Diffstat (limited to 'src/view/main.rs')
-rw-r--r-- | src/view/main.rs | 66 |
1 files changed, 66 insertions, 0 deletions
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<WeakComponentLink<AddressView>>, telephone_links: Vec<WeakComponentLink<TelephoneView>>, dates_links: Vec<WeakComponentLink<DatesView>>, + organizational_links: Vec<WeakComponentLink<OrganizationalView>>, 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!{ + <OrganizationalView weak_link=link + generated=self.link.callback( + |o: Organizational| + Msg::GeneratedOrganizational(o) + ) + /> + } + ) + } + <div class="block level-left"> <button onclick=self.link.callback(|_| Msg::Generate) class="button is-primary level-item">{ "Generate" }</button> @@ -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 |