summaryrefslogtreecommitdiff
path: root/src/view
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-02-07 21:43:48 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-02-07 21:43:48 +0100
commitad9ba30ed217ec9907d1faf389c321a1dcf5c13a (patch)
tree7fdadcde26842e4806881492b993b948c1f2032c /src/view
parentf88f8d7c7dc87cdf47de95b54cc6e9f8429820a4 (diff)
downloadwasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.gz
wasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.bz2
add organizational properties
Diffstat (limited to 'src/view')
-rw-r--r--src/view/address.rs11
-rw-r--r--src/view/dates.rs11
-rw-r--r--src/view/main.rs66
-rw-r--r--src/view/mod.rs12
-rw-r--r--src/view/name.rs11
-rw-r--r--src/view/organizational.rs83
-rw-r--r--src/view/telephone.rs11
7 files changed, 176 insertions, 29 deletions
diff --git a/src/view/address.rs b/src/view/address.rs
index 1aedcbd..a945272 100644
--- a/src/view/address.rs
+++ b/src/view/address.rs
@@ -1,11 +1,13 @@
+use crate::view::InputProps;
use yew::prelude::*;
use yewtil::NeqAssign;
-use super::WeakComponentLink;
use crate::viewmodel::address::*;
use crate::viewmodel::VCardPropertyInputObject;
use super::VCardPropertyInputComponent;
use crate::viewmodel::Error;
+type Props = InputProps<Address,AddressView>;
+
/// View Component for a `address` field
///
/// # Examples
@@ -20,6 +22,7 @@ use crate::viewmodel::Error;
/// />
/// };
/// ```
+#[derive(Clone,PartialEq)]
pub struct AddressView {
props: Props,
value: Address,
@@ -40,12 +43,6 @@ pub enum Msg {
Generate,
}
-#[derive(Clone, PartialEq, Properties)]
-pub struct Props {
- pub generated: Callback<Address>,
- pub weak_link: WeakComponentLink<AddressView>,
-}
-
impl VCardPropertyInputComponent<Address> for AddressView {
fn get_input_object(&self) -> Address {
self.value.clone()
diff --git a/src/view/dates.rs b/src/view/dates.rs
index 1c16680..de3d311 100644
--- a/src/view/dates.rs
+++ b/src/view/dates.rs
@@ -1,11 +1,14 @@
+use crate::view::InputProps;
use yew::prelude::*;
use yewtil::NeqAssign;
use crate::viewmodel::Error;
-use crate::view::WeakComponentLink;
use crate::viewmodel::dates::*;
use crate::viewmodel::VCardPropertyInputObject;
use super::VCardPropertyInputComponent;
+type Props = InputProps<Dates,DatesView>;
+
+#[derive(Clone,PartialEq)]
pub struct DatesView {
props: Props,
value: Dates,
@@ -19,12 +22,6 @@ pub enum Msg {
Generate,
}
-#[derive(Clone, PartialEq, Properties)]
-pub struct Props {
- pub generated: Callback<Dates>,
- pub weak_link: WeakComponentLink<DatesView>,
-}
-
impl VCardPropertyInputComponent<Dates> for DatesView {
fn get_input_object(&self) -> Dates {
self.value.clone()
diff --git a/src/view/main.rs b/src/view/main.rs
index 0d2cddb..c2af72a 100644
--- a/src/view/main.rs
+++ b/src/view/main.rs
@@ -1,3 +1,5 @@
+use crate::viewmodel::organizational::Organizational;
+use crate::view::organizational::{self,OrganizationalView};
use crate::viewmodel::dates::Dates;
use yew::services::ConsoleService;
use crate::viewmodel::vcard::VCardData;
@@ -35,6 +37,7 @@ pub struct MainView {
address_links: Vec<WeakComponentLink<AddressView>>,
telephone_links: Vec<WeakComponentLink<TelephoneView>>,
dates_links: Vec<WeakComponentLink<DatesView>>,
+ organizational_links: Vec<WeakComponentLink<OrganizationalView>>,
answer_count: usize,
}
@@ -44,6 +47,7 @@ pub enum Msg {
AddAddress,
AddTelephone,
AddDates,
+ AddOrganizational,
ChangeDownloadOption(DownloadOption),
@@ -52,6 +56,7 @@ pub enum Msg {
GeneratedAddress(Address),
GeneratedTelephone(Telephone),
GeneratedDates(Dates),
+ GeneratedOrganizational(Organizational),
GenerationComplete,
Nope,
@@ -73,6 +78,7 @@ impl Component for MainView {
address_links: vec![WeakComponentLink::default()],
telephone_links: vec![WeakComponentLink::default()],
dates_links: vec![WeakComponentLink::default()],
+ organizational_links: vec![WeakComponentLink::default()],
answer_count: 0,
}
}
@@ -98,6 +104,10 @@ impl Component for MainView {
self.dates_links.push(WeakComponentLink::default());
shouldrender = true;
},
+ Msg::AddOrganizational => {
+ self.organizational_links.push(WeakComponentLink::default());
+ shouldrender = true;
+ },
Msg::ChangeDownloadOption(option) => {
self.selected_option = option;
shouldrender = false;
@@ -125,6 +135,11 @@ impl Component for MainView {
let dates_link = dates_link.borrow().clone().unwrap();
dates_link.send_message(dates::Msg::Generate)
}
+
+ for organizational_links in self.organizational_links.iter() {
+ let organizational_link = organizational_links.borrow().clone().unwrap();
+ organizational_link.send_message(organizational::Msg::Generate)
+ }
}
/*
DownloadOption::PDF => {
@@ -189,6 +204,16 @@ impl Component for MainView {
shouldrender = true;
},
+ Msg::GeneratedOrganizational(organizational) => {
+ self.answer_count += 1;
+
+ match self.vcard_data.get_mut() {
+ Some(vcard_data) => vcard_data.add_organizational(organizational),
+ None => ConsoleService::info("Error in GeneratedOrganizational: Couldn't get mutable borrow of VCardData"),
+ };
+
+ shouldrender = true;
+ },
Msg::GenerationComplete => {
self.answer_count = 0;
@@ -345,6 +370,33 @@ impl Component for MainView {
);
}
}
+
+ for organizational in vcard_data.organizationals {
+
+ if !organizational.org.is_empty() {
+ builder = builder.with_org(vec![organizational.org]);
+ }
+
+ if !organizational.logo.is_empty() {
+ builder = builder.with_logo(organizational.logo);
+ }
+
+ if !organizational.title.is_empty() {
+ builder = builder.with_title(organizational.title);
+ }
+
+ if !organizational.role.is_empty() {
+ builder = builder.with_role(organizational.role);
+ }
+
+ if !organizational.member.is_empty() {
+ builder = builder.with_member(organizational.member);
+ }
+
+ if !organizational.related.is_empty() {
+ builder = builder.with_related(organizational.related);
+ }
+ }
let rev = Local::now();
@@ -498,6 +550,19 @@ impl Component for MainView {
)
}
+ {
+ for self.organizational_links.iter().map(|link|
+ html!{
+ <OrganizationalView weak_link=link
+ generated=self.link.callback(
+ |o: Organizational|
+ Msg::GeneratedOrganizational(o)
+ )
+ />
+ }
+ )
+ }
+
<div class="block level-left">
<button onclick=self.link.callback(|_| Msg::Generate) class="button is-primary level-item">{ "Generate" }</button>
@@ -641,5 +706,6 @@ impl MainView {
+ self.address_links.len()
+ self.telephone_links.len()
+ self.dates_links.len()
+ + self.organizational_links.len()
}
} \ No newline at end of file
diff --git a/src/view/mod.rs b/src/view/mod.rs
index 65ef06d..0751c53 100644
--- a/src/view/mod.rs
+++ b/src/view/mod.rs
@@ -9,9 +9,19 @@ pub mod name;
pub mod address;
pub mod telephone;
pub mod dates;
+pub mod organizational;
+
+#[derive(Clone, PartialEq, Properties)]
+pub struct InputProps<O, C>
+ where O: VCardPropertyInputObject<C> + Clone,
+ C: VCardPropertyInputComponent<O> + Clone
+{
+ pub generated: Callback<O>,
+ pub weak_link: WeakComponentLink<C>,
+}
/// Trait for types that represent an input component for a vcard property.
-pub trait VCardPropertyInputComponent<T: VCardPropertyInputObject<Self>>: Component {
+pub trait VCardPropertyInputComponent<T: VCardPropertyInputObject<Self>>: Component + Clone + PartialEq {
/// Returns the object containing the input data.
fn get_input_object(&self) -> T;
/// Getter function for the title of the component
diff --git a/src/view/name.rs b/src/view/name.rs
index 27dadf1..4976e7d 100644
--- a/src/view/name.rs
+++ b/src/view/name.rs
@@ -1,11 +1,13 @@
+use crate::view::InputProps;
use yew::prelude::*;
use yewtil::NeqAssign;
use crate::viewmodel::Error;
-use crate::view::WeakComponentLink;
use crate::viewmodel::name::*;
use crate::viewmodel::VCardPropertyInputObject;
use super::VCardPropertyInputComponent;
+type Props = InputProps<Name,NameView>;
+
/// View Component for a `name` field
///
/// # Examples
@@ -20,6 +22,7 @@ use super::VCardPropertyInputComponent;
/// />
/// };
/// ```
+#[derive(Clone,PartialEq)]
pub struct NameView {
props: Props,
value: Name,
@@ -36,12 +39,6 @@ pub enum Msg {
Generate,
}
-#[derive(Clone, PartialEq, Properties)]
-pub struct Props {
- pub generated: Callback<Name>,
- pub weak_link: WeakComponentLink<NameView>,
-}
-
impl VCardPropertyInputComponent<Name> for NameView {
fn get_input_object(&self) -> Name {
self.value.clone()
diff --git a/src/view/organizational.rs b/src/view/organizational.rs
new file mode 100644
index 0000000..b11c181
--- /dev/null
+++ b/src/view/organizational.rs
@@ -0,0 +1,83 @@
+use yew::prelude::*;
+use yewtil::NeqAssign;
+use crate::viewmodel::Error;
+use crate::view::InputProps;
+use crate::viewmodel::organizational::*;
+use crate::viewmodel::VCardPropertyInputObject;
+use super::VCardPropertyInputComponent;
+
+type Props = InputProps<Organizational,OrganizationalView>;
+
+#[derive(Clone,PartialEq)]
+pub struct OrganizationalView {
+ props: Props,
+ value: Organizational,
+ error: Option<Error>,
+}
+
+pub enum Msg {
+ UpdateOrg(String),
+ UpdateLogo(String),
+ UpdateTitle(String),
+ UpdateRole(String),
+ UpdateMember(String),
+ UpdateRelated(String),
+
+ Generate,
+}
+
+impl VCardPropertyInputComponent<Organizational> for OrganizationalView {
+ fn get_input_object(&self) -> Organizational {
+ self.value.clone()
+ }
+ fn get_title(&self) -> std::string::String {
+ "Organizational".to_string()
+ }
+ fn get_error(&self) -> std::option::Option<Error> {
+ self.error.clone()
+ }
+}
+
+impl Component for OrganizationalView {
+ type Message = Msg;
+ type Properties = Props;
+ fn create(props: <Self as yew::Component>::Properties, link: yew::html::Scope<Self>) -> Self {
+ props.weak_link.borrow_mut().replace(link);
+ Self {
+ props,
+ value: Organizational::new(),
+ error: None,
+ }
+ }
+ fn update(&mut self, msg: <Self as yew::Component>::Message) -> bool {
+ match msg {
+ Msg::UpdateOrg(o) => self.value.org = o,
+ Msg::UpdateLogo(l) => self.value.logo = l,
+ Msg::UpdateTitle(t) => self.value.title = t,
+ Msg::UpdateRole(r) => self.value.role = r,
+ Msg::UpdateMember(m) => self.value.member = m,
+ Msg::UpdateRelated(r) => self.value.related = r,
+ Msg::Generate => {
+ self.props.generated.emit(self.value.clone());
+ },
+ };
+ true
+ }
+ fn change(&mut self, props: <Self as yew::Component>::Properties) -> bool {
+ self.props.neq_assign(props)
+ }
+ fn view(&self) -> yew::virtual_dom::VNode {
+ let link = self.props.weak_link.borrow().clone().unwrap();
+
+ html!{
+ <div class="box">
+ { self.render_error() }
+
+ <h3 class="subtitle">{ self.get_title() }</h3>
+
+ { self.get_input_object().render(&link) }
+
+ </div>
+ }
+ }
+} \ No newline at end of file
diff --git a/src/view/telephone.rs b/src/view/telephone.rs
index 5db8ae1..dc93632 100644
--- a/src/view/telephone.rs
+++ b/src/view/telephone.rs
@@ -1,11 +1,13 @@
+use crate::view::InputProps;
use yew::prelude::*;
use yewtil::NeqAssign;
-use crate::view::WeakComponentLink;
use crate::viewmodel::Error;
use crate::viewmodel::telephone::*;
use crate::viewmodel::VCardPropertyInputObject;
use super::VCardPropertyInputComponent;
+type Props = InputProps<Telephone,TelephoneView>;
+
/// View Component for a `telephone` field
///
/// # Examples
@@ -20,6 +22,7 @@ use super::VCardPropertyInputComponent;
/// />
/// };
/// ```
+#[derive(Clone,PartialEq)]
pub struct TelephoneView {
props: Props,
value: Telephone,
@@ -41,12 +44,6 @@ pub enum Msg {
Generate,
}
-#[derive(Clone, PartialEq, Properties)]
-pub struct Props {
- pub generated: Callback<Telephone>,
- pub weak_link: WeakComponentLink<TelephoneView>,
-}
-
impl VCardPropertyInputComponent<Telephone> for TelephoneView {
fn get_input_object(&self) -> Telephone {
self.value.clone()