added quick entry and quick-paycheck screens
This commit is contained in:
parent
7ff39c993f
commit
43046ede95
4 changed files with 219 additions and 17 deletions
|
@ -78,7 +78,7 @@ pub enum ActiveFrame {
|
||||||
|
|
||||||
pub struct States<'a> {
|
pub struct States<'a> {
|
||||||
pub nav_state: NavigationState<'a>,
|
pub nav_state: NavigationState<'a>,
|
||||||
pub transactions: QuickTransactionState,
|
pub quick_transactions: QuickTransactionState,
|
||||||
pub manual_transactions: ManualTransactionState,
|
pub manual_transactions: ManualTransactionState,
|
||||||
pub history: HistoryState,
|
pub history: HistoryState,
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl<'a> States<'a> {
|
||||||
pub fn new() -> States<'a> {
|
pub fn new() -> States<'a> {
|
||||||
States {
|
States {
|
||||||
nav_state: NavigationState::new(),
|
nav_state: NavigationState::new(),
|
||||||
transactions: QuickTransactionState::new(),
|
quick_transactions: QuickTransactionState::new(),
|
||||||
manual_transactions: ManualTransactionState::new(),
|
manual_transactions: ManualTransactionState::new(),
|
||||||
history: HistoryState::new(),
|
history: HistoryState::new(),
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,7 @@ pub fn render_manual_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_manual_row<B: Backend>(
|
fn render_manual_row<B: Backend>(
|
||||||
f: &mut Frame<B>,
|
f: &mut Frame<B>,
|
||||||
row_body_rect: Rect,
|
row_body_rect: Rect,
|
||||||
left_text: &str,
|
left_text: &str,
|
||||||
|
|
|
@ -1,37 +1,69 @@
|
||||||
|
|
||||||
pub mod paycheck;
|
pub mod paycheck;
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::{Color, Style},
|
style::{Color, Style},
|
||||||
text::Text,
|
text::{Line, Span},
|
||||||
widgets::{Block, Borders, Paragraph},
|
widgets::{Block, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
|
use self::paycheck::QuickPaycheckState;
|
||||||
|
|
||||||
enum SelectedQuickEntry {
|
enum SelectedQuickEntry {
|
||||||
Paycheck,
|
Paycheck,
|
||||||
|
ChoiceMenu(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct QuickTransactionState {
|
pub struct QuickTransactionState {
|
||||||
|
current_screen: SelectedQuickEntry,
|
||||||
|
paycheck_state: QuickPaycheckState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuickTransactionState {
|
impl QuickTransactionState {
|
||||||
pub fn new() -> QuickTransactionState {
|
pub fn new() -> QuickTransactionState {
|
||||||
QuickTransactionState {
|
QuickTransactionState {
|
||||||
|
current_screen: SelectedQuickEntry::ChoiceMenu(0),
|
||||||
|
paycheck_state: QuickPaycheckState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_event(event: KeyEvent, app: &mut App) {
|
pub fn handle_event(event: KeyEvent, app: &mut App) {
|
||||||
// let transact_state = &app.states.transactions;
|
match app.states.quick_transactions.current_screen {
|
||||||
|
SelectedQuickEntry::ChoiceMenu(selected) => {
|
||||||
if event.kind == KeyEventKind::Press {
|
if event.kind == KeyEventKind::Press {
|
||||||
match event.code {
|
match event.code {
|
||||||
|
KeyCode::Up => {
|
||||||
|
if selected > 0 {
|
||||||
|
app.states.quick_transactions.current_screen =
|
||||||
|
SelectedQuickEntry::ChoiceMenu(selected - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyCode::Down => {
|
||||||
|
// Change this when new rows are added
|
||||||
|
if selected < 1 {
|
||||||
|
app.states.quick_transactions.current_screen =
|
||||||
|
SelectedQuickEntry::ChoiceMenu(selected + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyCode::Enter => match selected {
|
||||||
|
0 => {
|
||||||
|
app.states.quick_transactions.current_screen =
|
||||||
|
SelectedQuickEntry::Paycheck;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SelectedQuickEntry::Paycheck => {
|
||||||
|
paycheck::QuickPaycheckState::handle_event(event, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,5 +76,63 @@ impl Default for QuickTransactionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_quick_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
pub fn render_quick_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
||||||
|
match app.states.quick_transactions.current_screen {
|
||||||
|
SelectedQuickEntry::Paycheck => {
|
||||||
|
QuickPaycheckState::render(f, body_rect, &app.states.quick_transactions.paycheck_state);
|
||||||
|
}
|
||||||
|
SelectedQuickEntry::ChoiceMenu(selected) => {
|
||||||
|
render_choose_menu(f, body_rect, selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_choose_menu<B: Backend>(f: &mut Frame<B>, body_rect: Rect, cur_select_index: usize) {
|
||||||
|
let width_chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Percentage(30),
|
||||||
|
Constraint::Percentage(40),
|
||||||
|
Constraint::Percentage(30),
|
||||||
|
])
|
||||||
|
.split(body_rect);
|
||||||
|
|
||||||
|
let constraints: Vec<Constraint> = vec![
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1), // account
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1), // amount
|
||||||
|
Constraint::Length(1),
|
||||||
|
];
|
||||||
|
|
||||||
|
let split_body = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints(constraints)
|
||||||
|
.split(width_chunks[1]);
|
||||||
|
|
||||||
|
// Selected Quick Entry :: Paycheck
|
||||||
|
render_row(f, split_body[1], "Paycheck", cur_select_index == 0);
|
||||||
|
|
||||||
|
// Selected Quick Entry :: Paycheck
|
||||||
|
render_row(f, split_body[3], "Nothing", cur_select_index == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_row<B: Backend>(f: &mut Frame<B>, render_to: Rect, text: &str, focus: bool) {
|
||||||
|
let block: Block;
|
||||||
|
if focus {
|
||||||
|
block = Block::default()
|
||||||
|
.borders(Borders::NONE)
|
||||||
|
.style(Style::default().bg(Color::Yellow));
|
||||||
|
} else {
|
||||||
|
block = Block::default()
|
||||||
|
.borders(Borders::NONE)
|
||||||
|
.style(Style::default().bg(Color::White));
|
||||||
|
}
|
||||||
|
let p_widget: Paragraph = Paragraph::new(Line::from(Span::styled(
|
||||||
|
text,
|
||||||
|
Style::default().fg(Color::Black),
|
||||||
|
)))
|
||||||
|
.alignment(Alignment::Center)
|
||||||
|
.block(block);
|
||||||
|
|
||||||
|
f.render_widget(p_widget, render_to);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use crossterm::event::{KeyEvent, KeyEventKind, KeyCode};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::{Color, Style},
|
style::{Color, Style},
|
||||||
text::{Line, Span, Text},
|
text::{Line, Span, Text},
|
||||||
widgets::{Block, Borders, List, ListItem, Paragraph},
|
widgets::{Block, Borders, List, ListItem, Paragraph},
|
||||||
|
@ -10,9 +10,17 @@ use ratatui::{
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum SelectedEntry {
|
||||||
|
Gross,
|
||||||
|
Net,
|
||||||
|
Execute,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct QuickPaycheckState {
|
pub struct QuickPaycheckState {
|
||||||
pub gross_amount: String,
|
pub gross_amount: String,
|
||||||
pub net_amount: String,
|
pub net_amount: String,
|
||||||
|
selected: SelectedEntry,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl QuickPaycheckState {
|
impl QuickPaycheckState {
|
||||||
|
@ -20,11 +28,75 @@ impl QuickPaycheckState {
|
||||||
QuickPaycheckState {
|
QuickPaycheckState {
|
||||||
net_amount: "".to_string(),
|
net_amount: "".to_string(),
|
||||||
gross_amount: "".to_string(),
|
gross_amount: "".to_string(),
|
||||||
|
selected: SelectedEntry::Net,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &mut App) {
|
pub fn render<B: Backend>(f: &mut Frame<B>, body_rect: Rect, state: &QuickPaycheckState) {
|
||||||
|
let constraints: Vec<Constraint> = vec![
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1), // Gross amount
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1), // net amount
|
||||||
|
Constraint::Length(1),
|
||||||
|
Constraint::Length(1), // execute button
|
||||||
|
];
|
||||||
|
|
||||||
|
let split_body = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints(constraints)
|
||||||
|
.split(body_rect);
|
||||||
|
|
||||||
|
render_labled_entry_row(
|
||||||
|
f,
|
||||||
|
split_body[2],
|
||||||
|
"Take home:",
|
||||||
|
&state.net_amount,
|
||||||
|
state.selected == SelectedEntry::Net,
|
||||||
|
);
|
||||||
|
|
||||||
|
render_labled_entry_row(
|
||||||
|
f,
|
||||||
|
split_body[4],
|
||||||
|
"Gross:",
|
||||||
|
&state.net_amount,
|
||||||
|
state.selected == SelectedEntry::Gross,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_event(event: KeyEvent, app: &mut App) {
|
||||||
|
if event.kind == KeyEventKind::Press {
|
||||||
|
match event.code {
|
||||||
|
KeyCode::Up => {
|
||||||
|
match app.states.quick_transactions.paycheck_state.selected {
|
||||||
|
SelectedEntry::Net => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Execute;
|
||||||
|
}
|
||||||
|
SelectedEntry::Gross => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Net;
|
||||||
|
}
|
||||||
|
SelectedEntry::Execute => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Gross;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyCode::Down => {
|
||||||
|
match app.states.quick_transactions.paycheck_state.selected {
|
||||||
|
SelectedEntry::Net => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Gross;
|
||||||
|
}
|
||||||
|
SelectedEntry::Gross => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Execute;
|
||||||
|
}
|
||||||
|
SelectedEntry::Execute => {
|
||||||
|
app.states.quick_transactions.paycheck_state.selected = SelectedEntry::Net;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,3 +105,43 @@ impl Default for QuickPaycheckState {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_labled_entry_row<B: Backend>(
|
||||||
|
f: &mut Frame<B>,
|
||||||
|
row_body_rect: Rect,
|
||||||
|
left_text: &str,
|
||||||
|
right_text: &String,
|
||||||
|
do_highlight: bool,
|
||||||
|
) {
|
||||||
|
let horizontal_pieces = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Percentage(35),
|
||||||
|
Constraint::Percentage(45),
|
||||||
|
Constraint::Percentage(20),
|
||||||
|
])
|
||||||
|
.split(row_body_rect);
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(Text::styled(left_text, Style::default().fg(Color::Yellow)))
|
||||||
|
.alignment(Alignment::Right),
|
||||||
|
horizontal_pieces[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
let right_bg_color = if do_highlight {
|
||||||
|
Color::Yellow
|
||||||
|
} else {
|
||||||
|
Color::White
|
||||||
|
};
|
||||||
|
|
||||||
|
f.render_widget(
|
||||||
|
Paragraph::new(Text::styled(right_text, Style::default().fg(Color::Black)))
|
||||||
|
.alignment(Alignment::Center)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::NONE)
|
||||||
|
.style(Style::default().bg(right_bg_color)),
|
||||||
|
),
|
||||||
|
horizontal_pieces[1],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue