Compare commits

...

12 Commits

Author SHA1 Message Date
filipriec
8da29376ab moved key sequences also 2025-03-22 23:03:13 +01:00
filipriec
8ad5fedcea config was moved successfully 2025-03-22 22:58:58 +01:00
filipriec
16a7fa0bcc working change of the themes 2025-03-22 22:55:43 +01:00
filipriec
5f6858251c moved themes out of the config 2025-03-22 22:51:53 +01:00
filipriec
73567ae5cf moved everything up 2025-03-22 22:40:38 +01:00
filipriec
fe2d1e4684 working perfectly well, needs bug fixes to proper shortcuts to proper windows 2025-03-22 20:10:39 +01:00
filipriec
7d4b043d63 still one error missing 2025-03-22 20:05:13 +01:00
filipriec
04b4220c76 needs bug fixing 2025-03-22 19:37:41 +01:00
filipriec
841418759b last changes 2025-03-22 16:26:38 +01:00
filipriec
ccd76eabdd components are redesigned 2025-03-22 15:45:55 +01:00
filipriec
fabe1e0ca7 changing components infrastructure 2025-03-22 15:36:49 +01:00
filipriec
9bf1d065d5 restored functionality 2025-03-22 15:11:08 +01:00
30 changed files with 342 additions and 197 deletions

View File

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

View File

@@ -0,0 +1,118 @@
// src/components/admin/admin_panel.rs
use ratatui::{
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
style::Style,
text::{Line, Span, Text},
layout::{Alignment, Constraint, Direction, Layout, Rect},
Frame,
};
use common::proto::multieko2::table_definition::ProfileTreeResponse;
use crate::config::colors::themes::Theme;
pub struct AdminPanelState {
pub list_state: ListState,
pub profiles: Vec<String>,
}
impl AdminPanelState {
pub fn new(profiles: Vec<String>) -> Self {
let mut list_state = ListState::default();
if !profiles.is_empty() {
list_state.select(Some(0));
}
Self { list_state, profiles }
}
pub fn next(&mut self) {
let i = self.list_state.selected().map_or(0, |i|
if i >= self.profiles.len() - 1 { 0 } else { i + 1 });
self.list_state.select(Some(i));
}
pub fn previous(&mut self) {
let i = self.list_state.selected().map_or(0, |i|
if i == 0 { self.profiles.len() - 1 } else { i - 1 });
self.list_state.select(Some(i));
}
pub fn render(
&mut self,
f: &mut Frame,
area: Rect,
theme: &Theme,
profile_tree: &ProfileTreeResponse,
selected_profile: &Option<String>,
) {
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);
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Length(3), Constraint::Min(1)])
.split(inner_area);
// Title
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
f.render_widget(title_widget, chunks[0]);
// Content
let content_chunks = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
.split(chunks[1]);
// Profile list
let items: Vec<ListItem> = self.profiles.iter()
.map(|p| ListItem::new(Line::from(vec![
Span::styled(
if Some(p) == selected_profile.as_ref() { "" } else { " " },
Style::default().fg(theme.accent)
),
Span::styled(p, Style::default().fg(theme.fg)),
])))
.collect();
let list = List::new(items)
.block(Block::default().title("Profiles"))
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
f.render_stateful_widget(list, content_chunks[0], &mut self.list_state);
// Profile details
if let Some(profile) = self.list_state.selected()
.and_then(|i| profile_tree.profiles.get(i))
{
let mut text = Text::default();
text.lines.push(Line::from(vec![
Span::styled("Profile: ", Style::default().fg(theme.accent)),
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
]));
text.lines.push(Line::from(""));
text.lines.push(Line::from(Span::styled("Tables:", Style::default().fg(theme.accent))));
for table in &profile.tables {
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
if !table.depends_on.is_empty() {
line.push(Span::styled(
format!("{}", table.depends_on.join(", ")),
Style::default().fg(theme.secondary)
));
}
text.lines.push(Line::from(line));
}
let details_widget = Paragraph::new(text)
.block(Block::default().title("Details"));
f.render_widget(details_widget, content_chunks[1]);
}
}
}

View File

@@ -0,0 +1,8 @@
// src/components/common.rs
pub mod command_line;
pub mod status_line;
pub mod background;
pub use command_line::*;
pub use status_line::*;
pub use background::*;

View File

@@ -5,7 +5,7 @@ use ratatui::{
style::Style, style::Style,
Frame, Frame,
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
pub fn render_background(f: &mut Frame, area: Rect, theme: &Theme) { pub fn render_background(f: &mut Frame, area: Rect, theme: &Theme) {
let background = Block::default() let background = Block::default()

View File

@@ -5,7 +5,7 @@ use ratatui::{
layout::Rect, layout::Rect,
Frame, Frame,
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme, message: &str) { pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme, message: &str) {
let prompt = if active { let prompt = if active {

View File

@@ -6,7 +6,7 @@ use ratatui::{
Frame, Frame,
text::{Line, Span}, text::{Line, Span},
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
use std::path::Path; use std::path::Path;
pub fn render_status_line( pub fn render_status_line(

View File

@@ -1,18 +1,8 @@
// src/components/handlers.rs // src/components/handlers.rs
pub mod form; pub mod form;
pub mod command_line;
pub mod status_line;
pub mod canvas; pub mod canvas;
pub mod sidebar; pub mod sidebar;
pub mod background;
pub mod intro;
pub mod admin_panel;
pub use command_line::render_command_line;
pub use form::*; pub use form::*;
pub use status_line::render_status_line;
pub use canvas::*; pub use canvas::*;
pub use sidebar::*; pub use sidebar::*;
pub use background::*;
pub use intro::*;
pub use admin_panel::*;

View File

@@ -1,44 +0,0 @@
// src/components/handlers/admin_panel.rs
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::Style,
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
Frame,
};
use crate::config::colors::Theme;
pub struct AdminPanelState;
impl AdminPanelState {
pub fn new() -> Self {
Self
}
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);
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3), // Title
Constraint::Min(1), // Content
])
.split(inner_area);
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
let title_para = Paragraph::new(title)
.alignment(Alignment::Center);
f.render_widget(title_para, chunks[0]);
let content = Paragraph::new("Admin panel content goes here");
f.render_widget(content, chunks[1]);
}
}

View File

@@ -7,7 +7,7 @@ use ratatui::{
Frame, Frame,
prelude::Alignment, prelude::Alignment,
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
use crate::ui::form::FormState; use crate::ui::form::FormState;
pub fn render_canvas( pub fn render_canvas(

View File

@@ -5,7 +5,7 @@ use ratatui::{
style::Style, style::Style,
Frame, Frame,
}; };
use crate::config::colors::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 super::canvas::render_canvas; // Changed to canvas

View File

@@ -5,7 +5,7 @@ use ratatui::{
style::Style, style::Style,
Frame, Frame,
}; };
use crate::config::colors::Theme; 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};
@@ -26,41 +26,51 @@ pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) ->
} }
} }
pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme, profile_tree: &ProfileTreeResponse) { pub fn render_sidebar(
let sidebar_block = Block::default() f: &mut Frame,
.style(Style::default().bg(theme.bg)); area: Rect,
theme: &Theme,
profile_tree: &ProfileTreeResponse,
selected_profile: &Option<String>,
) {
let sidebar_block = Block::default().style(Style::default().bg(theme.bg));
let mut items = Vec::new(); let mut items = Vec::new();
for profile in &profile_tree.profiles { if let Some(profile_name) = selected_profile {
// Profile header if let Some(profile) = profile_tree.profiles.iter()
items.push(ListItem::new(Line::from(vec![ .find(|p| &p.name == profile_name)
Span::styled("📁 ", Style::default().fg(theme.accent)), {
Span::styled(&profile.name, Style::default().fg(theme.highlight)), // Profile header
])));
// 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![ items.push(ListItem::new(Line::from(vec![
Span::styled(format!(" {}", tree_prefix), Style::default().fg(theme.fg)), Span::styled("📁 ", Style::default().fg(theme.accent)),
Span::styled(&table.name, Style::default().fg(theme.fg)), Span::styled(&profile.name, Style::default().fg(theme.highlight)),
]))); ])));
// Dependencies // Tables
if !table.depends_on.is_empty() { for (table_idx, table) in profile.tables.iter().enumerate() {
let dep_prefix = if is_last_table { " " } else { "" }; let is_last = table_idx == profile.tables.len() - 1;
let deps = table.depends_on.join(", "); let prefix = if is_last { "└─ " } else { "├─ " };
items.push(ListItem::new(Line::from(vec![ let mut line = vec![
Span::styled(format!(" {} └─ ", dep_prefix), Style::default().fg(theme.secondary)), Span::styled(format!(" {}", prefix), Style::default().fg(theme.fg)),
Span::styled(format!("{}", deps), Style::default().fg(theme.secondary)), Span::styled(&table.name, Style::default().fg(theme.fg)),
]))); ];
if !table.depends_on.is_empty() {
line.push(Span::styled(
format!("{}", table.depends_on.join(", ")),
Style::default().fg(theme.secondary)
));
}
items.push(ListItem::new(Line::from(line)));
} }
} }
} 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)

