diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-08-17 04:37:07 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-08-17 04:37:07 -0400 |
commit | f5a1913b2b1b471d1b816db34b1c6d2da4970c73 (patch) | |
tree | bd932832d08c2ab263c4064f110a6ff44f1dc518 | |
parent | 41df9d4e94bad6b89f0b4e4e535a6e30576b2879 (diff) | |
download | ynab-api-f5a1913b2b1b471d1b816db34b1c6d2da4970c73.tar.gz ynab-api-f5a1913b2b1b471d1b816db34b1c6d2da4970c73.zip |
count the number of selected transactions
-rw-r--r-- | src/views/txn_table.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/views/txn_table.rs b/src/views/txn_table.rs index 7314337..a2ec3f7 100644 --- a/src/views/txn_table.rs +++ b/src/views/txn_table.rs @@ -209,31 +209,39 @@ fn txn_table( } }); - let outflow = s - .call_on_id("outflows_table", |v: &mut TxnTableView| -> i64 { + let outflows: Vec<_> = s + .call_on_id("outflows_table", |v: &mut TxnTableView| { v.borrow_items() .iter() .filter(|t| t.selected) .map(|t| t.amount) - .sum() + .collect() }) .unwrap(); - let inflow = s - .call_on_id("inflows_table", |v: &mut TxnTableView| -> i64 { + let inflows: Vec<_> = s + .call_on_id("inflows_table", |v: &mut TxnTableView| { v.borrow_items() .iter() .filter(|t| t.selected) .map(|t| t.amount) - .sum() + .collect() }) .unwrap(); + let outflow: i64 = outflows.iter().sum(); + let inflow: i64 = inflows.iter().sum(); 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) + "Selected: {} ({} transaction{}", + crate::ynab::format_amount(amount), + outflows.len() + inflows.len(), + if outflows.len() + inflows.len() == 1 { + ") " + } else { + "s)" + } )); }, ); @@ -269,7 +277,7 @@ 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") + cursive::views::TextView::new("Selected: $0.00 (0 transactions)") .h_align(cursive::align::HAlign::Right) .with_id("selected_total"), ); |