diff options
author | jelemux <jeremias.weber@protonmail.com> | 2021-02-09 23:18:45 +0100 |
---|---|---|
committer | jelemux <jeremias.weber@protonmail.com> | 2021-02-09 23:18:45 +0100 |
commit | 036a567bae8346eb38f9237f59645dbcc4f1cd8c (patch) | |
tree | 21a86e3c5cb8964030c414718190af12f3d26125 /src/viewmodel | |
parent | 9df3ff8d633a18e934d4e62b0e2e718620760552 (diff) | |
download | wasm-card-036a567bae8346eb38f9237f59645dbcc4f1cd8c.tar.gz wasm-card-036a567bae8346eb38f9237f59645dbcc4f1cd8c.tar.bz2 |
switch to cargo-make; format files with rustfmt
Diffstat (limited to 'src/viewmodel')
-rw-r--r-- | src/viewmodel/address.rs | 36 | ||||
-rw-r--r-- | src/viewmodel/dates.rs | 16 | ||||
-rw-r--r-- | src/viewmodel/mod.rs | 103 | ||||
-rw-r--r-- | src/viewmodel/name.rs | 31 | ||||
-rw-r--r-- | src/viewmodel/organizational.rs | 71 | ||||
-rw-r--r-- | src/viewmodel/telephone.rs | 27 | ||||
-rw-r--r-- | src/viewmodel/utility.rs | 6 | ||||
-rw-r--r-- | src/viewmodel/vcard.rs | 8 |
8 files changed, 146 insertions, 152 deletions
diff --git a/src/viewmodel/address.rs b/src/viewmodel/address.rs index 71cc8d3..9542675 100644 --- a/src/viewmodel/address.rs +++ b/src/viewmodel/address.rs @@ -31,15 +31,15 @@ impl VCardPropertyInputObject<AddressView> for Address { fn get_input_fields(&self, link: &ComponentLink<AddressView>) -> Vec<VCardPropertyInputField> { let typ = String::from("text"); vec![ - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Post Office Box".to_string(), id: Some("post_office_box".to_string()), placeholder: None, oninput: link.callback(|e: InputData| Msg::UpdatePostOfficeBox(e.value)), value: self.post_office_box.clone(), - typ: typ.clone(), + typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Extension".to_string(), id: Some("extension".to_string()), placeholder: None, @@ -47,7 +47,7 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.extension.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Street".to_string(), id: Some("street".to_string()), placeholder: None, @@ -55,7 +55,7 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.street.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Locality".to_string(), id: Some("locality".to_string()), placeholder: None, @@ -63,7 +63,7 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.locality.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Region".to_string(), id: Some("region".to_string()), placeholder: None, @@ -71,7 +71,7 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.region.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Code".to_string(), id: Some("code".to_string()), placeholder: None, @@ -79,7 +79,7 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.code.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Country".to_string(), id: Some("country".to_string()), placeholder: None, @@ -87,13 +87,13 @@ impl VCardPropertyInputObject<AddressView> for Address { value: self.country.clone(), typ, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Work".to_string(), id: Some("work".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleWork), value: self.work, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Home".to_string(), id: Some("home".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleHome), @@ -102,12 +102,12 @@ impl VCardPropertyInputObject<AddressView> for Address { ] } fn is_empty(&self) -> bool { - self.post_office_box.is_empty() && - self.extension.is_empty() && - self.street.is_empty() && - self.locality.is_empty() && - self.region.is_empty() && - self.code.is_empty() && - self.country.is_empty() + self.post_office_box.is_empty() + && self.extension.is_empty() + && self.street.is_empty() + && self.locality.is_empty() + && self.region.is_empty() + && self.code.is_empty() + && self.country.is_empty() } -}
\ No newline at end of file +} diff --git a/src/viewmodel/dates.rs b/src/viewmodel/dates.rs index 28e8bad..7d8d394 100644 --- a/src/viewmodel/dates.rs +++ b/src/viewmodel/dates.rs @@ -1,5 +1,5 @@ -use crate::view::dates::*; use super::*; +use crate::view::dates::*; /// Type that represents the vcard `anniversary` and `birthday` properties. #[derive(Clone, Debug, PartialEq)] @@ -15,10 +15,13 @@ impl VCardPropertyInputObject<DatesView> for Dates { birthday: String::new(), } } - fn get_input_fields(&self, link: &yew::html::Scope<DatesView>) -> std::vec::Vec<VCardPropertyInputField> { + fn get_input_fields( + &self, + link: &yew::html::Scope<DatesView>, + ) -> std::vec::Vec<VCardPropertyInputField> { let typ = String::from("date"); vec![ - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Anniversary".to_string(), id: Some("anniversary".to_string()), placeholder: None, @@ -26,7 +29,7 @@ impl VCardPropertyInputObject<DatesView> for Dates { value: self.anniversary.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Birthday".to_string(), id: Some("birthday".to_string()), placeholder: None, @@ -37,7 +40,6 @@ impl VCardPropertyInputObject<DatesView> for Dates { ] } fn is_empty(&self) -> bool { - self.anniversary.is_empty() - && self.birthday.is_empty() + self.anniversary.is_empty() && self.birthday.is_empty() } -}
\ No newline at end of file +} diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs index 044dbad..0385c61 100644 --- a/src/viewmodel/mod.rs +++ b/src/viewmodel/mod.rs @@ -1,23 +1,24 @@ +use crate::view::VCardPropertyInputComponent; +use crate::viewmodel::utility::File; use wasm_bindgen::closure::Closure; -use web_sys::FileReader; use wasm_bindgen::JsCast; -use yew::services::ConsoleService; -use crate::viewmodel::utility::File; +use web_sys::FileReader; use yew::prelude::*; -use crate::view::VCardPropertyInputComponent; +use yew::services::ConsoleService; -pub mod vcard; -pub mod utility; pub mod address; -pub mod name; -pub mod telephone; pub mod dates; +pub mod name; pub mod organizational; - +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<C: VCardPropertyInputComponent<Self>>: Clone + PartialEq - where Self: Sized +pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: + Clone + PartialEq +where + Self: Sized, { /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; @@ -25,12 +26,12 @@ pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: Clone fn get_input_fields(&self, link: &ComponentLink<C>) -> Vec<VCardPropertyInputField>; /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink<C>) -> Html { - html!{ + html! { <div class="columns is-mobile is-multiline"> - { + { for self.get_input_fields(link).iter().map(|field| field.render() - ) + ) } </div> } @@ -40,9 +41,9 @@ pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: Clone } /// Type for saving error messages. -/// +/// /// More of a placeholder for something better later on. -#[derive(Debug,Clone,PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct Error { pub msg: String, } @@ -97,10 +98,16 @@ impl VCardPropertyInputField { } => Self::checkbox_field_input(label, id, value, onclick), } } - /// Returns an `Html` representation of a text input field with the given parameters. - fn text_field_input(label: &str, id: &Option<String>, placeholder: &Option<String>, oninput: &Callback<InputData>, typ: &str) -> Html { - html!{ - <div class="field column + /// Returns an `Html` representation of a text input field with the given parameters. + fn text_field_input( + label: &str, + id: &Option<String>, + placeholder: &Option<String>, + oninput: &Callback<InputData>, + typ: &str, + ) -> Html { + html! { + <div class="field column is-one-fifth-widescreen is-one-quarter-desktop is-one-third-tablet @@ -116,14 +123,19 @@ impl VCardPropertyInputField { </div> } } - /// Returns an `Html` representation of a file input field with the given parameters. - fn file_field_input(label: &str, name: &str, callback: &Callback<Option<File>>, file: &Option<File>) -> Html { + /// Returns an `Html` representation of a file input field with the given parameters. + fn file_field_input( + label: &str, + name: &str, + callback: &Callback<Option<File>>, + file: &Option<File>, + ) -> Html { let callback = callback.clone(); let onchange = Callback::<()>::default(); - let onchange = onchange.reform(move |c: ChangeData| + let onchange = onchange.reform(move |c: ChangeData| { if let ChangeData::Files(files) = c { match files.item(0) { - Some(file) => { + Some(file) => { let file_reader = FileReader::new().unwrap(); match file_reader.read_as_data_url(&file) { Ok(_) => (), @@ -131,33 +143,33 @@ impl VCardPropertyInputField { }; let callback = callback.clone(); - let onload = Closure::wrap(Box::new(move |event: Event|{ - let file_reader: FileReader = event.target().unwrap().dyn_into().unwrap(); - let data_url: Option<String> = file_reader.result().unwrap().as_string(); + let onload = Closure::wrap(Box::new(move |event: Event| { + let file_reader: FileReader = + event.target().unwrap().dyn_into().unwrap(); + let data_url: Option<String> = + file_reader.result().unwrap().as_string(); match data_url { - Some(content) => callback.emit( - Some(File { - name: file.name(), - content, - }) - ), + Some(content) => callback.emit(Some(File { + name: file.name(), + content, + })), None => { ConsoleService::warn("Couldn't get data url as string."); callback.emit(None); - }, + } }; }) as Box<dyn FnMut(_)>); file_reader.set_onload(Some(onload.as_ref().unchecked_ref())); onload.forget(); - }, + } None => callback.emit(None), } } else { callback.emit(None); } - ); - html!{ + }); + html! { <div class="field column is-one-fifth-widescreen is-one-quarter-desktop @@ -192,17 +204,22 @@ impl VCardPropertyInputField { </div> } } - /// Returns an `Html` representation of a checkbox input field with the given parameters. - fn checkbox_field_input(label: &str, id: &Option<String>, checked: &bool, onclick: &Callback<MouseEvent>) -> Html { - html!{ - <div class="field column + /// Returns an `Html` representation of a checkbox input field with the given parameters. + fn checkbox_field_input( + label: &str, + id: &Option<String>, + checked: &bool, + onclick: &Callback<MouseEvent>, + ) -> Html { + html! { + <div class="field column is-one-fifth-widescreen is-one-quarter-desktop is-one-third-tablet is-half-mobile" > <label class="checkbox"> <input id=id.as_ref().unwrap_or(&"".to_string()) - type="checkbox" + type="checkbox" checked=*checked onclick=onclick /> @@ -211,4 +228,4 @@ impl VCardPropertyInputField { </div> } } -}
\ No newline at end of file +} diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs index ee4736f..de0aa81 100644 --- a/src/viewmodel/name.rs +++ b/src/viewmodel/name.rs @@ -2,7 +2,7 @@ use super::*; use crate::view::name::*; /// Type that represents a vcard `name` property -/// +/// /// # Examples /// ``` /// # use bcard_wasm_webapp::viewmodel::name::Name; @@ -13,7 +13,7 @@ use crate::view::name::*; /// name.middle_name = String::from("Charles"); /// name.last_name = String::from("Clarke"); /// name.suffix = String::from("CBE FRAS"); -/// +/// /// assert_eq!(name.generate_fn(), String::from("Sir Arthur Charles Clarke, CBE FRAS")); /// ``` #[derive(Clone, Debug, PartialEq)] @@ -35,10 +35,13 @@ impl VCardPropertyInputObject<NameView> for Name { suffix: String::new(), } } - fn get_input_fields(&self, link: &ComponentLink<NameView>) -> std::vec::Vec<VCardPropertyInputField> { + fn get_input_fields( + &self, + link: &ComponentLink<NameView>, + ) -> std::vec::Vec<VCardPropertyInputField> { let typ = String::from("text"); vec![ - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Prefix".to_string(), id: Some("prefix".to_string()), placeholder: Some("Sir".to_string()), @@ -46,7 +49,7 @@ impl VCardPropertyInputObject<NameView> for Name { value: self.prefix.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "First Name".to_string(), id: Some("first_name".to_string()), placeholder: Some("Arthur".to_string()), @@ -54,7 +57,7 @@ impl VCardPropertyInputObject<NameView> for Name { value: self.first_name.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Middle Name".to_string(), id: Some("middle_name".to_string()), placeholder: Some("Charles".to_string()), @@ -62,7 +65,7 @@ impl VCardPropertyInputObject<NameView> for Name { value: self.middle_name.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Last Name".to_string(), id: Some("last_name".to_string()), placeholder: Some("Clarke".to_string()), @@ -70,7 +73,7 @@ impl VCardPropertyInputObject<NameView> for Name { value: self.last_name.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Suffix".to_string(), id: Some("suffix".to_string()), placeholder: Some("CBE FRAS".to_string()), @@ -81,11 +84,11 @@ impl VCardPropertyInputObject<NameView> for Name { ] } fn is_empty(&self) -> bool { - self.prefix.is_empty() && - self.first_name.is_empty() && - self.middle_name.is_empty() && - self.last_name.is_empty() && - self.suffix.is_empty() + self.prefix.is_empty() + && self.first_name.is_empty() + && self.middle_name.is_empty() + && self.last_name.is_empty() + && self.suffix.is_empty() } } @@ -113,4 +116,4 @@ impl Name { full_name } -}
\ No newline at end of file +} diff --git a/src/viewmodel/organizational.rs b/src/viewmodel/organizational.rs index c8f7164..72b19d2 100644 --- a/src/viewmodel/organizational.rs +++ b/src/viewmodel/organizational.rs @@ -1,7 +1,7 @@ -use crate::view::organizational::*; use super::*; +use crate::view::organizational::*; -#[derive(Clone,Debug,PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct Organizational { pub org: String, pub logo: Option<File>, @@ -22,10 +22,13 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { related: String::new(), } } - fn get_input_fields(&self, link: &yew::html::Scope<OrganizationalView>) -> std::vec::Vec<VCardPropertyInputField> { + fn get_input_fields( + &self, + link: &yew::html::Scope<OrganizationalView>, + ) -> std::vec::Vec<VCardPropertyInputField> { let typ = String::from("text"); vec![ - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Organisation".to_string(), id: Some("org".to_string()), placeholder: None, @@ -33,46 +36,14 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { value: self.org.clone(), typ: typ.clone(), }, - VCardPropertyInputField::File{ // TODO: Add Upload for logo + VCardPropertyInputField::File { + // TODO: Add Upload for logo label: "Logo".to_string(), name: "logo".to_string(), - callback: link.callback(|file: Option<File>| - /* - if let ChangeData::Files(files) = c { - match files.item(0) { - Some(file) => { - let filereader = match FileReaderSync::new() { - Ok(reader) => reader, - Err(_) => { - ConsoleService::warn("Couldn't create new filereader."); - return Msg::UpdateLogo(None) - }, - }; - let content = match filereader.read_as_data_url(&file) { - Ok(content) => content, - Err(_) => { - ConsoleService::warn("Error: Couldn't get file as data url."); - return Msg::UpdateLogo(None) - }, - }; - Msg::UpdateLogo( - Some(File { - name: file.name(), - content, - }) - ) - }, - None => Msg::UpdateLogo(None), - } - } else { - Msg::UpdateLogo(None) - } - */ - Msg::UpdateLogo(file) - ), + callback: link.callback(|file: Option<File>| Msg::UpdateLogo(file)), value: self.logo.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Title".to_string(), id: Some("title".to_string()), placeholder: None, @@ -80,7 +51,7 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { value: self.title.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Role".to_string(), id: Some("role".to_string()), placeholder: None, @@ -88,7 +59,7 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { value: self.role.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Member".to_string(), id: Some("member".to_string()), placeholder: None, @@ -96,7 +67,7 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { value: self.member.clone(), typ: typ.clone(), }, - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Related".to_string(), id: Some("related".to_string()), placeholder: None, @@ -107,11 +78,11 @@ impl VCardPropertyInputObject<OrganizationalView> for Organizational { ] } fn is_empty(&self) -> bool { - self.org.is_empty() && - self.logo.is_none() && - self.title.is_empty() && - self.role.is_empty() && - self.member.is_empty() && - self.related.is_empty() + self.org.is_empty() + && self.logo.is_none() + && self.title.is_empty() + && self.role.is_empty() + && self.member.is_empty() + && self.related.is_empty() } -}
\ No newline at end of file +} diff --git a/src/viewmodel/telephone.rs b/src/viewmodel/telephone.rs index ee616c3..44b938f 100644 --- a/src/viewmodel/telephone.rs +++ b/src/viewmodel/telephone.rs @@ -30,10 +30,13 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone { text_phone: false, } } - fn get_input_fields(&self, link: &ComponentLink<TelephoneView>) -> Vec<VCardPropertyInputField> { + fn get_input_fields( + &self, + link: &ComponentLink<TelephoneView>, + ) -> Vec<VCardPropertyInputField> { let typ = String::from("tel"); vec![ - VCardPropertyInputField::Text{ + VCardPropertyInputField::Text { label: "Number".to_string(), id: Some("number".to_string()), placeholder: None, @@ -41,55 +44,55 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone { value: self.number.clone(), typ, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Work".to_string(), id: Some("work".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleWork), value: self.work, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Home".to_string(), id: Some("home".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleHome), value: self.home, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Text".to_string(), id: Some("text".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleText), value: self.text, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Voice".to_string(), id: Some("voice".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleVoice), value: self.voice, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Fax".to_string(), id: Some("fax".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleFax), value: self.fax, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Cell".to_string(), id: Some("cell".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleCell), value: self.cell, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Video".to_string(), id: Some("video".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleVideo), value: self.video, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Pager".to_string(), id: Some("pager".to_string()), onclick: link.callback(|_: MouseEvent| Msg::TogglePager), value: self.pager, }, - VCardPropertyInputField::CheckBox{ + VCardPropertyInputField::CheckBox { label: "Text Phone".to_string(), id: Some("text_phone".to_string()), onclick: link.callback(|_: MouseEvent| Msg::ToggleTextPhone), @@ -100,4 +103,4 @@ impl VCardPropertyInputObject<TelephoneView> for Telephone { fn is_empty(&self) -> bool { self.number.is_empty() } -}
\ No newline at end of file +} diff --git a/src/viewmodel/utility.rs b/src/viewmodel/utility.rs index cb581ac..617ee45 100644 --- a/src/viewmodel/utility.rs +++ b/src/viewmodel/utility.rs @@ -1,5 +1,3 @@ - - #[derive(Clone)] pub struct Download { pub file_name: String, @@ -40,8 +38,8 @@ pub enum DownloadOption { QrCode, } -#[derive(Clone,Debug,PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct File { pub name: String, pub content: String, -}
\ No newline at end of file +} diff --git a/src/viewmodel/vcard.rs b/src/viewmodel/vcard.rs index 0d2d6c4..18ce43a 100644 --- a/src/viewmodel/vcard.rs +++ b/src/viewmodel/vcard.rs @@ -1,8 +1,8 @@ -use crate::viewmodel::organizational::Organizational; -use crate::viewmodel::dates::Dates; -use crate::viewmodel::telephone::Telephone; use crate::viewmodel::address::Address; +use crate::viewmodel::dates::Dates; use crate::viewmodel::name::Name; +use crate::viewmodel::organizational::Organizational; +use crate::viewmodel::telephone::Telephone; /// Type that represents the data structure of a vcard. #[derive(Clone, Debug)] @@ -37,4 +37,4 @@ impl VCardData { 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_organizational organizationals => organizational: Organizational ); -}
\ No newline at end of file +} |