summaryrefslogtreecommitdiff
path: root/src/viewmodel
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/viewmodel
parentf88f8d7c7dc87cdf47de95b54cc6e9f8429820a4 (diff)
downloadwasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.gz
wasm-card-ad9ba30ed217ec9907d1faf389c321a1dcf5c13a.tar.bz2
add organizational properties
Diffstat (limited to 'src/viewmodel')
-rw-r--r--src/viewmodel/address.rs2
-rw-r--r--src/viewmodel/dates.rs2
-rw-r--r--src/viewmodel/mod.rs3
-rw-r--r--src/viewmodel/name.rs2
-rw-r--r--src/viewmodel/organizational.rs86
-rw-r--r--src/viewmodel/telephone.rs2
-rw-r--r--src/viewmodel/vcard.rs4
7 files changed, 96 insertions, 5 deletions
diff --git a/src/viewmodel/address.rs b/src/viewmodel/address.rs
index 26e168a..71cc8d3 100644
--- a/src/viewmodel/address.rs
+++ b/src/viewmodel/address.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::view::address::*;
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Address {
pub post_office_box: String,
pub extension: String,
diff --git a/src/viewmodel/dates.rs b/src/viewmodel/dates.rs
index 6c7fa37..28e8bad 100644
--- a/src/viewmodel/dates.rs
+++ b/src/viewmodel/dates.rs
@@ -2,7 +2,7 @@ use crate::view::dates::*;
use super::*;
/// Type that represents the vcard `anniversary` and `birthday` properties.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Dates {
pub anniversary: String,
pub birthday: String,
diff --git a/src/viewmodel/mod.rs b/src/viewmodel/mod.rs
index edd1a8e..75ed1d2 100644
--- a/src/viewmodel/mod.rs
+++ b/src/viewmodel/mod.rs
@@ -7,10 +7,11 @@ pub mod address;
pub mod name;
pub mod telephone;
pub mod dates;
+pub mod organizational;
/// Trait for types that represent the data of a vcard property used inside of a `VCardPropertyInputComponent`.
-pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>
+pub trait VCardPropertyInputObject<C: VCardPropertyInputComponent<Self>>: Clone + PartialEq
where Self: Sized
{
/// Function for creating a new (and empty) `VCardPropertyInputObject`.
diff --git a/src/viewmodel/name.rs b/src/viewmodel/name.rs
index aa6747c..ee4736f 100644
--- a/src/viewmodel/name.rs
+++ b/src/viewmodel/name.rs
@@ -16,7 +16,7 @@ use crate::view::name::*;
///
/// assert_eq!(name.generate_fn(), String::from("Sir Arthur Charles Clarke, CBE FRAS"));
/// ```
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Name {
pub prefix: String,
pub first_name: String,
diff --git a/src/viewmodel/organizational.rs b/src/viewmodel/organizational.rs
new file mode 100644
index 0000000..e7a4ae7
--- /dev/null
+++ b/src/viewmodel/organizational.rs
@@ -0,0 +1,86 @@
+use crate::view::organizational::*;
+use super::*;
+
+#[derive(Clone,Debug,PartialEq)]
+pub struct Organizational {
+ pub org: String,
+ pub logo: String,
+ pub title: String,
+ pub role: String,
+ pub member: String,
+ pub related: String,
+}
+
+impl VCardPropertyInputObject<OrganizationalView> for Organizational {
+ fn new() -> Self {
+ Self {
+ org: String::new(),
+ logo: String::new(),
+ title: String::new(),
+ role: String::new(),
+ member: String::new(),
+ related: String::new(),
+ }
+ }
+ fn get_input_fields(&self, link: &yew::html::Scope<OrganizationalView>) -> std::vec::Vec<VCardPropertyInputField> {
+ let typ = String::from("text");
+ vec![
+ VCardPropertyInputField::Text{
+ label: "Organisation".to_string(),
+ id: Some("org".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::UpdateOrg(e.value)),
+ value: self.org.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text{ // TODO: Add Upload for logo
+ label: "Logo".to_string(),
+ id: Some("logo".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::UpdateLogo(e.value)),
+ value: self.logo.clone(),
+ typ: typ.clone(),
+ },
+ VCardPropertyInputField::Text{
+ label: "Title".to_string(),
+ id: Some("title".to_string()),
+ placeholder: None,
+ oninput: link.callback(|e: InputData| Msg::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| Msg::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| Msg::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| Msg::UpdateRelated(e.value)),
+ value: self.related.clone(),
+ typ: typ,
+ },
+ ]
+ }
+ fn is_empty(&self) -> bool {
+ self.org.is_empty() &&
+ self.logo.is_empty() &&
+ 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 774b63d..ee616c3 100644
--- a/src/viewmodel/telephone.rs
+++ b/src/viewmodel/telephone.rs
@@ -1,7 +1,7 @@
use super::*;
use crate::view::telephone::*;
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
pub struct Telephone {
pub number: String,
pub work: bool,
diff --git a/src/viewmodel/vcard.rs b/src/viewmodel/vcard.rs
index 565b1ff..0d2d6c4 100644
--- a/src/viewmodel/vcard.rs
+++ b/src/viewmodel/vcard.rs
@@ -1,3 +1,4 @@
+use crate::viewmodel::organizational::Organizational;
use crate::viewmodel::dates::Dates;
use crate::viewmodel::telephone::Telephone;
use crate::viewmodel::address::Address;
@@ -10,6 +11,7 @@ pub struct VCardData {
pub addresses: Vec<Address>,
pub telephones: Vec<Telephone>,
pub datess: Vec<Dates>,
+ pub organizationals: Vec<Organizational>,
}
macro_rules! make_vec_adder_fn {
@@ -27,10 +29,12 @@ impl VCardData {
addresses: Vec::new(),
telephones: Vec::new(),
datess: 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_organizational organizationals => organizational: Organizational );
} \ No newline at end of file