From 0660151a8b641fa0a23dde2598132029970f7ae4 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 11 Feb 2021 12:07:22 +0100 Subject: refactoring - reduced code size by about a third --- src/model/organizational.rs | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/model/organizational.rs (limited to 'src/model/organizational.rs') diff --git a/src/model/organizational.rs b/src/model/organizational.rs new file mode 100644 index 0000000..f82f5d7 --- /dev/null +++ b/src/model/organizational.rs @@ -0,0 +1,120 @@ +use super::*; + +#[derive(Clone, Debug, PartialEq)] +pub struct Organizational { + pub org: String, + pub logo: Option, + pub title: String, + pub role: String, + pub member: String, + pub related: String, +} + +#[derive(Clone, PartialEq)] +pub enum OrganizationalMsg { + UpdateOrg(String), + UpdateLogo(Option), + UpdateTitle(String), + UpdateRole(String), + UpdateMember(String), + UpdateRelated(String), + + Generate, +} + +impl VCardPropertyInputObject for Organizational { + fn new() -> Self { + Self { + org: String::new(), + logo: None, + title: String::new(), + role: String::new(), + member: String::new(), + related: String::new(), + } + } + fn get_title(&self) -> std::string::String { + "Organizational".to_string() + } + fn get_input_fields( + &self, + link: &yew::html::Scope>, + ) -> std::vec::Vec { + let typ = String::from("text"); + vec![ + VCardPropertyInputField::Text { + label: "Organisation".to_string(), + id: Some("org".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateOrg(e.value)), + value: self.org.clone(), + typ: typ.clone(), + }, + VCardPropertyInputField::File { + // TODO: Add Upload for logo + label: "Logo".to_string(), + name: "logo".to_string(), + callback: link.callback(|file: Option| OrganizationalMsg::UpdateLogo(file)), + value: self.logo.clone(), + }, + VCardPropertyInputField::Text { + label: "Title".to_string(), + id: Some("title".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateTitle(e.value)), + value: self.title.clone(), + typ: typ.clone(), + }, + VCardPropertyInputField::Text { + label: "Role".to_string(), + id: Some("role".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateRole(e.value)), + value: self.role.clone(), + typ: typ.clone(), + }, + VCardPropertyInputField::Text { + label: "Member".to_string(), + id: Some("member".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateMember(e.value)), + value: self.member.clone(), + typ: typ.clone(), + }, + VCardPropertyInputField::Text { + label: "Related".to_string(), + id: Some("related".to_string()), + placeholder: None, + oninput: link.callback(|e: InputData| OrganizationalMsg::UpdateRelated(e.value)), + value: self.related.clone(), + typ: typ, + }, + ] + } + fn update( + &mut self, + props: InputProps, + msg: as yew::Component>::Message, + ) -> bool { + match msg { + OrganizationalMsg::UpdateOrg(o) => self.org = o, + OrganizationalMsg::UpdateLogo(l) => self.logo = l, + OrganizationalMsg::UpdateTitle(t) => self.title = t, + OrganizationalMsg::UpdateRole(r) => self.role = r, + OrganizationalMsg::UpdateMember(m) => self.member = m, + OrganizationalMsg::UpdateRelated(r) => self.related = r, + OrganizationalMsg::Generate => { + props.generated.emit(self.clone()); + } + }; + true + } + 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() + } +} -- cgit v1.2.3