From fd5b054fe655c81533c8a1138ba55a82a7b9d085 Mon Sep 17 00:00:00 2001 From: jelemux Date: Fri, 5 Feb 2021 18:05:16 +0100 Subject: add date properties --- src/view/main.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/view/main.rs') diff --git a/src/view/main.rs b/src/view/main.rs index 83acc3f..0d2cddb 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -1,3 +1,4 @@ +use crate::viewmodel::dates::Dates; use yew::services::ConsoleService; use crate::viewmodel::vcard::VCardData; use crate::viewmodel::Error; @@ -6,6 +7,7 @@ use crate::viewmodel::VCardPropertyInputObject; use super::WeakComponentLink; use super::name::{self,NameView}; use super::address::{self,AddressView}; +use super::dates::{self,DatesView}; use genpdf::Element as _; use genpdf::{elements, style, fonts}; use qrcodegen::QrCode; @@ -32,6 +34,7 @@ pub struct MainView { name_links: Vec>, address_links: Vec>, telephone_links: Vec>, + dates_links: Vec>, answer_count: usize, } @@ -40,6 +43,7 @@ pub enum Msg { AddName, AddAddress, AddTelephone, + AddDates, ChangeDownloadOption(DownloadOption), @@ -47,6 +51,7 @@ pub enum Msg { GeneratedName(Name), GeneratedAddress(Address), GeneratedTelephone(Telephone), + GeneratedDates(Dates), GenerationComplete, Nope, @@ -67,6 +72,7 @@ impl Component for MainView { name_links: vec![WeakComponentLink::default()], address_links: vec![WeakComponentLink::default()], telephone_links: vec![WeakComponentLink::default()], + dates_links: vec![WeakComponentLink::default()], answer_count: 0, } } @@ -88,6 +94,10 @@ impl Component for MainView { self.telephone_links.push(WeakComponentLink::default()); shouldrender = true; }, + Msg::AddDates => { + self.dates_links.push(WeakComponentLink::default()); + shouldrender = true; + }, Msg::ChangeDownloadOption(option) => { self.selected_option = option; shouldrender = false; @@ -110,6 +120,11 @@ impl Component for MainView { let telephone_link = telephone_link.borrow().clone().unwrap(); telephone_link.send_message(telephone::Msg::Generate); } + + for dates_link in self.dates_links.iter() { + let dates_link = dates_link.borrow().clone().unwrap(); + dates_link.send_message(dates::Msg::Generate) + } } /* DownloadOption::PDF => { @@ -163,6 +178,17 @@ impl Component for MainView { shouldrender = true; }, + Msg::GeneratedDates(dates) => { + + self.answer_count += 1; + + match self.vcard_data.get_mut() { + Some(vcard_data) => vcard_data.add_dates(dates), + None => ConsoleService::info("Error in GeneratedDates: Couldn't get mutable borrow of VCardData"), + }; + + shouldrender = true; + }, Msg::GenerationComplete => { self.answer_count = 0; @@ -305,6 +331,20 @@ impl Component for MainView { ); } } + + for dates in vcard_data.datess { + + if !dates.anniversary.is_empty() { + builder = builder.with_anniversary(dates.anniversary); + } + + if !dates.birthday.is_empty() { + builder = builder.with_bday( + parameters!(), + dates.birthday + ); + } + } let rev = Local::now(); @@ -445,6 +485,19 @@ impl Component for MainView { ) } + { + for self.dates_links.iter().map(|link| + html!{ + + } + ) + } +
@@ -587,5 +640,6 @@ impl MainView { self.name_links.len() + self.address_links.len() + self.telephone_links.len() + + self.dates_links.len() } } \ No newline at end of file -- cgit v1.2.3