Skip to content

Commit

Permalink
Simplify table and download handling.
Browse files Browse the repository at this point in the history
* Leave only edit mode in table rows.

* Download button now generates the file to download.
  • Loading branch information
vaijira committed Dec 1, 2024
1 parent 1bd36f2 commit 7290083
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 170 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies.web-sys]
version = "0.3"
features = [
"HtmlAnchorElement",
"HtmlInputElement",
"FileList",
]
Expand All @@ -25,7 +26,8 @@ dominator = "0.5"
encoding_rs = "0.8"
futures = "0.3"
futures-signals = "0.3"
gloo-file = { version = "0.2", features = [ "futures" ] }
gloo-file = { version = "0.3", features = [ "futures" ] }
gloo-utils = "0.2"
html5ever = "0.25"
infer = "0.16.0"
instant = { version = "0.1", features = [ "wasm-bindgen", "inaccurate" ] }
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h2>Instrucciones para la generación del modelo 720.</h2>
<p>Comparte en tus redes sociales si te ha sido de utilidad.</p>
<div>
<span style="margin: 2px;">
<a alt="Compartir en X" aria-label="Compartir en twitter" href="https://x.com/intent/tweet?text=Facilita trámites burocráticos como modelo 720&amp;url=https://www.burocratin.com/modelo-720-aeat/" target="_blank" rel="external nofollow"><svg alt="X twitter icon" width="24" height="24" viewBox="0 0 24 24"><path d="m 18.744792,0 h 3.850107 l -8.453496,10.079827 9.876362,13.673506 H 16.267332 L 10.199228,15.444049 3.2522952,23.753333 H -0.59781209 L 8.3578721,12.9723 -1.1,0 h 7.9429388 l 5.4822182,7.5905485 z m -1.347537,21.386764 h 2.134298 L 5.7213859,2.2789175 H 3.4280611 Z" style="stroke-width:0.0856513"/></svg></a>
<a alt="Compartir en X" aria-label="Compartir en X" href="https://x.com/intent/tweet?text=Facilita trámites burocráticos como modelo 720&amp;url=https://www.burocratin.com/modelo-720-aeat/" target="_blank" rel="external nofollow"><svg alt="X twitter icon" width="24" height="24" viewBox="0 0 24 24"><path d="m 18.744792,0 h 3.850107 l -8.453496,10.079827 9.876362,13.673506 H 16.267332 L 10.199228,15.444049 3.2522952,23.753333 H -0.59781209 L 8.3578721,12.9723 -1.1,0 h 7.9429388 l 5.4822182,7.5905485 z m -1.347537,21.386764 h 2.134298 L 5.7213859,2.2789175 H 3.4280611 Z" style="stroke-width:0.0856513"/></svg></a>
</span>
<span style="margin: 5px;">
<a alt="Compartir en facebook" aria-label="Compartir en facebook" href="https://www.facebook.com/sharer/sharer.php?u=www.burocratin.com/modelo-720-aeat/" target="_blank" rel="external nofollow"><svg alt="facebook icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="blue" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"></path></svg></a>
Expand Down
56 changes: 28 additions & 28 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use futures_signals::{
signal::{Mutable, Signal, SignalExt},
};
use gloo_file::{futures::read_as_bytes, Blob};
use wasm_bindgen::{JsCast, UnwrapThrowExt};
use wasm_bindgen_futures::spawn_local;
use web_sys::HtmlInputElement;
use web_sys::{Element, HtmlAnchorElement, HtmlElement, HtmlInputElement};

use crate::{
css::SECTION_HEADER,
Expand Down Expand Up @@ -142,37 +143,36 @@ impl App {
html!("section", {
.child_signal(
Self::is_needed_to_generate_report(this).map(clone!(this => move |x| {
let default_button = Some(
html!("button", {
.attr("type", "button")
.attr("disabled", "true")
.text("Descargar informe AEAT 720")
}));

if x {
let result = App::generate_720_file(&this);
if result.is_ok() {
Some(
html!(
"a", {
.attr("id", "aeat_720_form")
.attr_signal("href", this.aeat720_form_path.signal_cloned())
.attr("alt", "Informe 720 generado")
.attr("download", "fichero-720.txt")
.child(
html!("button", {
.attr("type", "button")
.text("Descargar informe AEAT 720")
})
)
html!("button" => HtmlElement, {
.attr("type", "button")
.attr("download", "fichero-720.txt")
.text("Descargar informe AEAT 720")
.with_node!(_element => {
.event(clone!(this => move |_: events::Click| {
let result = App::generate_720_file(&this);
if result.is_ok() {
let file_path = this.aeat720_form_path.lock_ref().clone().unwrap();
let elem: Element = gloo_utils::document().create_element("a").unwrap_throw();
let link: HtmlAnchorElement = elem.dyn_into().unwrap_throw();
link.set_href(&file_path);
let _ = link.set_attribute("download", "fichero-720.txt");
link.click();
/* let file_path = this.aeat720_form_path.lock_ref().clone().unwrap();
let _ = web_sys::window().unwrap_throw().open_with_url_and_target(&file_path, "fichero-720.txt"); */
}
}))
})
)

} else {
default_button
}
})
)
} else {
default_button
Some(
html!("button", {
.attr("type", "button")
.attr("disabled", "true")
.text("Descargar informe AEAT 720")
}))
}
})))
})
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/degiro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pérdidas
"#;

impl DegiroParser {
fn n_to_m_digits<'b>(n: usize, m: usize) -> impl FnMut(&'b str) -> Res<&str, String> {
fn n_to_m_digits<'b>(n: usize, m: usize) -> impl FnMut(&'b str) -> Res<&'b str, String> {
move |input| {
many_m_n(n, m, one_of("0123456789"))(input)
.map(|(next_input, result)| (next_input, result.into_iter().collect()))
Expand Down
Loading

1 comment on commit 7290083

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.