summaryrefslogtreecommitdiff
path: root/src/view
diff options
context:
space:
mode:
authorjelemux <jeremias.weber@protonmail.com>2021-03-04 07:29:39 +0100
committerjelemux <jeremias.weber@protonmail.com>2021-03-04 07:29:39 +0100
commit0b777005648985ec6d666efe7fb0094e870ee51e (patch)
tree7797b449cf1e08fc1c8a25db13fd2d73a383ee6f /src/view
parentce41ea82d7704e435feb8169c5bf8189b92f871b (diff)
downloadwasm-card-0b777005648985ec6d666efe7fb0094e870ee51e.tar.gz
wasm-card-0b777005648985ec6d666efe7fb0094e870ee51e.tar.bz2
start filling pdf (doesn't work yet)
Diffstat (limited to 'src/view')
-rw-r--r--src/view/main.rs97
1 files changed, 87 insertions, 10 deletions
diff --git a/src/view/main.rs b/src/view/main.rs
index 93d2492..40aaa34 100644
--- a/src/view/main.rs
+++ b/src/view/main.rs
@@ -190,21 +190,31 @@ impl Component for MainView {
communcation_link.send_message(CommunicationMsg::Generate)
}
}
- /*
- DownloadOption::PDF => {
- match self.generate_pdf() {
- Ok(pdf) => self.download = Some(
+ if self.selected_option == DownloadOption::PDF {
+ match self.generate_pdf() {
+ Ok(pdf) => {
+ let mut vcard_name = String::new();
+ if let Some(vcard_data) = self.vcard_data.get_mut() {
+ if let Some(name) = vcard_data.names.get(0) {
+ vcard_name = name.generate_fn();
+ }
+ }
+
+ self.download = Some(
Download {
- file_name: format!("Visitenkarten {}.pdf", self.name.formatted_name()),
+ file_name: format!("Visitenkarten {}.pdf", vcard_name),
content: pdf,
mime_type: MimeType::PDF,
}
- ),
- Err(_) => self.error.push(String::from("Unexpected error while generating the PDF. Please contact me about it.")),
- }
+ );
+ },
+ Err(_) => self.error = Some(
+ Error {
+ msg: String::from("Unexpected error while generating the PDF. Please contact me about it.")
+ }
+ ),
}
}
- */
true
}
@@ -742,6 +752,7 @@ impl Component for MainView {
}
impl MainView {
+
fn render_error(&self) -> Html {
html! {
<>
@@ -760,6 +771,7 @@ impl MainView {
</>
}
}
+
fn render_download(&self) -> Html {
if self.download.is_some() {
let download = self.download.as_ref().unwrap();
@@ -773,6 +785,7 @@ impl MainView {
html! {}
}
}
+
fn render_preview(&self) -> Html {
if self.download.is_some() {
let download = self.download.as_ref().unwrap();
@@ -796,6 +809,7 @@ impl MainView {
html! {}
}
}
+
fn generate_pdf(&self) -> Result<String, ()> {
let regular_bytes =
include_bytes!("/usr/share/fonts/liberation/LiberationSans-Regular.ttf");
@@ -836,7 +850,7 @@ impl MainView {
let mut doc = genpdf::Document::new(font_family);
- doc.set_title("BCard test");
+ doc.set_title("wasm-card test");
doc.set_minimal_conformance();
let mut decorator = genpdf::SimplePageDecorator::new();
@@ -851,6 +865,68 @@ impl MainView {
.styled(style::Style::new().bold().with_font_size(20)),
);
+ let mut card_data = elements::Paragraph::new("");
+
+ if let Ok(vcard_data) = self.vcard_data.irc().try_unwrap() {
+ if let Some(name) = vcard_data.names.get(0) {
+ card_data.push_styled(
+ name.generate_fn(),
+ style::Effect::Bold
+ );
+ }
+ card_data.push(
+ ""
+ );
+ if let Some(communication) = vcard_data.communications.get(0) {
+ card_data.push(
+ communication.email_address.clone()
+ );
+ }
+ card_data.push(
+ ""
+ );
+ if let Some(address) = vcard_data.addresses.get(0) {
+ card_data.push(
+ address.street.clone()
+ );
+ card_data.push(
+ format!("{} {} {}", address.code, address.locality, address.extension)
+ );
+ card_data.push(
+ format!("{} {}", address.region, address.country)
+ );
+ }
+ card_data.push(
+ ""
+ );
+ for telephone in vcard_data.telephones {
+ card_data.push(
+ telephone.number
+ );
+ }
+ } else {
+ ConsoleService::log("Could not unwrap vcard_data.");
+ }
+
+ let framed_card_data = elements::FramedElement::new(
+ card_data
+ );
+
+ let mut table = elements::TableLayout::new(vec![1,1]);
+ table.set_cell_decorator(
+ elements::FrameCellDecorator::new(false, false, false)
+ );
+ for _i in 0..4 {
+ table
+ .row()
+ .element(framed_card_data.clone())
+ .element(framed_card_data.clone())
+ .push()
+ .expect("invalid table row");
+ }
+
+ doc.push(table);
+
// TODO fill doc with real data
let mut buf: Vec<u8> = Vec::new();
@@ -862,6 +938,7 @@ impl MainView {
Err(_) => Err(()),
}
}
+
fn get_subcomponent_count(&self) -> usize {
self.name_links.len()
+ self.address_links.len()