From 036a567bae8346eb38f9237f59645dbcc4f1cd8c Mon Sep 17 00:00:00 2001 From: jelemux Date: Tue, 9 Feb 2021 23:18:45 +0100 Subject: switch to cargo-make; format files with rustfmt --- src/viewmodel/address.rs | 36 +++++++------- src/viewmodel/dates.rs | 16 ++++--- src/viewmodel/mod.rs | 103 +++++++++++++++++++++++----------------- src/viewmodel/name.rs | 31 ++++++------ src/viewmodel/organizational.rs | 71 ++++++++------------------- src/viewmodel/telephone.rs | 27 ++++++----- src/viewmodel/utility.rs | 6 +-- src/viewmodel/vcard.rs | 8 ++-- 8 files changed, 146 insertions(+), 152 deletions(-) (limited to 'src/viewmodel') 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 for Address { fn get_input_fields(&self, link: &ComponentLink) -> Vec { 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 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 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 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 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 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 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 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 for Dates { birthday: String::new(), } } - fn get_input_fields(&self, link: &yew::html::Scope) -> std::vec::Vec { + fn get_input_fields( + &self, + link: &yew::html::Scope, + ) -> std::vec::Vec { 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 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 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>: Clone + PartialEq - where Self: Sized +pub trait VCardPropertyInputObject>: + Clone + PartialEq +where + Self: Sized, { /// Function for creating a new (and empty) `VCardPropertyInputObject`. fn new() -> Self; @@ -25,12 +26,12 @@ pub trait VCardPropertyInputObject>: Clone fn get_input_fields(&self, link: &ComponentLink) -> Vec; /// Returns a `Html` representation of the `VCardPropertyInputObject`. fn render(&self, link: &ComponentLink) -> Html { - html!{ + html! {
- { + { for self.get_input_fields(link).iter().map(|field| field.render() - ) + ) }
} @@ -40,9 +41,9 @@ pub trait VCardPropertyInputObject>: 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, placeholder: &Option, oninput: &Callback, typ: &str) -> Html { - html!{ -
} } - /// Returns an `Html` representation of a file input field with the given parameters. - fn file_field_input(label: &str, name: &str, callback: &Callback>, file: &Option) -> Html { + /// Returns an `Html` representation of a file input field with the given parameters. + fn file_field_input( + label: &str, + name: &str, + callback: &Callback>, + file: &Option, + ) -> 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 = 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 = + 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); file_reader.set_onload(Some(onload.as_ref().unchecked_ref())); onload.forget(); - }, + } None => callback.emit(None), } } else { callback.emit(None); } - ); - html!{ + }); + html! {
, + checked: &bool, + onclick: &Callback, + ) -> Html { + html! { +
} } -} \ 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 for Name { suffix: String::new(), } } - fn get_input_fields(&self, link: &ComponentLink) -> std::vec::Vec { + fn get_input_fields( + &self, + link: &ComponentLink, + ) -> std::vec::Vec { 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 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 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 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 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 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, @@ -22,10 +22,13 @@ impl VCardPropertyInputObject for Organizational { related: String::new(), } } - fn get_input_fields(&self, link: &yew::html::Scope) -> std::vec::Vec { + fn get_input_fields( + &self, + link: &yew::html::Scope, + ) -> std::vec::Vec { 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 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| - /* - 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| 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 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 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 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 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 for Telephone { text_phone: false, } } - fn get_input_fields(&self, link: &ComponentLink) -> Vec { + fn get_input_fields( + &self, + link: &ComponentLink, + ) -> Vec { 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 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 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 +} -- cgit v1.2.3