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/model/address.rs | 2 +- src/model/dates.rs | 69 ----------------------- src/model/mod.rs | 65 +++++++++++++++++---- src/model/name.rs | 2 +- src/model/organizational.rs | 2 +- src/model/other_identification.rs | 116 ++++++++++++++++++++++++++++++++++++++ src/model/telephone.rs | 2 +- src/model/vcard.rs | 8 +-- 8 files changed, 179 insertions(+), 87 deletions(-) delete mode 100644 src/model/dates.rs create mode 100644 src/model/other_identification.rs (limited to 'src/model') diff --git a/src/model/address.rs b/src/model/address.rs index 2c42a98..2321f82 100644 --- a/src/model/address.rs +++ b/src/model/address.rs @@ -28,7 +28,7 @@ pub enum AddressMsg { Generate, } -impl VCardPropertyInputObject for Address { +impl VCardPropertyInputGroupObject for Address { fn new() -> Self { Self { post_office_box: String::new(), diff --git a/src/model/dates.rs b/src/model/dates.rs deleted file mode 100644 index 192f986..0000000 --- a/src/model/dates.rs +++ /dev/null @@ -1,69 +0,0 @@ -use super::*; - -/// Type that represents the vcard `anniversary` and `birthday` properties. -#[derive(Clone, Debug, PartialEq)] -pub struct Dates { - pub anniversary: String, - pub birthday: String, -} - -#[derive(Clone, PartialEq)] -pub enum DatesMsg { - UpdateAnniversary(String), - UpdateBirthday(String), - - Generate, -} - -impl VCardPropertyInputObject for Dates { - fn new() -> Self { - Self { - anniversary: String::new(), - birthday: String::new(), - } - } - fn get_title(&self) -> std::string::String { - "Dates".to_string() - } - fn get_input_fields( - &self, - link: &yew::html::Scope>, - ) -> std::vec::Vec { - let typ = String::from("date"); - vec![ - VCardPropertyInputField::Text { - label: "Anniversary".to_string(), - id: Some("anniversary".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| DatesMsg::UpdateAnniversary(e.value)), - value: self.anniversary.clone(), - typ: typ.clone(), - }, - VCardPropertyInputField::Text { - label: "Birthday".to_string(), - id: Some("birthday".to_string()), - placeholder: None, - oninput: link.callback(|e: InputData| DatesMsg::UpdateBirthday(e.value)), - value: self.birthday.clone(), - typ, - }, - ] - } - fn update( - &mut self, - props: InputProps, - msg: as yew::Component>::Message, - ) -> bool { - match msg { - DatesMsg::UpdateAnniversary(a) => self.anniversary = a, - DatesMsg::UpdateBirthday(b) => self.birthday = b, - DatesMsg::Generate => { - props.generated.emit(self.clone()); - } - }; - true - } - fn is_empty(&self) -> bool { - self.anniversary.is_empty() && self.birthday.is_empty() - } -} diff --git a/src/model/mod.rs b/src/model/mod.rs index 45c91f1..b8dcfff 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -7,23 +7,23 @@ use yew::prelude::*; use yew::services::ConsoleService; pub mod address; -pub mod dates; pub mod name; pub mod organizational; +pub mod other_identification; pub mod telephone; pub mod utility; pub mod vcard; /// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`. -pub trait VCardPropertyInputObject: Clone + PartialEq +pub trait VCardPropertyInputGroupObject: Clone + PartialEq where Self: Sized, { - /// Function for creating a new (and empty) `VCardPropertyInputObject`. + /// Function for creating a new (and empty) `VCardPropertyInputGroupObject`. fn new() -> Self; /// Getter function for the title of the component fn get_title(&self) -> String; - /// Converts each field of the `VCardPropertyInputObject` to a VCardPropertyInputField and returns them as a vector. + /// Converts each field of the `VCardPropertyInputGroupObject` to a VCardPropertyInputField and returns them as a vector. fn get_input_fields( &self, link: &ComponentLink>, @@ -33,7 +33,7 @@ where props: InputProps, msg: as yew::Component>::Message, ) -> bool; - /// Returns a `Html` representation of the `VCardPropertyInputObject`. + /// Returns a `Html` representation of the `VCardPropertyInputGroupObject`. fn render(&self, link: &ComponentLink>) -> Html { html! {
@@ -45,7 +45,7 @@ where
} } - /// Convenience function for checking if the `VCardPropertyInputObject` is empty. + /// Convenience function for checking if the `VCardPropertyInputGroupObject` is empty. fn is_empty(&self) -> bool; } @@ -73,6 +73,13 @@ pub enum VCardPropertyInputField { callback: Callback>, value: Option, }, + Select { + label: String, + id: Option, + options: Vec<(String, String)>, + onchange: Callback, + value: String, + }, CheckBox { label: String, id: Option, @@ -99,6 +106,13 @@ impl VCardPropertyInputField { callback, value, } => Self::file_field_input(label, name, callback, value), + Self::Select { + label, + id, + options, + onchange, + value, + } => Self::select_field_input(label, id, options, onchange, value), Self::CheckBox { label, id, @@ -180,10 +194,10 @@ impl VCardPropertyInputField { }); html! {
+ is-one-third-widescreen + is-two-quarters-desktop + is-two-thirds-tablet + is-full-mobile" >
} } + fn select_field_input( + label: &str, + id: &Option, + options: &Vec<(String, String)>, + onchange: &Callback, + value: &str, + ) -> Html { + html! { +
+ +
+ +
+ +
+ } + } /// Returns an `Html` representation of a checkbox input field with the given parameters. fn checkbox_field_input( label: &str, diff --git a/src/model/name.rs b/src/model/name.rs index 915579d..8cc889c 100644 --- a/src/model/name.rs +++ b/src/model/name.rs @@ -35,7 +35,7 @@ pub enum NameMsg { Generate, } -impl VCardPropertyInputObject for Name { +impl VCardPropertyInputGroupObject for Name { fn new() -> Self { Self { prefix: String::new(), diff --git a/src/model/organizational.rs b/src/model/organizational.rs index f82f5d7..cfdb44d 100644 --- a/src/model/organizational.rs +++ b/src/model/organizational.rs @@ -22,7 +22,7 @@ pub enum OrganizationalMsg { Generate, } -impl VCardPropertyInputObject for Organizational { +impl VCardPropertyInputGroupObject for Organizational { fn new() -> Self { Self { org: String::new(), diff --git a/src/model/other_identification.rs b/src/model/other_identification.rs new file mode 100644 index 0000000..a01b818 --- /dev/null +++ b/src/model/other_identification.rs @@ -0,0 +1,116 @@ +use super::*; + +/// Type that represents the vcard `anniversary` and `birthday` properties. +#[derive(Clone, Debug, PartialEq)] +pub struct OtherIdentification { + pub nickname: String, + pub photo: Option, + pub birthday: String, + pub anniversary: String, + pub gender: String, +} + +#[derive(Clone, PartialEq)] +pub enum OtherIdentificationMsg { + UpdateNickname(String), + UpdatePhoto(Option), + UpdateBirthday(String), + UpdateAnniversary(String), + UpdateGender(String), + + Generate, + + Nope, +} + +impl VCardPropertyInputGroupObject for OtherIdentification { + fn new() -> Self { + Self { + nickname: String::new(), + photo: None, + birthday: String::new(), + anniversary: String::new(), + gender: String::new(), + } + } + fn get_title(&self) -> std::string::String { + "Other Identification Properties".to_string() + } + fn get_input_fields( + &self, + link: &yew::html::Scope>, + ) -> std::vec::Vec { + vec![ + VCardPropertyInputField::Text { + label: String::from("Nickname"), + id: Some(String::from("nickname")), + placeholder: None, + oninput: link + .callback(|e: InputData| OtherIdentificationMsg::UpdateNickname(e.value)), + value: self.nickname.clone(), + typ: String::from("text"), + }, + VCardPropertyInputField::File { + label: String::from("Photo"), + name: String::from("photo"), + callback: link + .callback(|file: Option| OtherIdentificationMsg::UpdatePhoto(file)), + value: self.photo.clone(), + }, + VCardPropertyInputField::Text { + label: "Birthday".to_string(), + id: Some("birthday".to_string()), + placeholder: None, + oninput: link + .callback(|e: InputData| OtherIdentificationMsg::UpdateBirthday(e.value)), + value: self.birthday.clone(), + typ: String::from("date"), + }, + VCardPropertyInputField::Text { + label: "Anniversary".to_string(), + id: Some("anniversary".to_string()), + placeholder: None, + oninput: link + .callback(|e: InputData| OtherIdentificationMsg::UpdateAnniversary(e.value)), + value: self.anniversary.clone(), + typ: String::from("date"), + }, + VCardPropertyInputField::Select { + label: String::from("Gender"), + id: Some(String::from("gender")), + options: vec![ + (String::from(""), String::from("Select one")), + (String::from("M"), String::from("Male")), + (String::from("F"), String::from("Female")), + (String::from("O"), String::from("Other")), + (String::from("N"), String::from("Not applicable")), + (String::from("U"), String::from("Unknown")), + ], + onchange: link.callback(|c: ChangeData| match c { + ChangeData::Select(v) => OtherIdentificationMsg::UpdateGender(v.value()), + _ => OtherIdentificationMsg::Nope, + }), + value: self.gender.clone(), + }, + ] + } + fn update( + &mut self, + props: InputProps, + msg: as yew::Component>::Message, + ) -> bool { + match msg { + OtherIdentificationMsg::UpdateNickname(n) => self.nickname = n, + OtherIdentificationMsg::UpdatePhoto(p) => self.photo = p, + OtherIdentificationMsg::UpdateBirthday(b) => self.birthday = b, + OtherIdentificationMsg::UpdateAnniversary(a) => self.anniversary = a, + OtherIdentificationMsg::UpdateGender(g) => self.gender = g, + OtherIdentificationMsg::Generate => props.generated.emit(self.clone()), + OtherIdentificationMsg::Nope => (), + }; + true + } + fn is_empty(&self) -> bool { + self.anniversary.is_empty() && self.birthday.is_empty() + } +} diff --git a/src/model/telephone.rs b/src/model/telephone.rs index 946da33..b571aa4 100644 --- a/src/model/telephone.rs +++ b/src/model/telephone.rs @@ -30,7 +30,7 @@ pub enum TelephoneMsg { Generate, } -impl VCardPropertyInputObject for Telephone { +impl VCardPropertyInputGroupObject for Telephone { fn new() -> Self { Self { number: String::new(), diff --git a/src/model/vcard.rs b/src/model/vcard.rs index ee7e28e..185ae71 100644 --- a/src/model/vcard.rs +++ b/src/model/vcard.rs @@ -1,7 +1,7 @@ use crate::model::address::Address; -use crate::model::dates::Dates; use crate::model::name::Name; use crate::model::organizational::Organizational; +use crate::model::other_identification::OtherIdentification; use crate::model::telephone::Telephone; /// Type that represents the data structure of a vcard. @@ -10,7 +10,7 @@ pub struct VCardData { pub names: Vec, pub addresses: Vec
, pub telephones: Vec, - pub datess: Vec, + pub other_identifications: Vec, pub organizationals: Vec, } @@ -28,13 +28,13 @@ impl VCardData { names: Vec::new(), addresses: Vec::new(), telephones: Vec::new(), - datess: Vec::new(), + other_identifications: Vec::new(), organizationals: Vec::new(), } } make_vec_adder_fn!( fn add_name names => name: Name ); make_vec_adder_fn!( fn add_address addresses => address: Address ); make_vec_adder_fn!( fn add_telephone telephones => telephone: Telephone ); - make_vec_adder_fn!( fn add_dates datess => dates: Dates ); + make_vec_adder_fn!( fn add_other_identification other_identifications => other_identification: OtherIdentification ); make_vec_adder_fn!( fn add_organizational organizationals => organizational: Organizational ); } -- cgit v1.2.3