trx as list => to change to table
This commit is contained in:
parent
2395d72c7e
commit
df4fd0202d
47
src/app.rs
47
src/app.rs
@ -3,7 +3,7 @@ use sqlite::Connection;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data_layer,
|
data_layer,
|
||||||
entities::{Account, AccountType},
|
entities::{Account, AccountType, Transaction},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum CurrentScreen {
|
pub enum CurrentScreen {
|
||||||
@ -38,10 +38,39 @@ impl AccountList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct TrxList {
|
||||||
|
trx: Vec<Transaction>,
|
||||||
|
pub state: ListState,
|
||||||
|
}
|
||||||
|
impl TrxList {
|
||||||
|
fn new() -> TrxList {
|
||||||
|
let mut list_state = ListState::default();
|
||||||
|
list_state.select_first();
|
||||||
|
return TrxList {
|
||||||
|
trx: Vec::new(),
|
||||||
|
state: list_state,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_trx(&self, con: &Connection, app: &App) -> Vec<Transaction> {
|
||||||
|
if self.trx.iter().count() == 0 {
|
||||||
|
if let Some(i) = app.acc_list.state.selected() {
|
||||||
|
return data_layer::get_account_transactions(
|
||||||
|
con,
|
||||||
|
app.get_list_accounts()[i].get_id(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Vec::new();
|
||||||
|
}
|
||||||
|
return self.trx.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub current_screen: CurrentScreen,
|
pub current_screen: CurrentScreen,
|
||||||
pub current_widget: CurrentWidget,
|
pub current_widget: CurrentWidget,
|
||||||
pub acc_list: AccountList,
|
pub acc_list: AccountList,
|
||||||
|
pub trx_list: TrxList,
|
||||||
pub connection: Connection,
|
pub connection: Connection,
|
||||||
exit: bool,
|
exit: bool,
|
||||||
}
|
}
|
||||||
@ -59,6 +88,7 @@ impl App {
|
|||||||
current_screen: CurrentScreen::Main,
|
current_screen: CurrentScreen::Main,
|
||||||
current_widget: CurrentWidget::AccountList,
|
current_widget: CurrentWidget::AccountList,
|
||||||
acc_list: AccountList::new(),
|
acc_list: AccountList::new(),
|
||||||
|
trx_list: TrxList::new(),
|
||||||
connection: con,
|
connection: con,
|
||||||
exit: false,
|
exit: false,
|
||||||
};
|
};
|
||||||
@ -80,4 +110,19 @@ impl App {
|
|||||||
pub fn previous_ac(&mut self) {
|
pub fn previous_ac(&mut self) {
|
||||||
self.acc_list.state.select_previous();
|
self.acc_list.state.select_previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_list_trx(&self) -> Vec<Transaction> {
|
||||||
|
let accounts = &self.trx_list.get_trx(&self.connection, self);
|
||||||
|
return accounts.to_vec();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn first_tr(&mut self) {
|
||||||
|
self.trx_list.state.select_first();
|
||||||
|
}
|
||||||
|
pub fn next_tr(&mut self) {
|
||||||
|
self.trx_list.state.select_next();
|
||||||
|
}
|
||||||
|
pub fn previous_tr(&mut self) {
|
||||||
|
self.trx_list.state.select_previous();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use crate::{data_layer, entities::Account};
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use sqlite::Connection;
|
use sqlite::Connection;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Transaction {
|
pub struct Transaction {
|
||||||
id: i64,
|
id: i64,
|
||||||
account_id: i64,
|
account_id: i64,
|
||||||
|
|||||||
36
src/ui.rs
36
src/ui.rs
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
app::{App, CurrentScreen, CurrentWidget},
|
app::{App, CurrentScreen, CurrentWidget},
|
||||||
entities::Account,
|
entities::{Account, Transaction},
|
||||||
};
|
};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
@ -50,7 +50,7 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
|
|||||||
CurrentWidget::TrxList => trx_block = trx_block.border_style(active_style),
|
CurrentWidget::TrxList => trx_block = trx_block.border_style(active_style),
|
||||||
};
|
};
|
||||||
|
|
||||||
let items: Vec<ListItem> = app
|
let ac_items: Vec<ListItem> = app
|
||||||
.get_list_accounts()
|
.get_list_accounts()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -60,7 +60,7 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let list = List::new(items)
|
let list = List::new(ac_items)
|
||||||
.block(ac_block)
|
.block(ac_block)
|
||||||
.highlight_style(SELECTED_STYLE)
|
.highlight_style(SELECTED_STYLE)
|
||||||
.highlight_symbol(">")
|
.highlight_symbol(">")
|
||||||
@ -79,7 +79,29 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
|
|||||||
"No account selected...".to_string()
|
"No account selected...".to_string()
|
||||||
};
|
};
|
||||||
frame.render_widget(Paragraph::new(info).block(info_block), right_layout[0]);
|
frame.render_widget(Paragraph::new(info).block(info_block), right_layout[0]);
|
||||||
frame.render_widget(Paragraph::new("inner 1").block(trx_block), right_layout[1]);
|
|
||||||
|
let trx_items: Vec<ListItem> = app
|
||||||
|
.get_list_trx()
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, tr)| {
|
||||||
|
let color = alternate_colors(i);
|
||||||
|
ListItem::from(tr).bg(color)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let trx_list = List::new(trx_items)
|
||||||
|
.block(trx_block)
|
||||||
|
.highlight_style(SELECTED_STYLE)
|
||||||
|
.highlight_symbol(">")
|
||||||
|
.highlight_spacing(HighlightSpacing::Always);
|
||||||
|
|
||||||
|
StatefulWidget::render(
|
||||||
|
trx_list,
|
||||||
|
right_layout[1],
|
||||||
|
frame.buffer_mut(),
|
||||||
|
&mut app.trx_list.state,
|
||||||
|
);
|
||||||
|
|
||||||
if let CurrentScreen::Exiting = app.current_screen {
|
if let CurrentScreen::Exiting = app.current_screen {
|
||||||
let popup = Block::default()
|
let popup = Block::default()
|
||||||
@ -134,3 +156,9 @@ impl From<&Account> for ListItem<'_> {
|
|||||||
ListItem::new(line)
|
ListItem::new(line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl From<&Transaction> for ListItem<'_> {
|
||||||
|
fn from(value: &Transaction) -> Self {
|
||||||
|
let line = Line::styled(value.get_desc(), TEXT_FG_COLOR);
|
||||||
|
ListItem::new(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user