Compare commits

...

10 Commits

Author SHA1 Message Date
filipriec
c592dfc7f5 intro page working properly well 2025-03-21 23:07:10 +01:00
filipriec
1b0aaa55c9 switched stuff in the state.rs 2025-03-21 22:46:50 +01:00
filipriec
44c5963c71 removed unused stuff 2025-03-21 22:22:35 +01:00
filipriec
911dba9bce working profiler tree 2025-03-21 22:20:43 +01:00
filipriec
d55dff8a3e deprecation fixed 2025-03-21 21:26:06 +01:00
filipriec
8b2120bdc8 working perfectly well 2025-03-21 19:56:07 +01:00
filipriec
8ce90f3c42 sidebar behaviour is now amazing 2025-03-21 18:55:50 +01:00
filipriec
62d7fb6bda centered form 2025-03-21 18:46:17 +01:00
filipriec
27cca8763b removed preview card 2025-03-21 18:21:40 +01:00
filipriec
74054f2724 removed nonsense 2025-03-21 16:23:47 +01:00
12 changed files with 299 additions and 126 deletions

View File

@@ -1,14 +1,16 @@
// src/components/handlers.rs
pub mod form;
pub mod preview_card;
pub mod command_line;
pub mod status_line;
pub mod canvas;
pub mod sidebar;
pub mod background;
pub mod intro;
pub use command_line::render_command_line;
pub use form::*;
pub use preview_card::render_preview_card;
pub use status_line::render_status_line;
pub use canvas::*;
pub use sidebar::*;
pub use background::*;
pub use intro::*;

View File

@@ -0,0 +1,15 @@
// src/components/handlers/background.rs
use ratatui::{
widgets::{Block},
layout::Rect,
style::Style,
Frame,
};
use crate::config::colors::Theme;
pub fn render_background(f: &mut Frame, area: Rect, theme: &Theme) {
let background = Block::default()
.style(Style::default().bg(theme.bg));
f.render_widget(background, area);
}

View File

@@ -0,0 +1,110 @@
// src/components/handlers/intro.rs
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::Style,
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
prelude::Margin,
Frame,
};
use crate::config::colors::Theme;
pub struct IntroState {
pub selected_option: usize,
}
impl IntroState {
pub fn new() -> Self {
Self { selected_option: 0 }
}
pub fn render(&self, f: &mut Frame, area: Rect, theme: &Theme) {
let block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(theme.accent))
.style(Style::default().bg(theme.bg));
let inner_area = block.inner(area);
f.render_widget(block, area);
// Center layout
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage(35),
Constraint::Length(5),
Constraint::Percentage(35),
])
.split(inner_area);
// Title
let title = Line::from(vec![
Span::styled("multieko2", Style::default().fg(theme.highlight)),
Span::styled(" v", Style::default().fg(theme.fg)),
Span::styled(env!("CARGO_PKG_VERSION"), Style::default().fg(theme.secondary)),
]);
let title_para = Paragraph::new(title)
.alignment(Alignment::Center);
f.render_widget(title_para, chunks[1]);
// Buttons
let button_area = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
.split(chunks[1].inner(Margin {
horizontal: 1,
vertical: 1
}));
self.render_button(
f,
button_area[0],
"Continue",
self.selected_option == 0,
theme,
);
self.render_button(
f,
button_area[1],
"Admin",
self.selected_option == 1,
theme,
);
}
fn render_button(&self, f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
let button_style = if selected {
Style::default()
.fg(theme.highlight)
.bg(theme.bg)
.add_modifier(ratatui::style::Modifier::BOLD)
} else {
Style::default().fg(theme.fg).bg(theme.bg)
};
let button = Paragraph::new(text)
.style(button_style)
.alignment(Alignment::Center)
.block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Double)
.border_style(if selected {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.border)
}),
);
f.render_widget(button, area);
}
pub fn next_option(&mut self) {
self.selected_option = (self.selected_option + 1) % 2;
}
pub fn previous_option(&mut self) {
self.selected_option = if self.selected_option == 0 { 1 } else { 0 };
}
}

View File