View File

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

View File

@@ -7,7 +7,7 @@ use ratatui::{
prelude::Margin, prelude::Margin,
Frame, Frame,
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
pub struct IntroState { pub struct IntroState {
pub selected_option: usize, pub selected_option: usize,

View File

@@ -1,5 +1,10 @@
// src/components/mod.rs // src/components/mod.rs
pub mod models;
pub mod handlers; pub mod handlers;
pub mod intro;
pub mod admin;
pub mod common;
pub use handlers::*; pub use handlers::*;
pub use intro::*;
pub use admin::*;
pub use common::*;

View File

@@ -0,0 +1,7 @@
// src/config/binds.rs
pub mod config;
pub mod key_sequences;
pub use config::*;
pub use key_sequences::*;

View File

@@ -355,13 +355,13 @@ impl Config {
// Get string representations of the sequence // Get string representations of the sequence
let sequence_str = sequence.iter() let sequence_str = sequence.iter()
.map(|k| crate::config::key_sequences::key_to_string(k)) .map(|k| crate::config::binds::key_sequences::key_to_string(k))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(""); .join("");
// Add the missing sequence_plus definition // Add the missing sequence_plus definition
let sequence_plus = sequence.iter() let sequence_plus = sequence.iter()
.map(|k| crate::config::key_sequences::key_to_string(k)) .map(|k| crate::config::binds::key_sequences::key_to_string(k))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("+"); .join("+");
@@ -414,7 +414,7 @@ impl Config {
// Special case for + format in bindings // Special case for + format in bindings
if binding.contains('+') { if binding.contains('+') {
let normalized_sequence = sequence.iter() let normalized_sequence = sequence.iter()
.map(|k| crate::config::key_sequences::key_to_string(k)) .map(|k| crate::config::binds::key_sequences::key_to_string(k))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
let binding_parts: Vec<&str> = binding.split('+').collect(); let binding_parts: Vec<&str> = binding.split('+').collect();
@@ -442,7 +442,7 @@ impl Config {
// Get string representation of the sequence // Get string representation of the sequence
let sequence_str = sequence.iter() let sequence_str = sequence.iter()
.map(|k| crate::config::key_sequences::key_to_string(k)) .map(|k| crate::config::binds::key_sequences::key_to_string(k))
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(""); .join("");
@@ -491,7 +491,7 @@ impl Config {
if binding.contains('+') { if binding.contains('+') {
let binding_parts: Vec<&str> = binding.split('+').collect(); let binding_parts: Vec<&str> = binding.split('+').collect();
let sequence_parts = sequence.iter() let sequence_parts = sequence.iter()
.map(|k| crate::config::key_sequences::key_to_string(k)) .map(|k| crate::config::binds::key_sequences::key_to_string(k))
.collect::<Vec<String>>(); .collect::<Vec<String>>();
if binding_parts.len() > sequence_parts.len() { if binding_parts.len() > sequence_parts.len() {

View File

@@ -1,68 +1,4 @@
// src/client/colors.rs // src/config/colors.rs
use ratatui::style::Color; pub mod themes;
#[derive(Debug, Clone)] pub use themes::*;
pub struct Theme {
pub bg: Color,
pub fg: Color,
pub accent: Color,
pub secondary: Color,
pub highlight: Color,
pub warning: Color,
pub border: Color,
}
impl Theme {
pub fn from_str(theme_name: &str) -> Self {
match theme_name.to_lowercase().as_str() {
"dark" => Self::dark(),
"high_contrast" => Self::high_contrast(),
_ => Self::light(),
}
}
// Default light theme
pub fn light() -> Self {
Self {
bg: Color::Rgb(245, 245, 245), // Light gray
fg: Color::Rgb(64, 64, 64), // Dark gray
accent: Color::Rgb(173, 216, 230), // Pastel blue
secondary: Color::Rgb(255, 165, 0), // Orange for secondary
highlight: Color::Rgb(152, 251, 152), // Pastel green
warning: Color::Rgb(255, 182, 193), // Pastel pink
border: Color::Rgb(220, 220, 220), // Light gray border
}
}
// High-contrast dark theme
pub fn dark() -> Self {
Self {
bg: Color::Rgb(30, 30, 30), // Dark background
fg: Color::Rgb(255, 255, 255), // White text
accent: Color::Rgb(0, 191, 255), // Bright blue
secondary: Color::Rgb(255, 215, 0), // Gold for secondary
highlight: Color::Rgb(50, 205, 50), // Bright green
warning: Color::Rgb(255, 99, 71), // Bright red
border: Color::Rgb(100, 100, 100), // Medium gray border
}
}
// High-contrast light theme
pub fn high_contrast() -> Self {
Self {
bg: Color::Rgb(255, 255, 255), // White background
fg: Color::Rgb(0, 0, 0), // Black text
accent: Color::Rgb(0, 0, 255), // Blue
secondary: Color::Rgb(255, 140, 0), // Dark orange for secondary
highlight: Color::Rgb(0, 128, 0), // Green
warning: Color::Rgb(255, 0, 0), // Red
border: Color::Rgb(0, 0, 0), // Black border
}
}
}
impl Default for Theme {
fn default() -> Self {
Self::light() // Default to light theme
}
}

View File

@@ -0,0 +1,68 @@
// src/client/themes/colors.rs
use ratatui::style::Color;
#[derive(Debug, Clone)]
pub struct Theme {
pub bg: Color,
pub fg: Color,
pub accent: Color,
pub secondary: Color,
pub highlight: Color,
pub warning: Color,
pub border: Color,
}
impl Theme {
pub fn from_str(theme_name: &str) -> Self {
match theme_name.to_lowercase().as_str() {
"dark" => Self::dark(),
"high_contrast" => Self::high_contrast(),
_ => Self::light(),
}
}
// Default light theme
pub fn light() -> Self {
Self {
bg: Color::Rgb(245, 245, 245), // Light gray
fg: Color::Rgb(64, 64, 64), // Dark gray
accent: Color::Rgb(173, 216, 230), // Pastel blue
secondary: Color::Rgb(255, 165, 0), // Orange for secondary
highlight: Color::Rgb(152, 251, 152), // Pastel green
warning: Color::Rgb(255, 182, 193), // Pastel pink
border: Color::Rgb(220, 220, 220), // Light gray border
}
}
// High-contrast dark theme
pub fn dark() -> Self {
Self {
bg: Color::Rgb(30, 30, 30), // Dark background
fg: Color::Rgb(255, 255, 255), // White text
accent: Color::Rgb(0, 191, 255), // Bright blue
secondary: Color::Rgb(255, 215, 0), // Gold for secondary
highlight: Color::Rgb(50, 205, 50), // Bright green
warning: Color::Rgb(255, 99, 71), // Bright red
border: Color::Rgb(100, 100, 100), // Medium gray border
}
}
// High-contrast light theme
pub fn high_contrast() -> Self {
Self {
bg: Color::Rgb(255, 255, 255), // White background
fg: Color::Rgb(0, 0, 0), // Black text
accent: Color::Rgb(0, 0, 255), // Blue
secondary: Color::Rgb(255, 140, 0), // Dark orange for secondary
highlight: Color::Rgb(0, 128, 0), // Green
warning: Color::Rgb(255, 0, 0), // Red
border: Color::Rgb(0, 0, 0), // Black border
}
}
}
impl Default for Theme {
fn default() -> Self {
Self::light() // Default to light theme
}
}

View File

@@ -1,4 +1,4 @@
// src/config/mod.rs // src/config/mod.rs
pub mod binds;
pub mod colors; pub mod colors;
pub mod config;
pub mod key_sequences;

View File

@@ -2,7 +2,7 @@
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers}; use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::grpc_client::GrpcClient; use crate::tui::terminal::grpc_client::GrpcClient;
use crate::config::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use super::common; use super::common;

View File

@@ -4,7 +4,7 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::tui::terminal::{ use crate::tui::terminal::{
grpc_client::GrpcClient, grpc_client::GrpcClient,
}; };
use crate::config::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use super::common; use super::common;

View File

@@ -6,11 +6,11 @@ use crate::tui::terminal::{
grpc_client::GrpcClient, grpc_client::GrpcClient,
commands::CommandHandler, commands::CommandHandler,
}; };
use crate::config::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;
use crate::modes::handlers::{edit, command_mode, read_only}; use crate::modes::handlers::{edit, command_mode, read_only};
use crate::config::key_sequences::KeySequenceTracker; use crate::config::binds::key_sequences::KeySequenceTracker;
use super::common; use super::common;
pub struct EventHandler { pub struct EventHandler {
@@ -47,7 +47,7 @@ impl EventHandler {
app_state: &mut crate::state::state::AppState, app_state: &mut crate::state::state::AppState,
total_count: u64, total_count: u64,
current_position: &mut u64, current_position: &mut u64,
intro_state: &mut crate::components::handlers::intro::IntroState, intro_state: &mut crate::components::intro::intro::IntroState,
) -> Result<(bool, String), Box<dyn std::error::Error>> { ) -> Result<(bool, String), Box<dyn std::error::Error>> {
if app_state.ui.show_intro { if app_state.ui.show_intro {
if let Event::Key(key) = event { if let Event::Key(key) = event {

View File

@@ -1,9 +1,9 @@
// src/modes/handlers/read_only.rs // src/modes/handlers/read_only.rs
use crossterm::event::{KeyEvent}; use crossterm::event::{KeyEvent};
use crate::config::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::form::FormState; use crate::ui::handlers::form::FormState;
use crate::config::key_sequences::KeySequenceTracker; use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::tui::terminal::grpc_client::GrpcClient; use crate::tui::terminal::grpc_client::GrpcClient;
#[derive(PartialEq)] #[derive(PartialEq)]

View File

@@ -16,6 +16,7 @@ pub struct AppState {
pub total_count: u64, pub total_count: u64,
pub current_position: u64, pub current_position: u64,
pub profile_tree: ProfileTreeResponse, pub profile_tree: ProfileTreeResponse,
pub selected_profile: Option<String>,
// UI preferences // UI preferences
pub ui: UiState, pub ui: UiState,
@@ -31,6 +32,7 @@ impl AppState {
total_count: 0, total_count: 0,
current_position: 0, current_position: 0,
profile_tree: ProfileTreeResponse::default(), profile_tree: ProfileTreeResponse::default(),
selected_profile: None,
ui: UiState::default(), ui: UiState::default(),
}) })
} }

View File

@@ -1,5 +1,5 @@
// src/client/ui/handlers/form.rs // src/client/ui/handlers/form.rs
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
use ratatui::layout::Rect; use ratatui::layout::Rect;
use ratatui::Frame; use ratatui::Frame;

View File

@@ -1,6 +1,6 @@
// src/ui/handlers/rat_state.rs // src/ui/handlers/rat_state.rs
use crossterm::event::{KeyCode, KeyModifiers}; use crossterm::event::{KeyCode, KeyModifiers};
use crate::config::config::Config; use crate::config::binds::config::Config;
use crate::state::state::UiState; use crate::state::state::UiState;
pub struct UiStateHandler; pub struct UiStateHandler;

View File

@@ -4,9 +4,11 @@ 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}, intro, admin_panel::AdminPanelState, form::render_form}, handlers::{sidebar::{self, calculate_sidebar_layout}, form::render_form},
intro::{intro},
admin::{admin_panel::AdminPanelState},
}; };
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
use ratatui::layout::{Constraint, Direction, Layout}; use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame; use ratatui::Frame;
use super::form::FormState; use super::form::FormState;
@@ -25,7 +27,7 @@ pub fn render_ui(
command_message: &str, command_message: &str,
app_state: &AppState, app_state: &AppState,
intro_state: &intro::IntroState, intro_state: &intro::IntroState,
admin_panel_state: &AdminPanelState, admin_panel_state: &mut AdminPanelState,
) { ) {
render_background(f, f.area(), theme); render_background(f, f.area(), theme);
@@ -42,7 +44,13 @@ pub fn render_ui(
if app_state.ui.show_intro { if app_state.ui.show_intro {
intro_state.render(f, main_content_area, theme); intro_state.render(f, main_content_area, theme);
} else if app_state.ui.show_admin { } else if app_state.ui.show_admin {
admin_panel_state.render(f, main_content_area, theme); admin_panel_state.render(
f,
main_content_area,
theme,
&app_state.profile_tree,
&app_state.selected_profile,
);
} else { } else {
let (sidebar_area, form_area) = calculate_sidebar_layout( let (sidebar_area, form_area) = calculate_sidebar_layout(
app_state.ui.show_sidebar, app_state.ui.show_sidebar,
@@ -50,17 +58,38 @@ pub fn render_ui(
); );
if let Some(sidebar_rect) = sidebar_area { if let Some(sidebar_rect) = sidebar_area {
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree); sidebar::render_sidebar(
f,
sidebar_rect,
theme,
&app_state.profile_tree,
&app_state.selected_profile // Remove trailing comma
);
} }
let form_constraint = Layout::default() // This change makes the form stay stationary when toggling sidebar
.direction(Direction::Horizontal) let available_width = form_area.width;
.constraints([ let form_constraint = if available_width >= 80 {
Constraint::Min(0), // Use main_content_area for centering when enough space
Constraint::Length(80.min(form_area.width)), Layout::default()
Constraint::Min(0), .direction(Direction::Horizontal)
]) .constraints([
.split(form_area)[1]; Constraint::Min(0),
Constraint::Length(80),
Constraint::Min(0),
])
.split(main_content_area)[1]
} else {
// Use form_area (post sidebar) when limited space
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(80.min(available_width)),
Constraint::Min(0),
])
.split(form_area)[1]
};
// Convert fields to &[&str] and values to &[&String] // Convert fields to &[&str] and values to &[&String]
let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect(); let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect();

View File

@@ -1,15 +1,16 @@
// src/client/ui/handlers/ui.rs // src/ui/handlers/ui.rs
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::terminal::CommandHandler;
use crate::tui::terminal::EventReader; use crate::tui::terminal::EventReader;
use crate::config::colors::Theme; use crate::config::colors::themes::Theme;
use crate::config::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::{form::FormState, render::render_ui}; use crate::ui::handlers::{form::FormState, render::render_ui};
use crate::modes::handlers::event::EventHandler; use crate::modes::handlers::event::EventHandler;
use crate::state::state::AppState; use crate::state::state::AppState;
use crate::components::handlers::{intro::IntroState, admin_panel::AdminPanelState}; use crate::components::admin::{admin_panel::AdminPanelState};
use crate::components::intro::{intro::IntroState};
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()?;
@@ -18,10 +19,22 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
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);
let mut intro_state = IntroState::new(); let mut intro_state = IntroState::new();
let admin_panel_state = AdminPanelState::new();
// Initialize app_state first
let mut app_state = AppState::new()?;
// Fetch profile tree and table structure
let profile_tree = grpc_client.get_profile_tree().await?;
app_state.profile_tree = profile_tree;
// Now create admin panel with profiles from app_state
let profiles = app_state.profile_tree.profiles
.iter()
.map(|p| p.name.clone())
.collect();
let mut admin_panel_state = AdminPanelState::new(profiles);
// 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.
let table_structure = grpc_client.get_table_structure().await?; let table_structure = grpc_client.get_table_structure().await?;
// Extract the column names from the response // Extract the column names from the response
@@ -34,13 +47,9 @@ 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()?;
app_state.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?;
@@ -66,7 +75,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&event_handler.command_message, &event_handler.command_message,
&app_state, &app_state,
&intro_state, &intro_state,
&admin_panel_state, &mut admin_panel_state,
); );
})?; })?;
@@ -99,7 +108,6 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
}; };
form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos); form_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
// Ensure position never exceeds total_count + 1 // Ensure position never exceeds total_count + 1
if app_state.current_position > total_count + 1 { if app_state.current_position > total_count + 1 {
app_state.current_position = total_count + 1; app_state.current_position = total_count + 1;