aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-08-12 04:07:28 -0400
committerJesse Luehrs <doy@tozt.net>2019-08-12 04:07:28 -0400
commita3779d11dd6e2069b5284c9bb85e55f5cbe6b808 (patch)
tree76316ddaf809387ba0ee02f608684ed638341ab5
parentf25f7a8f610bf60b5a79fc59192904f225ee7da2 (diff)
downloadynab-api-a3779d11dd6e2069b5284c9bb85e55f5cbe6b808.tar.gz
ynab-api-a3779d11dd6e2069b5284c9bb85e55f5cbe6b808.zip
display currently selected total amount
-rw-r--r--src/views/txn_table.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/views/txn_table.rs b/src/views/txn_table.rs
index 8ace7b0..8cc927c 100644
--- a/src/views/txn_table.rs
+++ b/src/views/txn_table.rs
@@ -154,6 +154,35 @@ fn txn_table(
txn.selected = !txn.selected;
}
});
+
+ let outflow = s
+ .call_on_id("outflows_table", |v: &mut TxnTableView| -> i64 {
+ v.borrow_items()
+ .iter()
+ .filter(|t| t.selected)
+ .map(|t| t.amount)
+ .sum()
+ })
+ .unwrap();
+ let inflow = s
+ .call_on_id("inflows_table", |v: &mut TxnTableView| -> i64 {
+ v.borrow_items()
+ .iter()
+ .filter(|t| t.selected)
+ .map(|t| t.amount)
+ .sum()
+ })
+ .unwrap();
+ let amount = outflow + inflow;
+ s.call_on_id(
+ "selected_total",
+ |v: &mut cursive::views::TextView| {
+ v.set_content(format!(
+ "Selected: {}",
+ crate::ynab::format_amount(amount)
+ ));
+ },
+ );
});
TableView { view }
}
@@ -161,9 +190,15 @@ fn txn_table(
pub fn txn_tables(budget: &crate::ynab::Budget) -> impl cursive::view::View {
let mut layout = cursive::views::LinearLayout::vertical();
+ layout.add_child(
+ cursive::views::TextView::new("Selected: $0.00")
+ .h_align(cursive::align::HAlign::Right)
+ .with_id("selected_total"),
+ );
+
let mut inflows_table = inflows_table(&budget);
layout.add_child(cursive::views::TextView::new(format!(
- "\nInflows: {} ({} transactions)",
+ "Inflows: {} ({} transactions)",
crate::ynab::format_amount(inflows_table.amount()),
inflows_table.len()
)));
@@ -176,9 +211,11 @@ pub fn txn_tables(budget: &crate::ynab::Budget) -> impl cursive::view::View {
),
));
+ layout.add_child(cursive::views::TextView::new(" "));
+
let mut outflows_table = outflows_table(&budget);
layout.add_child(cursive::views::TextView::new(format!(
- "\nOutflows: {} ({} transactions)",
+ "Outflows: {} ({} transactions)",
crate::ynab::format_amount(outflows_table.amount()),
outflows_table.len()
)));