aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-08-18 14:16:45 -0400
committerJesse Luehrs <doy@tozt.net>2019-08-18 14:16:45 -0400
commit5226ccd054e93d8b0ec119c84ef949cabc44ae52 (patch)
treea8ccfc5f7d55102d4a724f6732b0c8fb971160aa
parentaef8e74b849c7861dce63c0e2c1d0a8bdfa379fe (diff)
downloadynab-reimbursements-5226ccd054e93d8b0ec119c84ef949cabc44ae52.tar.gz
ynab-reimbursements-5226ccd054e93d8b0ec119c84ef949cabc44ae52.zip
simplify
-rw-r--r--src/views/txn_tables.rs46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/views/txn_tables.rs b/src/views/txn_tables.rs
index 36e535b..757e25a 100644
--- a/src/views/txn_tables.rs
+++ b/src/views/txn_tables.rs
@@ -1,5 +1,9 @@
use cursive::view::Identifiable;
+const SELECTED_TOTAL_ID: &str = "selected_total";
+const INFLOWS_TABLE_ID: &str = "inflows_table";
+const OUTFLOWS_TABLE_ID: &str = "outflows_table";
+
pub struct TxnTables {
view: super::util::FullView<cursive::views::LinearLayout>,
}
@@ -17,10 +21,17 @@ impl TxnTables {
layout.add_child(
cursive::views::TextView::new("Selected: $0.00 (0 transactions)")
.h_align(cursive::align::HAlign::Right)
- .with_id("selected_total"),
+ .with_id(SELECTED_TOTAL_ID),
);
- let mut inflows_table = inflows_table(&budget);
+ let inflows = budget
+ .reimbursables()
+ .iter()
+ .filter(|t| !t.reimbursed && t.amount > 0)
+ .cloned()
+ .collect();
+ let mut inflows_table =
+ super::txn_table::TxnTable::new(inflows, INFLOWS_TABLE_ID);
layout.add_child(cursive::views::TextView::new(format!(
"Inflows: {} ({} transaction{}",
crate::ynab::format_amount(inflows_table.amount()),
@@ -36,7 +47,14 @@ impl TxnTables {
layout.add_child(cursive::views::TextView::new(" "));
- let mut outflows_table = outflows_table(&budget);
+ let outflows = budget
+ .reimbursables()
+ .iter()
+ .filter(|t| !t.reimbursed && t.amount <= 0)
+ .cloned()
+ .collect();
+ let mut outflows_table =
+ super::txn_table::TxnTable::new(outflows, OUTFLOWS_TABLE_ID);
layout.add_child(cursive::views::TextView::new(format!(
"Outflows: {} ({} transaction{}",
crate::ynab::format_amount(outflows_table.amount()),
@@ -56,25 +74,3 @@ impl TxnTables {
}
}
}
-
-fn inflows_table(budget: &crate::ynab::Budget) -> super::txn_table::TxnTable {
- let inflows = budget
- .reimbursables()
- .iter()
- .filter(|t| !t.reimbursed && t.amount > 0)
- .cloned()
- .collect();
- super::txn_table::TxnTable::new(inflows, "inflows_table")
-}
-
-fn outflows_table(
- budget: &crate::ynab::Budget,
-) -> super::txn_table::TxnTable {
- let outflows = budget
- .reimbursables()
- .iter()
- .filter(|t| !t.reimbursed && t.amount <= 0)
- .cloned()
- .collect();
- super::txn_table::TxnTable::new(outflows, "outflows_table")
-}