Compare commits

..

6 Commits

Author SHA1 Message Date
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
filipriec
62aed812b6 displaying admin panel properly well 2025-03-22 13:18:50 +01:00
filipriec
a58e976227 admin panel is working, needs to clear the terminal tho from the other things 2025-03-22 10:33:09 +01:00
filipriec
c198297a5c admin panel compiled 2025-03-22 10:27:21 +01:00
15 changed files with 132 additions and 51 deletions

View File

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

View File

@@ -0,0 +1,44 @@
// src/components/admin/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

@@ -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

@@ -1,16 +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 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::*;

View File

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

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

@@ -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 {
@@ -58,7 +58,8 @@ impl EventHandler {
if intro_state.selected_option == 0 { if intro_state.selected_option == 0 {
app_state.ui.show_intro = false; app_state.ui.show_intro = false;
} else { } else {
self.command_message = "Admin panel coming soon".to_string(); app_state.ui.show_intro = false;
app_state.ui.show_admin = true;
} }
return Ok((false, String::new())); return Ok((false, String::new()));
} }

View File

@@ -1,4 +1,4 @@
// src/client/ui/handlers/state.rs // src/state/state.rs
use std::env; use std::env;
use common::proto::multieko2::table_definition::ProfileTreeResponse; use common::proto::multieko2::table_definition::ProfileTreeResponse;
@@ -7,6 +7,7 @@ pub struct UiState {
pub show_sidebar: bool, pub show_sidebar: bool,
pub is_saved: bool, pub is_saved: bool,
pub show_intro: bool, pub show_intro: bool,
pub show_admin: bool,
} }
pub struct AppState { pub struct AppState {
@@ -50,6 +51,7 @@ impl Default for UiState {
show_sidebar: true, show_sidebar: true,
is_saved: false, is_saved: false,
show_intro: true, show_intro: true,
show_admin: false,
} }
} }
} }

View File

@@ -1,9 +1,11 @@
// src/ui/handlers/render.rs // src/ui/handlers/render.rs
use crate::components::{ 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}, handlers::{sidebar::{self, calculate_sidebar_layout}, admin_panel::AdminPanelState, form::render_form},
intro::{intro},
}; };
use crate::config::colors::Theme; use crate::config::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout}; use ratatui::layout::{Constraint, Direction, Layout};
@@ -24,28 +26,38 @@ 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,
) { ) {
render_background(f, f.area(), theme); render_background(f, f.area(), theme);
if app_state.ui.show_intro {
intro_state.render(f, f.area(), theme);
return;
}
let root = Layout::default() let root = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([
Constraint::Min(10), Constraint::Min(1),
Constraint::Length(1), Constraint::Length(1),
Constraint::Length(1), Constraint::Length(1),
]) ])
.split(f.area()); .split(f.area());
let main_content_area = root[0]; let main_content_area = root[0];
let (sidebar_area, form_area) = calculate_sidebar_layout(app_state.ui.show_sidebar, main_content_area); if app_state.ui.show_intro {
let available_width = form_area.width; intro_state.render(f, main_content_area, theme);
} else if app_state.ui.show_admin {
admin_panel_state.render(f, main_content_area, theme);
} else {
let (sidebar_area, form_area) = calculate_sidebar_layout(
app_state.ui.show_sidebar,
main_content_area
);
if let Some(sidebar_rect) = sidebar_area {
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
}
// This change makes the form stay stationary when toggling sidebar
let available_width = form_area.width;
let form_constraint = if available_width >= 80 { let form_constraint = if available_width >= 80 {
// Use main_content_area for centering when enough space
Layout::default() Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([ .constraints([
@@ -55,6 +67,7 @@ pub fn render_ui(
]) ])
.split(main_content_area)[1] .split(main_content_area)[1]
} else { } else {
// Use form_area (post sidebar) when limited space
Layout::default() Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([ .constraints([
@@ -65,17 +78,22 @@ pub fn render_ui(
.split(form_area)[1] .split(form_area)[1]
}; };
form_state.render( // Convert fields to &[&str] and values to &[&String]
let fields: Vec<&str> = form_state.fields.iter().map(|s| s.as_str()).collect();
let values: Vec<&String> = form_state.values.iter().collect();
render_form(
f, f,
form_constraint, form_constraint,
form_state,
&fields,
&form_state.current_field,
&values,
theme, theme,
is_edit_mode, is_edit_mode,
total_count, total_count,
current_position, current_position,
); );
if let Some(sidebar_rect) = sidebar_area {
sidebar::render_sidebar(f, sidebar_rect, theme, &app_state.profile_tree);
} }
render_status_line(f, root[1], current_dir, theme, is_edit_mode); render_status_line(f, root[1], current_dir, theme, is_edit_mode);

View File

@@ -9,7 +9,8 @@ use crate::config::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; use crate::components::handlers::{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,6 +19,7 @@ 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();
// 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.
@@ -65,6 +67,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,
); );
})?; })?;