From d0d42c5ae00560e4464479a98df90ed063a1c773 Mon Sep 17 00:00:00 2001 From: jelemux Date: Wed, 17 Feb 2021 19:43:30 +0100 Subject: change dates to other_identification and add some stuff --- src/view/main.rs | 93 +++++++++++++++++++++++++++------------------- src/view/property_group.rs | 8 ++-- 2 files changed, 58 insertions(+), 43 deletions(-) (limited to 'src/view') diff --git a/src/view/main.rs b/src/view/main.rs index d35fb59..808b160 100644 --- a/src/view/main.rs +++ b/src/view/main.rs @@ -1,14 +1,14 @@ -use crate::view::property_group::PropertyGroupInputComponent; -use crate::view::weak_links::WeakComponentLink; use crate::model::address::*; -use crate::model::dates::*; use crate::model::name::*; use crate::model::organizational::*; +use crate::model::other_identification::*; use crate::model::telephone::*; use crate::model::utility::*; use crate::model::vcard::VCardData; use crate::model::Error; -use crate::model::VCardPropertyInputObject; +use crate::model::VCardPropertyInputGroupObject; +use crate::view::property_group::PropertyGroupInputComponent; +use crate::view::weak_links::WeakComponentLink; use boolinator::Boolinator; use chrono::prelude::*; use genpdf::Element as _; @@ -23,7 +23,8 @@ use yewtil::ptr::Mrc; type NameView = PropertyGroupInputComponent; type AddressView = PropertyGroupInputComponent; -type DatesView = PropertyGroupInputComponent; +type OtherIdentificationView = + PropertyGroupInputComponent; type OrganizationalView = PropertyGroupInputComponent; type TelephoneView = PropertyGroupInputComponent; @@ -37,7 +38,7 @@ pub struct MainView { name_links: Vec>, address_links: Vec>, telephone_links: Vec>, - dates_links: Vec>, + other_identifications_links: Vec>, organizational_links: Vec>, answer_count: usize, @@ -54,9 +55,9 @@ pub enum Msg { Generate, GeneratedName(Name), + GeneratedOtherIdentification(OtherIdentification), GeneratedAddress(Address), GeneratedTelephone(Telephone), - GeneratedDates(Dates), GeneratedOrganizational(Organizational), GenerationComplete, @@ -78,7 +79,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()], + other_identifications_links: vec![WeakComponentLink::default()], organizational_links: vec![WeakComponentLink::default()], answer_count: 0, } @@ -102,7 +103,7 @@ impl Component for MainView { shouldrender = true; } Msg::AddDates => { - self.dates_links.push(WeakComponentLink::default()); + self.other_identifications_links.push(WeakComponentLink::default()); shouldrender = true; } Msg::AddOrganizational => { @@ -132,9 +133,9 @@ impl Component for MainView { telephone_link.send_message(TelephoneMsg::Generate); } - for dates_link in self.dates_links.iter() { + for dates_link in self.other_identifications_links.iter() { let dates_link = dates_link.borrow().clone().unwrap(); - dates_link.send_message(DatesMsg::Generate) + dates_link.send_message(OtherIdentificationMsg::Generate) } for organizational_links in self.organizational_links.iter() { @@ -172,37 +173,37 @@ impl Component for MainView { shouldrender = true; } - Msg::GeneratedAddress(address) => { + Msg::GeneratedOtherIdentification(other_identification) => { self.answer_count += 1; match self.vcard_data.get_mut() { - Some(vcard_data) => vcard_data.add_address(address), + Some(vcard_data) => vcard_data.add_other_identification(other_identification), None => ConsoleService::info( - "Error in GeneratedAddress: Couldn't get mutable borrow of VCardData", + "Error in GeneratedOtherIdentification: Couldn't get mutable borrow of VCardData", ), }; shouldrender = true; } - Msg::GeneratedTelephone(telephone) => { + Msg::GeneratedAddress(address) => { self.answer_count += 1; match self.vcard_data.get_mut() { - Some(vcard_data) => vcard_data.add_telephone(telephone), + Some(vcard_data) => vcard_data.add_address(address), None => ConsoleService::info( - "Error in GeneratedTelephone: Couldn't get mutable borrow of VCardData", + "Error in GeneratedAddress: Couldn't get mutable borrow of VCardData", ), }; shouldrender = true; } - Msg::GeneratedDates(dates) => { + Msg::GeneratedTelephone(telephone) => { self.answer_count += 1; match self.vcard_data.get_mut() { - Some(vcard_data) => vcard_data.add_dates(dates), + Some(vcard_data) => vcard_data.add_telephone(telephone), None => ConsoleService::info( - "Error in GeneratedDates: Couldn't get mutable borrow of VCardData", + "Error in GeneratedTelephone: Couldn't get mutable borrow of VCardData", ), }; @@ -336,13 +337,27 @@ impl Component for MainView { } } - for dates in vcard_data.datess { - if !dates.anniversary.is_empty() { - builder = builder.with_anniversary(dates.anniversary); + for other_identification in vcard_data.other_identifications { + if !other_identification.nickname.is_empty() { + builder = + builder.with_nickname(parameters!(), other_identification.nickname); + } + + match other_identification.photo { + Some(file) => builder = builder.with_photo(parameters!(), file.content), + None => (), + }; + + if !other_identification.anniversary.is_empty() { + builder = builder.with_anniversary(other_identification.anniversary); } - if !dates.birthday.is_empty() { - builder = builder.with_bday(parameters!(), dates.birthday); + if !other_identification.birthday.is_empty() { + builder = builder.with_bday(parameters!(), other_identification.birthday); + } + + if !other_identification.gender.is_empty() { + builder = builder.with_gender(parameters!(), other_identification.gender); } } @@ -483,6 +498,19 @@ impl Component for MainView { ) } + { + for self.other_identifications_links.iter().map(|link| + html!{ + + } + ) + } + { for self.address_links.iter().map(|link| html!{ @@ -509,19 +537,6 @@ impl Component for MainView { ) } - { - for self.dates_links.iter().map(|link| - html!{ - - } - ) - } - { for self.organizational_links.iter().map(|link| html!{ @@ -695,7 +710,7 @@ impl MainView { self.name_links.len() + self.address_links.len() + self.telephone_links.len() - + self.dates_links.len() + + self.other_identifications_links.len() + self.organizational_links.len() } } diff --git a/src/view/property_group.rs b/src/view/property_group.rs index 9c86e80..f4b62a4 100644 --- a/src/view/property_group.rs +++ b/src/view/property_group.rs @@ -5,7 +5,7 @@ use yewtil::NeqAssign; #[derive(Clone, PartialEq, Properties)] pub struct InputProps< - O: 'static + VCardPropertyInputObject + Clone, + O: 'static + VCardPropertyInputGroupObject + Clone, M: 'static + PartialEq + Clone, > { pub generated: Callback, @@ -14,7 +14,7 @@ pub struct InputProps< #[derive(Clone, PartialEq)] pub struct PropertyGroupInputComponent< - O: 'static + VCardPropertyInputObject, + O: 'static + VCardPropertyInputGroupObject, M: 'static + PartialEq + Clone, > { pub props: InputProps, @@ -22,7 +22,7 @@ pub struct PropertyGroupInputComponent< pub error: Option, } -impl, M: 'static + PartialEq + Clone> Component +impl, M: 'static + PartialEq + Clone> Component for PropertyGroupInputComponent { type Message = M; @@ -57,7 +57,7 @@ impl, M: 'static + PartialEq + Clone> C } } -impl, M: 'static + PartialEq + Clone> +impl, M: 'static + PartialEq + Clone> PropertyGroupInputComponent { /// Returns the error as `Html` -- cgit v1.2.3