Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44c5963c71 | ||
|
|
911dba9bce | ||
|
|
d55dff8a3e | ||
|
|
8b2120bdc8 | ||
|
|
8ce90f3c42 | ||
|
|
62d7fb6bda | ||
|
|
27cca8763b | ||
|
|
74054f2724 |
@@ -1,14 +1,14 @@
|
|||||||
// src/components/handlers.rs
|
// src/components/handlers.rs
|
||||||
pub mod form;
|
pub mod form;
|
||||||
pub mod preview_card;
|
|
||||||
pub mod command_line;
|
pub mod command_line;
|
||||||
pub mod status_line;
|
pub mod status_line;
|
||||||
pub mod canvas;
|
pub mod canvas;
|
||||||
pub mod sidebar;
|
pub mod sidebar;
|
||||||
|
pub mod background;
|
||||||
|
|
||||||
pub use command_line::render_command_line;
|
pub use command_line::render_command_line;
|
||||||
pub use form::*;
|
pub use form::*;
|
||||||
pub use preview_card::render_preview_card;
|
|
||||||
pub use status_line::render_status_line;
|
pub use status_line::render_status_line;
|
||||||
pub use canvas::*;
|
pub use canvas::*;
|
||||||
pub use sidebar::*;
|
pub use sidebar::*;
|
||||||
|
pub use background::*;
|
||||||
|
|||||||
15
client/src/components/handlers/background.rs
Normal file
15
client/src/components/handlers/background.rs
Normal 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);
|
||||||
|
}
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,67 @@
|
|||||||
// src/components/handlers/sidebar.rs
|
// src/components/handlers/sidebar.rs
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
widgets::{Block, List, ListItem},
|
widgets::{Block, List, ListItem},
|
||||||
layout::Rect,
|
layout::{Rect, Direction, Layout, Constraint},
|
||||||
style::Style,
|
style::Style,
|
||||||
text::Text,
|
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::config::colors::Theme;
|
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()
|
let sidebar_block = Block::default()
|
||||||
.style(Style::default().bg(theme.bg));
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
let items = vec![
|
let mut items = Vec::new();
|
||||||
ListItem::new(Text::from(" Navigation ")),
|
|
||||||
ListItem::new(Text::from(" Search ")),
|
for profile in &profile_tree.profiles {
|
||||||
ListItem::new(Text::from(" Settings ")),
|
// 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)
|
let list = List::new(items)
|
||||||
.block(sidebar_block)
|
.block(sidebar_block)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
// src/client/ui/handlers/state.rs
|
// src/client/ui/handlers/state.rs
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub show_sidebar: bool,
|
pub show_sidebar: bool,
|
||||||
// Add other UI-related states here
|
pub profile_tree: ProfileTreeResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
@@ -42,3 +42,12 @@ impl AppState {
|
|||||||
self.current_position = current_position;
|
self.current_position = current_position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for UiState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
show_sidebar: true,
|
||||||
|
profile_tree: ProfileTreeResponse::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -6,17 +6,28 @@ use common::proto::multieko2::adresar::{AdresarResponse, PostAdresarRequest, Put
|
|||||||
use common::proto::multieko2::common::{CountResponse, PositionRequest, Empty};
|
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::table_structure_service_client::TableStructureServiceClient;
|
||||||
use common::proto::multieko2::table_structure::TableStructureResponse;
|
use common::proto::multieko2::table_structure::TableStructureResponse;
|
||||||
|
use common::proto::multieko2::table_definition::{
|
||||||
|
table_definition_client::TableDefinitionClient,
|
||||||
|
ProfileTreeResponse
|
||||||
|
};
|
||||||
|
|
||||||
pub struct GrpcClient {
|
pub struct GrpcClient {
|
||||||
adresar_client: AdresarClient<Channel>,
|
adresar_client: AdresarClient<Channel>,
|
||||||
table_structure_client: TableStructureServiceClient<Channel>,
|
table_structure_client: TableStructureServiceClient<Channel>,
|
||||||
|
table_definition_client: TableDefinitionClient<Channel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GrpcClient {
|
impl GrpcClient {
|
||||||
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
||||||
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
|
let adresar_client = AdresarClient::connect("http://[::1]:50051").await?;
|
||||||
let table_structure_client = TableStructureServiceClient::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>> {
|
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?;
|
let response = self.table_structure_client.get_adresar_table_structure(request).await?;
|
||||||
Ok(response.into_inner())
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
// src/ui/handlers/render.rs
|
// src/ui/handlers/render.rs
|
||||||
|
use crate::components::{
|
||||||
use crate::components::{render_command_line, render_preview_card, render_status_line};
|
render_background,
|
||||||
|
render_command_line,
|
||||||
|
render_status_line,
|
||||||
|
handlers::sidebar::{self, calculate_sidebar_layout}
|
||||||
|
};
|
||||||
use crate::config::colors::Theme;
|
use crate::config::colors::Theme;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout};
|
use ratatui::layout::{Constraint, Direction, Layout};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
@@ -20,82 +24,54 @@ pub fn render_ui(
|
|||||||
command_message: &str,
|
command_message: &str,
|
||||||
ui_state: &UiState,
|
ui_state: &UiState,
|
||||||
) {
|
) {
|
||||||
// Root layout - vertical split for main content, status, and command line
|
render_background(f, f.area(), theme);
|
||||||
|
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Min(10), // Main content area
|
Constraint::Min(10),
|
||||||
Constraint::Length(1), // Status line
|
Constraint::Length(1),
|
||||||
Constraint::Length(1), // Command line
|
Constraint::Length(1),
|
||||||
])
|
])
|
||||||
.split(f.area());
|
.split(f.area());
|
||||||
|
|
||||||
// Main content area layout
|
|
||||||
let main_content_area = root[0];
|
let main_content_area = root[0];
|
||||||
|
let (sidebar_area, form_area) = calculate_sidebar_layout(ui_state.show_sidebar, main_content_area);
|
||||||
// Split into sidebar + content or just content
|
let available_width = form_area.width;
|
||||||
let (sidebar_area, content_area) = if ui_state.show_sidebar {
|
|
||||||
let chunks = Layout::default()
|
let form_constraint = if available_width >= 80 {
|
||||||
|
Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(16), // Fixed sidebar width
|
Constraint::Min(0),
|
||||||
Constraint::Fill(1), // Remaining space for form/preview
|
Constraint::Length(80),
|
||||||
|
Constraint::Min(0),
|
||||||
])
|
])
|
||||||
.split(main_content_area);
|
.split(main_content_area)[1]
|
||||||
(Some(chunks[0]), chunks[1])
|
|
||||||
} else {
|
} 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(
|
form_state.render(
|
||||||
f,
|
f,
|
||||||
content_chunks[0],
|
form_constraint,
|
||||||
theme,
|
theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
total_count,
|
total_count,
|
||||||
current_position,
|
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 {
|
if let Some(sidebar_rect) = sidebar_area {
|
||||||
crate::components::handlers::sidebar::render_sidebar(f, sidebar_rect, theme);
|
sidebar::render_sidebar(f, sidebar_rect, theme, &ui_state.profile_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status line
|
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
||||||
render_status_line(
|
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
|
||||||
f,
|
|
||||||
root[1],
|
|
||||||
current_dir,
|
|
||||||
theme,
|
|
||||||
is_edit_mode,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Command line
|
|
||||||
render_command_line(
|
|
||||||
f,
|
|
||||||
root[2],
|
|
||||||
command_input,
|
|
||||||
command_mode,
|
|
||||||
theme,
|
|
||||||
command_message,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ use crate::state::state::AppState;
|
|||||||
|
|
||||||
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let config = Config::load()?;
|
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 grpc_client = GrpcClient::new().await?;
|
||||||
let mut command_handler = CommandHandler::new();
|
let mut command_handler = CommandHandler::new();
|
||||||
let theme = Theme::from_str(&config.colors.theme);
|
let theme = Theme::from_str(&config.colors.theme);
|
||||||
|
|
||||||
// Fetch table structure at startup (one-time)
|
// Fetch table structure at startup (one-time)
|
||||||
// TODO: Later, consider implementing a live update for table structure changes.
|
// 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
|
// Extract the column names from the response
|
||||||
let column_names: Vec<String> = table_structure
|
let column_names: Vec<String> = table_structure
|
||||||
@@ -32,10 +32,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Initialize FormState with dynamic fields
|
// Initialize FormState with dynamic fields
|
||||||
let mut form_state = FormState::new(column_names);
|
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
|
// The rest of your UI initialization remains the same
|
||||||
let mut event_handler = EventHandler::new();
|
let mut event_handler = EventHandler::new();
|
||||||
let event_reader = EventReader::new();
|
let event_reader = EventReader::new();
|
||||||
let mut app_state = AppState::new()?;
|
let mut app_state = AppState::new()?;
|
||||||
|
app_state.ui.profile_tree = profile_tree;
|
||||||
|
|
||||||
// Fetch the total count of Adresar entries
|
// Fetch the total count of Adresar entries
|
||||||
let total_count = grpc_client.get_adresar_count().await?;
|
let total_count = grpc_client.get_adresar_count().await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user