Compare commits

...

5 Commits

Author SHA1 Message Date
filipriec
8a248cab58 working finally 2025-03-24 18:57:59 +01:00
filipriec
e6851e1fe4 small error to fix 2025-03-24 17:14:12 +01:00
filipriec
65ff1256aa canvas common needs redesign, sidebar displaying even when no profile selected 2025-03-24 16:46:02 +01:00
filipriec
36dc4302a0 sidebar if there is no profile selected 2025-03-24 16:15:55 +01:00
filipriec
938a1f16f1 form component is now in the separate component 2025-03-24 15:57:41 +01:00
15 changed files with 108 additions and 116 deletions

View File

@@ -0,0 +1,4 @@
// src/components/form.rs
pub mod form;
pub use form::*;

View File

@@ -7,7 +7,7 @@ use ratatui::{
}; };
use crate::config::colors::themes::Theme; use crate::config::colors::themes::Theme;
use crate::ui::form::FormState; use crate::ui::form::FormState;
use super::canvas::render_canvas; // Changed to canvas use crate::components::handlers::canvas::render_canvas;
pub fn render_form( pub fn render_form(
f: &mut Frame, f: &mut Frame,

View File

@@ -1,8 +1,6 @@
// src/components/handlers.rs // src/components/handlers.rs
pub mod form;
pub mod canvas; pub mod canvas;
pub mod sidebar; pub mod sidebar;
pub use form::*;
pub use canvas::*; pub use canvas::*;
pub use sidebar::*; pub use sidebar::*;

View File

@@ -9,7 +9,8 @@ use crate::config::colors::themes::Theme;
use common::proto::multieko2::table_definition::{ProfileTreeResponse}; use common::proto::multieko2::table_definition::{ProfileTreeResponse};
use ratatui::text::{Span, Line}; use ratatui::text::{Span, Line};
const SIDEBAR_WIDTH: u16 = 16; // Reduced sidebar width
const SIDEBAR_WIDTH: u16 = 12;
pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) { pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) {
if show_sidebar { if show_sidebar {
@@ -37,46 +38,72 @@ pub fn render_sidebar(
let mut items = Vec::new(); let mut items = Vec::new();
if let Some(profile_name) = selected_profile { if let Some(profile_name) = selected_profile {
if let Some(profile) = profile_tree.profiles.iter() // Existing code for when a profile is selected...
.find(|p| &p.name == profile_name) } else {
{ // Show full profile tree when no profile is selected (compact version)
// Profile header for (profile_idx, profile) in profile_tree.profiles.iter().enumerate() {
// Profile header - more compact
items.push(ListItem::new(Line::from(vec![ items.push(ListItem::new(Line::from(vec![
Span::styled("📁 ", Style::default().fg(theme.accent)), Span::styled("", Style::default().fg(theme.accent)),
Span::styled(&profile.name, Style::default().fg(theme.highlight)), Span::styled(&profile.name, Style::default().fg(theme.highlight)),
]))); ])));
// Tables // Tables with compact prefixes
for (table_idx, table) in profile.tables.iter().enumerate() { for (table_idx, table) in profile.tables.iter().enumerate() {
let is_last = table_idx == profile.tables.len() - 1; let is_last_table = table_idx == profile.tables.len() - 1;
let prefix = if is_last { "└─ " } else { "├─ " }; let is_last_profile = profile_idx == profile_tree.profiles.len() - 1;
// Shorter prefix characters
let prefix = match (is_last_profile, is_last_table) {
(true, true) => "",
(true, false) => "",
(false, true) => "│└",
(false, false) => "│├",
};
// Get table name without year prefix to save space
let display_name = if table.name.starts_with("2025_") {
&table.name[5..] // Skip "2025_" prefix
} else {
&table.name
};
let mut line = vec![ let mut line = vec![
Span::styled(format!(" {}", prefix), Style::default().fg(theme.fg)), Span::styled(prefix, Style::default().fg(theme.fg)),
Span::styled(&table.name, Style::default().fg(theme.fg)), Span::styled(display_name, Style::default().fg(theme.fg)),
]; ];
// Show a simple indicator for dependencies instead of listing them
if !table.depends_on.is_empty() { if !table.depends_on.is_empty() {
line.push(Span::styled( line.push(Span::styled(
format!("{}", table.depends_on.join(", ")), "",
Style::default().fg(theme.secondary) Style::default().fg(theme.secondary)
)); ));
} }
items.push(ListItem::new(Line::from(line))); items.push(ListItem::new(Line::from(line)));
} }
// Compact separator between profiles
if profile_idx < profile_tree.profiles.len() - 1 {
items.push(ListItem::new(Line::from(
Span::styled("", Style::default().fg(theme.secondary))
)));
}
}
if profile_tree.profiles.is_empty() {
items.push(ListItem::new(Span::styled(
"No profiles",
Style::default().fg(theme.secondary)
)));
} }
} else {
items.push(ListItem::new(Span::styled(
"No profile selected",
Style::default().fg(theme.secondary)
)));
} }
let list = List::new(items) let list = List::new(items)
.block(sidebar_block) .block(sidebar_block)
.highlight_style(Style::default().fg(theme.highlight)) .highlight_style(Style::default().fg(theme.highlight))
.highlight_symbol(">>"); .highlight_symbol(">");
f.render_widget(list, area); f.render_widget(list, area);
} }

View File

@@ -3,8 +3,10 @@ pub mod handlers;
pub mod intro; pub mod intro;
pub mod admin; pub mod admin;
pub mod common; pub mod common;
pub mod form;
pub use handlers::*; pub use handlers::*;
pub use intro::*; pub use intro::*;
pub use admin::*; pub use admin::*;
pub use common::*; pub use common::*;
pub use form::*;

View File

@@ -4,7 +4,7 @@ use crossterm::event::{KeyEvent};
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::tui::terminal::grpc_client::GrpcClient; use crate::tui::terminal::grpc_client::GrpcClient;
use crate::tui::terminal::core::TerminalCore; use crate::tui::terminal::core::TerminalCore;
use crate::tui::terminal::commands::CommandHandler; use crate::tui::controls::commands::CommandHandler;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use crate::state::state::AppState; use crate::state::state::AppState;
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest}; use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
@@ -32,12 +32,19 @@ pub async fn handle_core_action(
Ok((false, message)) Ok((false, message))
}, },
"force_quit" => { "force_quit" => {
let (should_exit, message) = command_handler.handle_command("force_quit", terminal).await?; terminal.cleanup()?;
Ok((should_exit, message)) Ok((true, "Force exiting without saving.".to_string()))
}, },
"save_and_quit" => { "save_and_quit" => {
let (should_exit, message) = command_handler.handle_command("save_and_quit", terminal).await?; let message = save(
Ok((should_exit, message)) form_state,
grpc_client,
&mut app_state.ui.is_saved,
current_position,
total_count,
).await?;
terminal.cleanup()?;
Ok((true, format!("{}. Exiting application.", message)))
}, },
"revert" => { "revert" => {
let message = revert( let message = revert(
@@ -132,64 +139,6 @@ pub async fn save(
Ok(message) Ok(message)
} }
/// Shared logic for force quitting the application
pub fn force_quit() -> (bool, String) {
(true, "Force quitting application".to_string())
}
/// Shared logic for saving and quitting
pub async fn save_and_quit(
form_state: &mut FormState,
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
let is_new = *current_position == total_count + 1;
if is_new {
let post_request = PostAdresarRequest {
firma: form_state.values[0].clone(),
kz: form_state.values[1].clone(),
drc: form_state.values[2].clone(),
ulica: form_state.values[3].clone(),
psc: form_state.values[4].clone(),
mesto: form_state.values[5].clone(),
stat: form_state.values[6].clone(),
banka: form_state.values[7].clone(),
ucet: form_state.values[8].clone(),
skladm: form_state.values[9].clone(),
ico: form_state.values[10].clone(),
kontakt: form_state.values[11].clone(),
telefon: form_state.values[12].clone(),
skladu: form_state.values[13].clone(),
fax: form_state.values[14].clone(),
};
let _ = grpc_client.post_adresar(post_request).await?;
} else {
let put_request = PutAdresarRequest {
id: form_state.id,
firma: form_state.values[0].clone(),
kz: form_state.values[1].clone(),
drc: form_state.values[2].clone(),
ulica: form_state.values[3].clone(),
psc: form_state.values[4].clone(),
mesto: form_state.values[5].clone(),
stat: form_state.values[6].clone(),
banka: form_state.values[7].clone(),
ucet: form_state.values[8].clone(),
skladm: form_state.values[9].clone(),
ico: form_state.values[10].clone(),
kontakt: form_state.values[11].clone(),
telefon: form_state.values[12].clone(),
skladu: form_state.values[13].clone(),
fax: form_state.values[14].clone(),
};
let _ = grpc_client.put_adresar(put_request).await?;
}
Ok((true, "Saved and exiting application".to_string()))
}
/// Discard changes since last save /// Discard changes since last save
pub async fn revert( pub async fn revert(
form_state: &mut FormState, form_state: &mut FormState,

View File

@@ -4,6 +4,8 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::grpc_client::GrpcClient; use crate::tui::terminal::grpc_client::GrpcClient;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use crate::tui::controls::commands::CommandHandler;
use crate::tui::terminal::core::TerminalCore;
use crate::modes::{ use crate::modes::{
canvas::{common}, canvas::{common},
}; };
@@ -15,7 +17,8 @@ pub async fn handle_command_event(
command_input: &mut String, command_input: &mut String,
command_message: &mut String, command_message: &mut String,
grpc_client: &mut GrpcClient, grpc_client: &mut GrpcClient,
is_saved: &mut bool, command_handler: &mut CommandHandler,
terminal: &mut TerminalCore,
current_position: &mut u64, current_position: &mut u64,
total_count: u64, total_count: u64,
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> { ) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
@@ -37,7 +40,8 @@ pub async fn handle_command_event(
command_input, command_input,
command_message, command_message,
grpc_client, grpc_client,
is_saved, command_handler,
terminal,
current_position, current_position,
total_count, total_count,
).await; ).await;
@@ -68,7 +72,8 @@ async fn process_command(
command_input: &mut String, command_input: &mut String,
command_message: &mut String, command_message: &mut String,
grpc_client: &mut GrpcClient, grpc_client: &mut GrpcClient,
is_saved: &mut bool, command_handler: &mut CommandHandler,
terminal: &mut TerminalCore,
current_position: &mut u64, current_position: &mut u64,
total_count: u64, total_count: u64,
) -> Result<(bool, String, bool), Box<dyn std::error::Error>> { ) -> Result<(bool, String, bool), Box<dyn std::error::Error>> {
@@ -84,32 +89,24 @@ async fn process_command(
.unwrap_or("unknown"); .unwrap_or("unknown");
match action { match action {
"force_quit" | "save_and_quit" | "quit" => {
let (should_exit, message) = command_handler
.handle_command(action, terminal)
.await?;
command_input.clear();
Ok((should_exit, message, true))
},
"save" => { "save" => {
let message = common::save( let message = common::save(
form_state, form_state,
grpc_client, grpc_client,
is_saved, &mut command_handler.is_saved,
current_position, current_position,
total_count, total_count,
).await?; ).await?;
command_input.clear(); command_input.clear();
return Ok((false, message, true)); return Ok((false, message, true));
}, },
"force_quit" => {
let (should_exit, message) = common::force_quit();
command_input.clear();
return Ok((should_exit, message, true));
},
"save_and_quit" => {
let (should_exit, message) = common::save_and_quit(
form_state,
grpc_client,
current_position,
total_count,
).await?;
command_input.clear();
return Ok((should_exit, message, true));
},
"revert" => { "revert" => {
let message = common::revert( let message = common::revert(
form_state, form_state,

View File

@@ -4,8 +4,8 @@ use crossterm::cursor::SetCursorStyle;
use crate::tui::terminal::{ use crate::tui::terminal::{
core::TerminalCore, core::TerminalCore,
grpc_client::GrpcClient, grpc_client::GrpcClient,
commands::CommandHandler,
}; };
use crate::tui::controls::commands::CommandHandler;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use crate::ui::handlers::rat_state::UiStateHandler; use crate::ui::handlers::rat_state::UiStateHandler;
@@ -224,7 +224,8 @@ impl EventHandler {
&mut self.command_input, &mut self.command_input,
&mut self.command_message, &mut self.command_message,
grpc_client, grpc_client,
&mut app_state.ui.is_saved, command_handler,
terminal,
current_position, current_position,
total_count, total_count,
).await?; ).await?;

View File

@@ -0,0 +1,5 @@
// src/tui/controls.rs
pub mod commands;
pub use commands::*;

View File

@@ -1,9 +1,8 @@
// src/tui/terminal/commands.rs // src/tui/controls/commands.rs
use crate::tui::terminal::core::TerminalCore; use crate::tui::terminal::core::TerminalCore;
pub struct CommandHandler { pub struct CommandHandler {
is_saved: bool, pub is_saved: bool,
} }
impl CommandHandler { impl CommandHandler {
@@ -24,7 +23,10 @@ impl CommandHandler {
} }
} }
async fn handle_quit(&self, terminal: &mut TerminalCore) -> Result<(bool, String), Box<dyn std::error::Error>> { async fn handle_quit(
&self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
if self.is_saved { if self.is_saved {
terminal.cleanup()?; terminal.cleanup()?;
Ok((true, "Exiting.".into())) Ok((true, "Exiting.".into()))
@@ -33,12 +35,18 @@ impl CommandHandler {
} }
} }
async fn handle_force_quit(&self, terminal: &mut TerminalCore) -> Result<(bool, String), Box<dyn std::error::Error>> { async fn handle_force_quit(
&self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
terminal.cleanup()?; terminal.cleanup()?;
Ok((true, "Force exiting without saving.".into())) Ok((true, "Force exiting without saving.".into()))
} }
async fn handle_save_quit(&mut self, terminal: &mut TerminalCore) -> Result<(bool, String), Box<dyn std::error::Error>> { async fn handle_save_quit(
&mut self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
self.is_saved = true; self.is_saved = true;
terminal.cleanup()?; terminal.cleanup()?;
Ok((true, "State saved. Exiting.".into())) Ok((true, "State saved. Exiting.".into()))

View File

@@ -1,2 +1,4 @@
// src/tui/mod.rs // src/tui/mod.rs
pub mod terminal; pub mod terminal;
pub mod controls;

View File

@@ -2,10 +2,8 @@
pub mod core; pub mod core;
pub mod grpc_client; pub mod grpc_client;
pub mod commands;
pub mod event_reader; pub mod event_reader;
pub use core::TerminalCore; pub use core::TerminalCore;
pub use grpc_client::GrpcClient; pub use grpc_client::GrpcClient;
pub use commands::CommandHandler;
pub use event_reader::EventReader; pub use event_reader::EventReader;

View File

@@ -38,7 +38,7 @@ impl FormState {
let fields: Vec<&str> = self.fields.iter().map(|s| s.as_str()).collect(); let fields: Vec<&str> = self.fields.iter().map(|s| s.as_str()).collect();
let values: Vec<&String> = self.values.iter().collect(); let values: Vec<&String> = self.values.iter().collect();
crate::components::handlers::form::render_form( crate::components::form::form::render_form(
f, f,
area, area,
self, self,

View File

@@ -4,7 +4,8 @@ use crate::components::{
render_background, render_background,
render_command_line, render_command_line,
render_status_line, render_status_line,
handlers::{sidebar::{self, calculate_sidebar_layout}, form::render_form}, handlers::sidebar::{self, calculate_sidebar_layout},
form::form::render_form,
intro::{intro}, intro::{intro},
admin::{admin_panel::AdminPanelState}, admin::{admin_panel::AdminPanelState},
}; };

View File

@@ -2,7 +2,7 @@
use crate::tui::terminal::TerminalCore; use crate::tui::terminal::TerminalCore;
use crate::tui::terminal::GrpcClient; use crate::tui::terminal::GrpcClient;
use crate::tui::terminal::CommandHandler; use crate::tui::controls::CommandHandler;
use crate::tui::terminal::EventReader; use crate::tui::terminal::EventReader;
use crate::config::colors::themes::Theme; use crate::config::colors::themes::Theme;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;