@@ -1,33 +0,0 @@
// src/client/components/preview_card.rs
use ratatui::{
widgets::{Block, Borders, List, ListItem},
layout::Rect,
style::Style,
text::Text,
Frame,
};
use crate::config::colors::Theme;
pub fn render_preview_card(f: &mut Frame, area: Rect, fields: &[&String], theme: &Theme) {
let card = Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(theme.border))
.title(" Preview Card ")
.style(Style::default().bg(theme.bg).fg(theme.fg));
let items = vec![
ListItem::new(Text::from(format!("Firma: {}", fields[0]))),
ListItem::new(Text::from(format!("Ulica: {}", fields[1]))),
ListItem::new(Text::from(format!("Mesto: {}", fields[2]))),
ListItem::new(Text::from(format!("PSC: {}", fields[3]))),
ListItem::new(Text::from(format!("ICO: {}", fields[4]))),
ListItem::new(Text::from(format!("Kontakt: {}", fields[5]))),
ListItem::new(Text::from(format!("Telefon: {}", fields[6]))),
];
let list = List::new(items)
.block(card)
.style(Style::default().bg(theme.bg).fg(theme.fg));
f.render_widget(list, area);
}

View File

@@ -1,22 +1,67 @@
// src/components/handlers/sidebar.rs
use ratatui::{
widgets::{Block, List, ListItem},
layout::Rect,
layout::{Rect, Direction, Layout, Constraint},
style::Style,
text::Text,
Frame,
};
use crate::config::colors::Theme;
use common::proto::multieko2::table_definition::{ProfileTreeResponse};
use ratatui::text::{Span, Line};
pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme) {
const SIDEBAR_WIDTH: u16 = 16;
pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) -> (Option<Rect>, Rect) {
if show_sidebar {
let chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(SIDEBAR_WIDTH),
Constraint::Min(0),
])
.split(main_content_area);
(Some(chunks[0]), chunks[1])
} else {
(None, main_content_area)
}
}
pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme, profile_tree: &ProfileTreeResponse) {
let sidebar_block = Block::default()
.style(Style::default().bg(theme.bg));
let items = vec![
ListItem::new(Text::from(" Navigation ")),
ListItem::new(Text::from(" Search ")),
ListItem::new(Text::from(" Settings ")),
];
let mut items = Vec::new();
for profile in &profile_tree.profiles {
// Profile header
items.push(ListItem::new(Line::from(vec![
Span::styled("📁 ", Style::default().fg(theme.accent)),
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
])));
// Profile tables
for (table_idx, table) in profile.tables.iter().enumerate() {
let is_last_table = table_idx == profile.tables.len() - 1;
let tree_prefix = if is_last_table { "└─ " } else { "├─ " };
// Table name
items.push(ListItem::new(Line::from(vec![
Span::styled(format!(" {}", tree_prefix), Style::default().fg(theme.fg)),
Span::styled(&table.name, Style::default().fg(theme.fg)),
])));
// Dependencies
if !table.depends_on.is_empty() {
let dep_prefix = if is_last_table { " " } else { "" };
let deps = table.depends_on.join(", ");
items.push(ListItem::new(Line::from(vec![
Span::styled(format!(" {} └─ ", dep_prefix), Style::default().fg(theme.secondary)),
Span::styled(format!("{}", deps), Style::default().fg(theme.secondary)),
])));
}
}
}
let list = List::new(items)
.block(sidebar_block)

View File

@@ -1,6 +1,5 @@
// src/modes/handlers/event.rs
use crossterm::event::Event;
use crossterm::event::{Event, KeyCode};
use crossterm::cursor::SetCursorStyle;
use crate::tui::terminal::{
core::TerminalCore,
@@ -48,21 +47,41 @@ impl EventHandler {
app_state: &mut crate::state::state::AppState,
total_count: u64,
current_position: &mut u64,
intro_state: &mut crate::components::handlers::intro::IntroState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
if app_state.ui.show_intro {
if let Event::Key(key) = event {
match key.code {
KeyCode::Left => intro_state.previous_option(),
KeyCode::Right => intro_state.next_option(),
KeyCode::Enter => {
if intro_state.selected_option == 0 {
app_state.ui.show_intro = false;
} else {
self.command_message = "Admin panel coming soon".to_string();
}
return Ok((false, String::new()));
}
_ => {}
}
}
return Ok((false, String::new()));
}
if let Event::Key(key) = event {
let key_code = key.code;
let modifiers = key.modifiers;
if UiStateHandler::toggle_sidebar(
&mut app_state.ui,
config,
key_code,
modifiers,
) {
return Ok((false, format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)));
}
if UiStateHandler::toggle_sidebar(
&mut app_state.ui,
config,
key_code,
modifiers,
) {
return Ok((false, format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)));
}
if let Some(action) = config.get_action_for_key_in_mode(
&config.keybindings.common,
@@ -74,7 +93,7 @@ impl EventHandler {
let message = common::save(
form_state,
grpc_client,
&mut app_state.is_saved,
&mut app_state.ui.is_saved,
current_position,
total_count,
).await?;
@@ -109,7 +128,7 @@ impl EventHandler {
&mut self.command_input,
&mut self.command_message,
grpc_client,
&mut app_state.is_saved,
&mut app_state.ui.is_saved,
current_position,
total_count,
).await?;
@@ -146,7 +165,7 @@ impl EventHandler {
form_state,
&mut self.ideal_cursor_column,
&mut self.command_message,
&mut app_state.is_saved,
&mut app_state.ui.is_saved,
current_position,
total_count,
grpc_client,

View File

@@ -1,19 +1,20 @@
// src/client/ui/handlers/state.rs
use std::env;
use common::proto::multieko2::table_definition::ProfileTreeResponse;
#[derive(Default)]
pub struct UiState {
pub show_sidebar: bool,
// Add other UI-related states here
pub is_saved: bool,
pub show_intro: bool,
}
pub struct AppState {
// Core editor state
pub is_saved: bool,
pub current_dir: String,
pub total_count: u64,
pub current_position: u64,
pub profile_tree: ProfileTreeResponse,
// UI preferences
pub ui: UiState,
@@ -25,10 +26,10 @@ impl AppState {
.to_string_lossy()
.to_string();
Ok(AppState {
is_saved: false,
current_dir,
total_count: 0,
current_position: 0,
profile_tree: ProfileTreeResponse::default(),
ui: UiState::default(),
})
}
@@ -42,3 +43,13 @@ impl AppState {
self.current_position = current_position;
}
}
impl Default for UiState {
fn default() -> Self {
Self {
show_sidebar: true,
is_saved: false,
show_intro: true,
}
}
}

View File

@@ -1 +0,0 @@
cat src/modes/handlers/event.rs src/state/state.rs src/ui/handlers.rs src/ui/handlers/render.rs src/ui/handlers/ui.rs src/components/handlers.rs

View File

@@ -6,17 +6,28 @@ use common::proto::multieko2::adresar::{AdresarResponse, PostAdresarRequest, Put
use common::proto::multieko2::common::{CountResponse, PositionRequest, Empty};
use common::proto::multieko2::table_structure::table_structure_service_client::TableStructureServiceClient;
use common::proto::multieko2::table_structure::TableStructureResponse;
use common::proto::multieko2::table_definition::{
table_definition_client::TableDefinitionClient,
ProfileTreeResponse
};
pub struct GrpcClient {
adresar_client: AdresarClient<Channel>,
table_structure_client: TableStructureServiceClient<Channel>,
table_definition_client: TableDefinitionClient<Channel>,
}
impl GrpcClient {
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
let table_structure_client = TableStructureServiceClient::connect("http://[::1]:50051").await?;
Ok(Self { adresar_client, table_structure_client })
let table_definition_client = TableDefinitionClient::connect("http://[::1]:50051").await?;
Ok(Self {
adresar_client,
table_structure_client,
table_definition_client,
})
}
pub async fn get_adresar_count(&mut self) -> Result<u64, Box<dyn std::error::Error>> {
@@ -48,4 +59,10 @@ impl GrpcClient {
let response = self.table_structure_client.get_adresar_table_structure(request).await?;
Ok(response.into_inner())
}
pub async fn get_profile_tree(&mut self) -> Result<ProfileTreeResponse, Box<dyn std::error::Error>> {
let request = tonic::Request::new(Empty::default());
let response = self.table_definition_client.get_profile_tree(request).await?;
Ok(response.into_inner())
}
}

View File

@@ -1,11 +1,15 @@
// src/ui/handlers/render.rs
use crate::components::{render_command_line, render_preview_card, render_status_line};
use crate::components::{
render_background,
render_command_line,
render_status_line,
handlers::{sidebar::{self, calculate_sidebar_layout}, intro},
};
use crate::config::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
use super::form::FormState;
use crate::state::state::UiState;
use crate::state::state::AppState;
pub fn render_ui(
f: &mut Frame,
@@ -18,84 +22,62 @@ pub fn render_ui(
command_input: &str,
command_mode: bool,
command_message: &str,
ui_state: &UiState,
app_state: &AppState,
intro_state: &intro::IntroState,
) {
// Root layout - vertical split for main content, status, and command line
render_background(f, f.area(), theme);
if app_state.ui.show_intro {
intro_state.render(f, f.area(), theme);
return;
}
let root = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(10), // Main content area
Constraint::Length(1), // Status line
Constraint::Length(1), // Command line
Constraint::Min(10),
Constraint::Length(1),
Constraint::Length(1),
])
.split(f.area());
// Main content area layout
let main_content_area = root[0];
// Split into sidebar + content or just content
let (sidebar_area, content_area) = if ui_state.show_sidebar {
let chunks = Layout::default()
let (sidebar_area, form_area) = calculate_sidebar_layout(app_state.ui.show_sidebar, main_content_area);
let available_width = form_area.width;
let form_constraint = if available_width >= 80 {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(16), // Fixed sidebar width
Constraint::Fill(1), // Remaining space for form/preview
Constraint::Min(0),
Constraint::Length(80),
Constraint::Min(0),
])
.split(main_content_area);
(Some(chunks[0]), chunks[1])
.split(main_content_area)[1]
} else {
(None, main_content_area)
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(80.min(available_width)),
Constraint::Min(0),
])
.split(form_area)[1]
};
// Split content area into form and preview
let content_chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(60),
Constraint::Percentage(40),
])
.split(content_area);
// Render form in the left content area
form_state.render(
f,
content_chunks[0],
form_constraint,
theme,
is_edit_mode,
total_count,
current_position,
);
// Render preview card in the right content area
let preview_values: Vec<&String> = form_state.values.iter().collect();
render_preview_card(
f,
content_chunks[1],
&preview_values,
theme,
);
// Render sidebar if enabled
if let Some(sidebar_rect) = sidebar_area {
crate::components::handlers::sidebar::render_sidebar(f, sidebar_rect, theme);
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
}
// Status line
render_status_line(
f,
root[1],
current_dir,
theme,
is_edit_mode,
);
// Command line
render_command_line(
f,
root[2],
command_input,
command_mode,
theme,
command_message,
);
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
}

