summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/transactions_view.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-02-08 20:26:30 +0000
committerJoe Carstairs <me@joeac.net>2026-02-08 20:26:30 +0000
commit97b413aa5962bded37dedb380034fa7b97bdc06c (patch)
tree2cb96478c3808e027528a175e673f77dcc328f9d /schist_desktop_gui/src/gui/components/transactions_view.rs
parent170c1a58ebd8b6ff1dceb5f46146f76b601c91ad (diff)
task-085: display transaction data in tables
Diffstat (limited to 'schist_desktop_gui/src/gui/components/transactions_view.rs')
-rw-r--r--schist_desktop_gui/src/gui/components/transactions_view.rs87
1 files changed, 69 insertions, 18 deletions
diff --git a/schist_desktop_gui/src/gui/components/transactions_view.rs b/schist_desktop_gui/src/gui/components/transactions_view.rs
index f39b522..8e076f1 100644
--- a/schist_desktop_gui/src/gui/components/transactions_view.rs
+++ b/schist_desktop_gui/src/gui/components/transactions_view.rs
@@ -6,13 +6,14 @@ use itertools::Itertools;
use schist_models::{Account, Transaction};
use crate::{
- gui::components::{navigation, AccountNavigationEntry, Navigation},
+ gui::components::{navigation, table, AccountNavigationEntry, Navigation, Table},
traits::Component,
};
#[derive(Clone, Debug)]
pub struct TransactionsView {
navigation: Navigation<AccountNavigationEntry>,
+ table: Table<i32>,
transactions_by_account_id: HashMap<i32, Vec<Transaction>>,
}
@@ -23,6 +24,7 @@ pub enum Message {
SelectPrevAccount,
SetAccounts(Vec<Account>),
SetTransactions(Vec<Transaction>),
+ TableMessage(table::Message),
}
pub enum Action {
@@ -30,57 +32,106 @@ pub enum Action {
}
impl TransactionsView {
- pub fn new(accounts: Vec<Account>, transactions: Vec<Transaction>) -> Self {
+ pub fn new(accounts: &[Account], transactions: &[Transaction]) -> Self {
let account_navigation_entries: Vec<AccountNavigationEntry> = accounts
- .into_iter()
+ .iter()
+ .cloned()
.map(AccountNavigationEntry::new)
.collect();
let navigation = Navigation::new(
account_navigation_entries.first().cloned(),
account_navigation_entries,
);
- Self {
+ let mut transactions_view = Self {
navigation: navigation,
+ table: Table::default(),
transactions_by_account_id: transactions
.into_iter()
+ .cloned()
.into_group_map_by(|t| t.account_id),
- }
+ };
+ transactions_view.refresh_table();
+ transactions_view
+ }
+
+ fn refresh_table(&mut self) {
+ self.table =
+ Table {
+ cols: vec![
+ table::Column::new(0, "Date"),
+ table::Column::new(1, "Bucket"),
+ table::Column::new(2, "Payee"),
+ table::Column::new(3, "Quantity"),
+ table::Column::new(4, "Balance"),
+ ],
+ rows: self.navigation.active_option.clone().map_or_else(
+ Vec::new,
+ |AccountNavigationEntry { account, .. }| {
+ self.transactions_by_account_id
+ .get(&account.id)
+ .cloned()
+ .unwrap_or_else(Vec::new)
+ .iter()
+ .map(|t| {
+ HashMap::from([
+ (0, table::Value::String(t.date.to_string())),
+ (
+ 1,
+ table::Value::String(t.bucket_id.map_or_else(
+ || String::from("None"),
+ |id| id.to_string(),
+ )),
+ ),
+ (2, table::Value::String(t.counterparty.clone())),
+ (3, table::Value::Currency(t.amount)),
+ (4, table::Value::String(String::from("TODO"))),
+ ])
+ })
+ .collect()
+ },
+ ),
+ };
}
}
impl<'a> Component<'a, Message, Action> for TransactionsView {
fn update(&mut self, message: Message) -> Action {
match message {
- Message::NavigationMessage(message) => {
- self.navigation.update(message);
- Action::None
- }
+ Message::NavigationMessage(message) => self.update_navigation(message),
Message::SetAccounts(accounts) => {
let account_navigation_entries: Vec<AccountNavigationEntry> = accounts
.into_iter()
.map(AccountNavigationEntry::new)
.collect();
- self.navigation
- .update(navigation::Message::SetOptions(account_navigation_entries));
- Action::None
+ self.update_navigation(navigation::Message::SetOptions(account_navigation_entries))
}
Message::SetTransactions(transactions) => {
self.transactions_by_account_id =
transactions.into_iter().into_group_map_by(|t| t.account_id);
+ self.refresh_table();
Action::None
}
- Message::SelectNextAccount => {
- self.navigation.update(navigation::Message::SelectNext);
- Action::None
- }
+ Message::SelectNextAccount => self.update_navigation(navigation::Message::SelectNext),
+
+ Message::SelectPrevAccount => self.update_navigation(navigation::Message::SelectPrev),
+ }
+ }
+}
- Message::SelectPrevAccount => {
- self.navigation.update(navigation::Message::SelectPrev);
+impl TransactionsView {
+ fn update_navigation(
+ &mut self,
+ message: navigation::Message<AccountNavigationEntry>,
+ ) -> Action {
+ match self.navigation.update(message) {
+ navigation::Action::ActivateOption(_) | navigation::Action::SelectOption(_) => {
+ self.refresh_table();
Action::None
}
+ navigation::Action::None => Action::None,
}
}
}