View File

@@ -9,18 +9,19 @@ use crate::config::config::Config;
use crate::ui::handlers::{form::FormState, render::render_ui};
use crate::modes::handlers::event::EventHandler;
use crate::state::state::AppState;
use crate::components::handlers::intro::IntroState;
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let mut terminal = TerminalCore::new()?; // Remove .await
let mut terminal = TerminalCore::new()?;
let mut grpc_client = GrpcClient::new().await?;
let mut command_handler = CommandHandler::new();
let theme = Theme::from_str(&config.colors.theme);
let mut intro_state = IntroState::new();
// Fetch table structure at startup (one-time)
// TODO: Later, consider implementing a live update for table structure changes.
let table_structure = grpc_client.get_table_structure().await?; // Changed
let table_structure = grpc_client.get_table_structure().await?;
// Extract the column names from the response
let column_names: Vec<String> = table_structure
@@ -32,10 +33,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
// Initialize FormState with dynamic fields
let mut form_state = FormState::new(column_names);
// Fetch profile tree and table structure
let profile_tree = grpc_client.get_profile_tree().await?;
// The rest of your UI initialization remains the same
let mut event_handler = EventHandler::new();
let event_reader = EventReader::new();
let mut app_state = AppState::new()?;
app_state.profile_tree = profile_tree;
// Fetch the total count of Adresar entries
let total_count = grpc_client.get_adresar_count().await?;
@@ -59,7 +63,8 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
&app_state.ui,
&app_state,
&intro_state,
);
})?;
@@ -77,6 +82,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&mut app_state,
total_count,
&mut current_position,
&mut intro_state,
).await?;
app_state.current_position = current_position;