Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20f9fae141 | ||
|
|
ec062bbf24 | ||
|
|
8745c9ea2f | ||
|
|
0917654361 | ||
|
|
d892d1cfa0 | ||
|
|
e31138c250 | ||
|
|
7cbe5ce8be | ||
|
|
1c31d4cd1c |
@@ -10,6 +10,7 @@ next_option = ["l", "Right"]
|
|||||||
previous_option = ["h", "Left"]
|
previous_option = ["h", "Left"]
|
||||||
select = ["Enter"]
|
select = ["Enter"]
|
||||||
toggle_sidebar = ["ctrl+t"]
|
toggle_sidebar = ["ctrl+t"]
|
||||||
|
toggle_buffer_list = ["ctrl+b"]
|
||||||
next_field = ["Tab"]
|
next_field = ["Tab"]
|
||||||
prev_field = ["Shift+Tab"]
|
prev_field = ["Shift+Tab"]
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ save_and_quit = ["ctrl+shift+s"]
|
|||||||
move_up = ["Up"]
|
move_up = ["Up"]
|
||||||
move_down = ["Down"]
|
move_down = ["Down"]
|
||||||
toggle_sidebar = ["ctrl+t"]
|
toggle_sidebar = ["ctrl+t"]
|
||||||
|
toggle_buffer_list = ["ctrl+b"]
|
||||||
|
|
||||||
# MODE SPECIFIC
|
# MODE SPECIFIC
|
||||||
# READ ONLY MODE
|
# READ ONLY MODE
|
||||||
|
|||||||
@@ -1,24 +1,35 @@
|
|||||||
// src/components/admin/admin_panel.rs
|
// src/components/admin/admin_panel.rs
|
||||||
|
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::state::pages::admin::AdminState; // Import the persistent state
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::admin::AdminState;
|
||||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::Style, // Added Modifier
|
style::Style,
|
||||||
text::{Line, Span, Text},
|
text::{Line, Span, Text},
|
||||||
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph, Wrap},
|
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph, Wrap},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Renamed from AdminPanelState::render and made a standalone function
|
/// Renders the view specific to admin users.
|
||||||
|
fn render_admin_panel_admin(f: &mut Frame, content_chunks: &[Rect], theme: &Theme) {
|
||||||
|
// Admin-specific view placeholder
|
||||||
|
let admin_message = Paragraph::new("Admin-specific view. Profile selection not applicable.")
|
||||||
|
.style(Style::default().fg(theme.fg))
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
// Render only in the right pane for now, leaving left empty
|
||||||
|
f.render_widget(admin_message, content_chunks[1]);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_admin_panel(
|
pub fn render_admin_panel(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
admin_state: &AdminState, // Accept the persistent state (immutable borrow is enough for rendering)
|
auth_state: &AuthState,
|
||||||
|
admin_state: &AdminState,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
profile_tree: &ProfileTreeResponse,
|
profile_tree: &ProfileTreeResponse,
|
||||||
selected_profile: &Option<String>, // The globally selected profile for the checkmark
|
selected_profile: &Option<String>,
|
||||||
) {
|
) {
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
@@ -45,14 +56,36 @@ pub fn render_admin_panel(
|
|||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||||
.split(chunks[1]);
|
.split(chunks[1]);
|
||||||
|
|
||||||
|
if auth_state.role.as_deref() != Some("admin") {
|
||||||
|
render_admin_panel_non_admin(
|
||||||
|
f,
|
||||||
|
admin_state,
|
||||||
|
&content_chunks,
|
||||||
|
theme,
|
||||||
|
profile_tree,
|
||||||
|
selected_profile,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
render_admin_panel_admin(f, &content_chunks, theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Renders the view for non-admin users (profile list and details).
|
||||||
|
fn render_admin_panel_non_admin(
|
||||||
|
f: &mut Frame,
|
||||||
|
admin_state: &AdminState,
|
||||||
|
content_chunks: &[Rect],
|
||||||
|
theme: &Theme,
|
||||||
|
profile_tree: &ProfileTreeResponse,
|
||||||
|
selected_profile: &Option<String>,
|
||||||
|
) {
|
||||||
// Profile list - Use data from admin_state
|
// Profile list - Use data from admin_state
|
||||||
let items: Vec<ListItem> = admin_state
|
let items: Vec<ListItem> = admin_state
|
||||||
.profiles // Use profiles from the persistent state
|
.profiles
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
ListItem::new(Line::from(vec![
|
ListItem::new(Line::from(vec![
|
||||||
Span::styled(
|
Span::styled(
|
||||||
// Check against the globally selected profile for the checkmark
|
|
||||||
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
||||||
Style::default().fg(theme.accent),
|
Style::default().fg(theme.accent),
|
||||||
),
|
),
|
||||||
@@ -65,15 +98,12 @@ pub fn render_admin_panel(
|
|||||||
.block(Block::default().title("Profiles"))
|
.block(Block::default().title("Profiles"))
|
||||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
||||||
|
|
||||||
// Render statefully using a CLONE of the list_state from persistent AdminState
|
|
||||||
// Cloning is necessary because render_stateful_widget needs `&mut ListState`
|
|
||||||
// but we only have `&AdminState`. This is a common pattern in Ratatui.
|
|
||||||
let mut list_state_clone = admin_state.list_state.clone();
|
let mut list_state_clone = admin_state.list_state.clone();
|
||||||
f.render_stateful_widget(list, content_chunks[0], &mut list_state_clone);
|
f.render_stateful_widget(list, content_chunks[0], &mut list_state_clone);
|
||||||
|
|
||||||
// Profile details - Use selection info from admin_state
|
// Profile details - Use selection info from admin_state
|
||||||
if let Some(profile) = admin_state
|
if let Some(profile) = admin_state
|
||||||
.get_selected_index() // Use the method from persistent state
|
.get_selected_index()
|
||||||
.and_then(|i| profile_tree.profiles.get(i))
|
.and_then(|i| profile_tree.profiles.get(i))
|
||||||
{
|
{
|
||||||
let mut text = Text::default();
|
let mut text = Text::default();
|
||||||
@@ -101,8 +131,7 @@ pub fn render_admin_panel(
|
|||||||
|
|
||||||
let details_widget = Paragraph::new(text)
|
let details_widget = Paragraph::new(text)
|
||||||
.block(Block::default().title("Details"))
|
.block(Block::default().title("Details"))
|
||||||
.wrap(Wrap { trim: true }); // Add wrapping
|
.wrap(Wrap { trim: true });
|
||||||
f.render_widget(details_widget, content_chunks[1]);
|
f.render_widget(details_widget, content_chunks[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// src/components/handlers.rs
|
// src/components/handlers.rs
|
||||||
pub mod canvas;
|
pub mod canvas;
|
||||||
pub mod sidebar;
|
pub mod sidebar;
|
||||||
|
pub mod buffer_list;
|
||||||
|
|
||||||
pub use canvas::*;
|
pub use canvas::*;
|
||||||
pub use sidebar::*;
|
pub use sidebar::*;
|
||||||
|
pub use buffer_list::*;
|
||||||
|
|||||||
61
client/src/components/handlers/buffer_list.rs
Normal file
61
client/src/components/handlers/buffer_list.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// src/components/handlers/buffer_list.rs
|
||||||
|
|
||||||
|
use crate::config::colors::themes::Theme;
|
||||||
|
use crate::state::app::state::AppState;
|
||||||
|
use ratatui::{
|
||||||
|
layout::{Alignment, Rect}, // Added Alignment
|
||||||
|
style::{Style, Stylize},
|
||||||
|
text::{Line, Span}, // Added Span
|
||||||
|
widgets::{Block, Borders, Paragraph}, // Changed widgets
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn render_buffer_list(
|
||||||
|
f: &mut Frame,
|
||||||
|
area: Rect,
|
||||||
|
theme: &Theme,
|
||||||
|
app_state: &AppState,
|
||||||
|
) {
|
||||||
|
let mut current_buffer_name = "*scratch*"; // Default
|
||||||
|
|
||||||
|
// Determine the active buffer name based on UI state
|
||||||
|
if app_state.ui.show_intro {
|
||||||
|
current_buffer_name = "Intro";
|
||||||
|
} else if app_state.ui.show_register {
|
||||||
|
current_buffer_name = "Register";
|
||||||
|
} else if app_state.ui.show_login {
|
||||||
|
current_buffer_name = "Login";
|
||||||
|
} else if app_state.ui.show_admin {
|
||||||
|
current_buffer_name = "Admin Panel";
|
||||||
|
} else if app_state.ui.show_form {
|
||||||
|
// Potentially make this more specific later (e.g., show table name)
|
||||||
|
current_buffer_name = "Data Form";
|
||||||
|
}
|
||||||
|
// Add more conditions if other views exist
|
||||||
|
|
||||||
|
// Create the text line for the buffer name with padding
|
||||||
|
let buffer_text = Line::from(vec![
|
||||||
|
Span::raw(" "), // Left padding
|
||||||
|
Span::styled(
|
||||||
|
current_buffer_name,
|
||||||
|
Style::default().fg(theme.bg).bg(theme.highlight), // Style active tab
|
||||||
|
),
|
||||||
|
Span::raw(" "), // Right padding
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create the paragraph centered within the block
|
||||||
|
let paragraph = Paragraph::new(buffer_text)
|
||||||
|
.alignment(Alignment::Left) // Align text left, padding handles spacing
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
// Keep only the bottom border to act as a separator
|
||||||
|
.borders(Borders::BOTTOM)
|
||||||
|
.border_style(Style::default().fg(theme.secondary)),
|
||||||
|
)
|
||||||
|
// Set the background for the entire area (behind the text/block)
|
||||||
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
|
// Render the paragraph widget
|
||||||
|
f.render_widget(paragraph, area);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -8,103 +8,80 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
|
use crate::state::pages::intro::IntroState;
|
||||||
|
|
||||||
pub struct IntroState {
|
pub fn render_intro(f: &mut Frame, intro_state: &IntroState, area: Rect, theme: &Theme) {
|
||||||
pub selected_option: usize,
|
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(40),
|
||||||
|
Constraint::Length(5),
|
||||||
|
Constraint::Percentage(40),
|
||||||
|
])
|
||||||
|
.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 - now with 4 options
|
||||||
|
let button_area = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Percentage(25),
|
||||||
|
Constraint::Percentage(25),
|
||||||
|
Constraint::Percentage(25),
|
||||||
|
Constraint::Percentage(25),
|
||||||
|
])
|
||||||
|
.split(chunks[1].inner(Margin {
|
||||||
|
horizontal: 1,
|
||||||
|
vertical: 1
|
||||||
|
}));
|
||||||
|
|
||||||
|
let buttons = ["Continue", "Admin", "Login", "Register"];
|
||||||
|
for (i, &text) in buttons.iter().enumerate() {
|
||||||
|
render_button(f, button_area[i], text, intro_state.selected_option == i, theme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntroState {
|
fn render_button(f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
|
||||||
pub fn new() -> Self {
|
let button_style = Style::default()
|
||||||
Self { selected_option: 0 }
|
.fg(if selected { theme.highlight } else { theme.fg })
|
||||||
}
|
.bg(theme.bg)
|
||||||
|
.add_modifier(if selected {
|
||||||
|
ratatui::style::Modifier::BOLD
|
||||||
|
} else {
|
||||||
|
ratatui::style::Modifier::empty()
|
||||||
|
});
|
||||||
|
|
||||||
pub fn render(&self, f: &mut Frame, area: Rect, theme: &Theme) {
|
let border_style = Style::default()
|
||||||
let block = Block::default()
|
.fg(if selected { theme.accent } else { theme.border });
|
||||||
|
|
||||||
|
let button = Paragraph::new(text)
|
||||||
|
.style(button_style)
|
||||||
|
.alignment(Alignment::Center)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Double)
|
||||||
.border_style(Style::default().fg(theme.accent))
|
.border_style(border_style),
|
||||||
.style(Style::default().bg(theme.bg));
|
);
|
||||||
|
|
||||||
let inner_area = block.inner(area);
|
f.render_widget(button, area);
|
||||||
f.render_widget(block, area);
|
|
||||||
|
|
||||||
// Center layout
|
|
||||||
let chunks = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
Constraint::Length(5),
|
|
||||||
Constraint::Percentage(40),
|
|
||||||
])
|
|
||||||
.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 - now with 4 options
|
|
||||||
let button_area = Layout::default()
|
|
||||||
.direction(Direction::Horizontal)
|
|
||||||
.constraints([
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
Constraint::Percentage(25),
|
|
||||||
])
|
|
||||||
.split(chunks[1].inner(Margin {
|
|
||||||
horizontal: 1,
|
|
||||||
vertical: 1
|
|
||||||
}));
|
|
||||||
|
|
||||||
let buttons = ["Continue", "Admin", "Login", "Register"];
|
|
||||||
for (i, &text) in buttons.iter().enumerate() {
|
|
||||||
self.render_button(
|
|
||||||
f,
|
|
||||||
button_area[i],
|
|
||||||
text,
|
|
||||||
self.selected_option == i,
|
|
||||||
theme,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_button(&self, f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
|
|
||||||
let button_style = Style::default()
|
|
||||||
.fg(if selected { theme.highlight } else { theme.fg })
|
|
||||||
.bg(theme.bg)
|
|
||||||
.add_modifier(if selected {
|
|
||||||
ratatui::style::Modifier::BOLD
|
|
||||||
} else {
|
|
||||||
ratatui::style::Modifier::empty()
|
|
||||||
});
|
|
||||||
|
|
||||||
let border_style = Style::default()
|
|
||||||
.fg(if selected { theme.accent } else { theme.border });
|
|
||||||
|
|
||||||
let button = Paragraph::new(text)
|
|
||||||
.style(button_style)
|
|
||||||
.alignment(Alignment::Center)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_type(BorderType::Double)
|
|
||||||
.border_style(border_style),
|
|
||||||
);
|
|
||||||
|
|
||||||
f.render_widget(button, area);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_option(&mut self) {
|
|
||||||
self.selected_option = (self.selected_option + 1) % 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous_option(&mut self) {
|
|
||||||
self.selected_option = if self.selected_option == 0 { 3 } else { self.selected_option - 1 };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::state::app::state::AppState;
|
|||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::LoginState;
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
|
use crate::state::pages::intro::IntroState;
|
||||||
use crate::state::pages::admin::AdminState;
|
use crate::state::pages::admin::AdminState;
|
||||||
use crate::state::pages::canvas_state::CanvasState;
|
use crate::state::pages::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::context::UiContext;
|
use crate::ui::handlers::context::UiContext;
|
||||||
@@ -18,6 +19,7 @@ pub async fn handle_navigation_event(
|
|||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
login_state: &mut LoginState,
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
|
intro_state: &mut IntroState,
|
||||||
admin_state: &mut AdminState,
|
admin_state: &mut AdminState,
|
||||||
command_mode: &mut bool,
|
command_mode: &mut bool,
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
@@ -26,27 +28,21 @@ pub async fn handle_navigation_event(
|
|||||||
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
||||||
match action {
|
match action {
|
||||||
"move_up" => {
|
"move_up" => {
|
||||||
move_up(app_state, login_state, register_state, admin_state);
|
move_up(app_state, login_state, register_state, intro_state, admin_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"move_down" => {
|
"move_down" => {
|
||||||
move_down(app_state, admin_state);
|
move_down(app_state, intro_state, admin_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"next_option" => {
|
"next_option" => {
|
||||||
next_option(app_state);
|
next_option(app_state, intro_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"previous_option" => {
|
"previous_option" => {
|
||||||
previous_option(app_state);
|
previous_option(app_state, intro_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"toggle_sidebar" => {
|
|
||||||
toggle_sidebar(app_state);
|
|
||||||
return Ok(EventOutcome::Ok(format!("Sidebar {}",
|
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
"next_field" => {
|
"next_field" => {
|
||||||
next_field(form_state);
|
next_field(form_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
@@ -61,7 +57,7 @@ pub async fn handle_navigation_event(
|
|||||||
}
|
}
|
||||||
"select" => {
|
"select" => {
|
||||||
let (context, index) = if app_state.ui.show_intro {
|
let (context, index) = if app_state.ui.show_intro {
|
||||||
(UiContext::Intro, app_state.ui.intro_state.selected_option)
|
(UiContext::Intro, intro_state.selected_option)
|
||||||
} else if app_state.ui.show_login && app_state.ui.focus_outside_canvas {
|
} else if app_state.ui.show_login && app_state.ui.focus_outside_canvas {
|
||||||
(UiContext::Login, app_state.focused_button_index)
|
(UiContext::Login, app_state.focused_button_index)
|
||||||
} else if app_state.ui.show_register && app_state.ui.focus_outside_canvas {
|
} else if app_state.ui.show_register && app_state.ui.focus_outside_canvas {
|
||||||
@@ -81,7 +77,7 @@ pub async fn handle_navigation_event(
|
|||||||
Ok(EventOutcome::Ok(String::new()))
|
Ok(EventOutcome::Ok(String::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, admin_state: &mut AdminState) {
|
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, intro_state: &mut IntroState, admin_state: &mut AdminState) {
|
||||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
||||||
if app_state.focused_button_index == 0 {
|
if app_state.focused_button_index == 0 {
|
||||||
app_state.ui.focus_outside_canvas = false;
|
app_state.ui.focus_outside_canvas = false;
|
||||||
@@ -96,28 +92,28 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
|
|||||||
app_state.focused_button_index = app_state.focused_button_index.saturating_sub(1);
|
app_state.focused_button_index = app_state.focused_button_index.saturating_sub(1);
|
||||||
}
|
}
|
||||||
} else if app_state.ui.show_intro {
|
} else if app_state.ui.show_intro {
|
||||||
app_state.ui.intro_state.previous_option();
|
intro_state.previous_option();
|
||||||
} else if app_state.ui.show_admin {
|
} else if app_state.ui.show_admin {
|
||||||
admin_state.previous();
|
admin_state.previous();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) {
|
pub fn move_down(app_state: &mut AppState, intro_state: &mut IntroState, admin_state: &mut AdminState) {
|
||||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
|
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
|
||||||
let num_general_elements = 2;
|
let num_general_elements = 2;
|
||||||
if app_state.focused_button_index < num_general_elements - 1 {
|
if app_state.focused_button_index < num_general_elements - 1 {
|
||||||
app_state.focused_button_index += 1;
|
app_state.focused_button_index += 1;
|
||||||
}
|
}
|
||||||
} else if app_state.ui.show_intro {
|
} else if app_state.ui.show_intro {
|
||||||
app_state.ui.intro_state.next_option();
|
intro_state.next_option();
|
||||||
} else if app_state.ui.show_admin {
|
} else if app_state.ui.show_admin {
|
||||||
admin_state.next();
|
admin_state.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
|
pub fn next_option(app_state: &mut AppState, intro_state: &mut IntroState) {
|
||||||
if app_state.ui.show_intro {
|
if app_state.ui.show_intro {
|
||||||
app_state.ui.intro_state.next_option();
|
intro_state.next_option();
|
||||||
} else {
|
} else {
|
||||||
// Get option count from state instead of parameter
|
// Get option count from state instead of parameter
|
||||||
let option_count = app_state.profile_tree.profiles.len();
|
let option_count = app_state.profile_tree.profiles.len();
|
||||||
@@ -125,9 +121,9 @@ pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn previous_option(app_state: &mut AppState) {
|
pub fn previous_option(app_state: &mut AppState, intro_state: &mut IntroState) {
|
||||||
if app_state.ui.show_intro {
|
if app_state.ui.show_intro {
|
||||||
app_state.ui.intro_state.previous_option();
|
intro_state.previous_option();
|
||||||
} else {
|
} else {
|
||||||
let option_count = app_state.profile_tree.profiles.len();
|
let option_count = app_state.profile_tree.profiles.len();
|
||||||
app_state.focused_button_index = if app_state.focused_button_index == 0 {
|
app_state.focused_button_index = if app_state.focused_button_index == 0 {
|
||||||
@@ -138,10 +134,6 @@ pub fn previous_option(app_state: &mut AppState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_sidebar(app_state: &mut AppState) {
|
|
||||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_field(form_state: &mut FormState) {
|
pub fn next_field(form_state: &mut FormState) {
|
||||||
if !form_state.fields.is_empty() {
|
if !form_state.fields.is_empty() {
|
||||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::state::pages::form::FormState;
|
|||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::pages::auth::LoginState;
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
|
use crate::state::pages::intro::IntroState;
|
||||||
use crate::state::pages::admin::AdminState;
|
use crate::state::pages::admin::AdminState;
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
use crate::state::pages::canvas_state::CanvasState;
|
use crate::state::pages::canvas_state::CanvasState;
|
||||||
@@ -70,6 +71,7 @@ impl EventHandler {
|
|||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
login_state: &mut LoginState,
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
|
intro_state: &mut IntroState,
|
||||||
admin_state: &mut AdminState,
|
admin_state: &mut AdminState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
@@ -99,6 +101,13 @@ impl EventHandler {
|
|||||||
);
|
);
|
||||||
return Ok(EventOutcome::Ok(message));
|
return Ok(EventOutcome::Ok(message));
|
||||||
}
|
}
|
||||||
|
if UiStateHandler::toggle_buffer_list(&mut app_state.ui, config, key_code, modifiers) {
|
||||||
|
let message = format!("Buffer {}",
|
||||||
|
if app_state.ui.show_buffer_list { "shown" } else { "hidden" }
|
||||||
|
);
|
||||||
|
return Ok(EventOutcome::Ok(message));
|
||||||
|
}
|
||||||
|
// --- End Global UI Toggles ---
|
||||||
|
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
@@ -109,6 +118,7 @@ impl EventHandler {
|
|||||||
app_state,
|
app_state,
|
||||||
login_state,
|
login_state,
|
||||||
register_state,
|
register_state,
|
||||||
|
intro_state,
|
||||||
admin_state,
|
admin_state,
|
||||||
&mut self.command_mode,
|
&mut self.command_mode,
|
||||||
&mut self.command_input,
|
&mut self.command_input,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||||
use crate::components::IntroState;
|
|
||||||
use crate::modes::handlers::mode_manager::AppMode;
|
use crate::modes::handlers::mode_manager::AppMode;
|
||||||
use crate::ui::handlers::context::DialogPurpose;
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
|
|
||||||
@@ -17,12 +16,12 @@ pub struct DialogState {
|
|||||||
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub show_sidebar: bool,
|
pub show_sidebar: bool,
|
||||||
|
pub show_buffer_list: bool,
|
||||||
pub show_intro: bool,
|
pub show_intro: bool,
|
||||||
pub show_admin: bool,
|
pub show_admin: bool,
|
||||||
pub show_form: bool,
|
pub show_form: bool,
|
||||||
pub show_login: bool,
|
pub show_login: bool,
|
||||||
pub show_register: bool,
|
pub show_register: bool,
|
||||||
pub intro_state: IntroState,
|
|
||||||
pub focus_outside_canvas: bool,
|
pub focus_outside_canvas: bool,
|
||||||
pub dialog: DialogState,
|
pub dialog: DialogState,
|
||||||
}
|
}
|
||||||
@@ -138,7 +137,7 @@ impl Default for UiState {
|
|||||||
show_form: false,
|
show_form: false,
|
||||||
show_login: false,
|
show_login: false,
|
||||||
show_register: false,
|
show_register: false,
|
||||||
intro_state: IntroState::new(),
|
show_buffer_list: false,
|
||||||
focus_outside_canvas: false,
|
focus_outside_canvas: false,
|
||||||
dialog: DialogState::default(),
|
dialog: DialogState::default(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
pub mod form;
|
pub mod form;
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod admin;
|
pub mod admin;
|
||||||
|
pub mod intro;
|
||||||
pub mod canvas_state;
|
pub mod canvas_state;
|
||||||
|
|||||||
25
client/src/state/pages/intro.rs
Normal file
25
client/src/state/pages/intro.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// src/state/pages/intro.rs
|
||||||
|
|
||||||
|
#[derive(Default, Clone, Debug)]
|
||||||
|
pub struct IntroState {
|
||||||
|
pub selected_option: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntroState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_option(&mut self) {
|
||||||
|
if self.selected_option < 3 {
|
||||||
|
self.selected_option += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn previous_option(&mut self) {
|
||||||
|
if self.selected_option > 0 {
|
||||||
|
self.selected_option -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
|
// src/tui/functions/intro.rs
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
|
|
||||||
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add index parameter
|
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) {
|
||||||
match index { // Use index directly
|
match index { // Use index directly
|
||||||
0 => { // Continue
|
0 => { // Continue
|
||||||
app_state.ui.show_form = true;
|
app_state.ui.show_form = true;
|
||||||
|
|||||||
@@ -21,4 +21,18 @@ impl UiStateHandler {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle_buffer_list(
|
||||||
|
ui_state: &mut UiState,
|
||||||
|
config: &Config,
|
||||||
|
key: KeyCode,
|
||||||
|
modifiers: KeyModifiers,
|
||||||
|
) -> bool {
|
||||||
|
if let Some(action) = config.get_common_action(key, modifiers) {
|
||||||
|
if action == "toggle_buffer_list" {
|
||||||
|
ui_state.show_buffer_list = !ui_state.show_buffer_list;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
render_background,
|
render_background,
|
||||||
|
render_buffer_list,
|
||||||
render_command_line,
|
render_command_line,
|
||||||
render_status_line,
|
render_status_line,
|
||||||
|
intro::intro::render_intro,
|
||||||
handlers::sidebar::{self, calculate_sidebar_layout},
|
handlers::sidebar::{self, calculate_sidebar_layout},
|
||||||
form::form::render_form,
|
form::form::render_form,
|
||||||
auth::{login::render_login, register::render_register},
|
auth::{login::render_login, register::render_register},
|
||||||
@@ -15,6 +17,7 @@ use crate::state::pages::form::FormState;
|
|||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::pages::auth::LoginState;
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
|
use crate::state::pages::intro::IntroState;
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
use crate::state::pages::admin::AdminState;
|
use crate::state::pages::admin::AdminState;
|
||||||
|
|
||||||
@@ -24,6 +27,7 @@ pub fn render_ui(
|
|||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
login_state: &LoginState,
|
login_state: &LoginState,
|
||||||
register_state: &RegisterState,
|
register_state: &RegisterState,
|
||||||
|
intro_state: &IntroState,
|
||||||
admin_state: &mut AdminState,
|
admin_state: &mut AdminState,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
@@ -37,18 +41,46 @@ pub fn render_ui(
|
|||||||
) {
|
) {
|
||||||
render_background(f, f.area(), theme);
|
render_background(f, f.area(), theme);
|
||||||
|
|
||||||
|
// Adjust layout based on whether buffer list is shown
|
||||||
|
let constraints = if app_state.ui.show_buffer_list {
|
||||||
|
vec![
|
||||||
|
Constraint::Length(2), // Buffer list
|
||||||
|
Constraint::Min(1), // Main content
|
||||||
|
Constraint::Length(1), // Status line
|
||||||
|
Constraint::Length(1), // Command line
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![
|
||||||
|
Constraint::Min(1), // Main content
|
||||||
|
Constraint::Length(1), // Status line (no buffer list)
|
||||||
|
Constraint::Length(1), // Command line
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints(constraints)
|
||||||
Constraint::Min(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
])
|
|
||||||
.split(f.area());
|
.split(f.area());
|
||||||
|
|
||||||
let main_content_area = root[0];
|
let mut buffer_list_area = None;
|
||||||
|
let main_content_area;
|
||||||
|
let status_line_area;
|
||||||
|
let command_line_area;
|
||||||
|
|
||||||
|
// Assign areas based on layout
|
||||||
|
if app_state.ui.show_buffer_list {
|
||||||
|
buffer_list_area = Some(root[0]);
|
||||||
|
main_content_area = root[1];
|
||||||
|
status_line_area = root[2];
|
||||||
|
command_line_area = root[3];
|
||||||
|
} else {
|
||||||
|
main_content_area = root[0];
|
||||||
|
status_line_area = root[1];
|
||||||
|
command_line_area = root[2];
|
||||||
|
}
|
||||||
|
|
||||||
if app_state.ui.show_intro {
|
if app_state.ui.show_intro {
|
||||||
app_state.ui.intro_state.render(f, main_content_area, theme);
|
render_intro(f, intro_state, main_content_area, theme);
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
render_register(
|
render_register(
|
||||||
f,
|
f,
|
||||||
@@ -58,7 +90,7 @@ pub fn render_ui(
|
|||||||
app_state,
|
app_state,
|
||||||
register_state.current_field < 4
|
register_state.current_field < 4
|
||||||
);
|
);
|
||||||
}else if app_state.ui.show_login {
|
} else if app_state.ui.show_login {
|
||||||
render_login(
|
render_login(
|
||||||
f,
|
f,
|
||||||
main_content_area,
|
main_content_area,
|
||||||
@@ -68,8 +100,9 @@ pub fn render_ui(
|
|||||||
login_state.current_field < 2
|
login_state.current_field < 2
|
||||||
);
|
);
|
||||||
} else if app_state.ui.show_admin {
|
} else if app_state.ui.show_admin {
|
||||||
crate::components::admin::admin_panel::render_admin_panel(
|
crate::components::admin::admin_panel::render_admin_panel(
|
||||||
f,
|
f,
|
||||||
|
auth_state,
|
||||||
admin_state,
|
admin_state,
|
||||||
main_content_area,
|
main_content_area,
|
||||||
theme,
|
theme,
|
||||||
@@ -132,10 +165,14 @@ pub fn render_ui(
|
|||||||
total_count,
|
total_count,
|
||||||
current_position,
|
current_position,
|
||||||
);
|
);
|
||||||
} else{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
// Render buffer list if enabled and area is available
|
||||||
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
|
if let Some(area) = buffer_list_area {
|
||||||
|
if app_state.ui.show_buffer_list {
|
||||||
|
render_buffer_list(f, area, theme, app_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render_status_line(f, status_line_area, current_dir, theme, is_edit_mode);
|
||||||
|
render_command_line(f, command_line_area, command_input, command_mode, theme, command_message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use crate::state::pages::auth::AuthState;
|
|||||||
use crate::state::pages::auth::LoginState;
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::pages::admin::AdminState;
|
use crate::state::pages::admin::AdminState;
|
||||||
|
use crate::state::pages::intro::IntroState;
|
||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
// Import SaveOutcome
|
// Import SaveOutcome
|
||||||
use crate::tui::terminal::{EventReader, TerminalCore};
|
use crate::tui::terminal::{EventReader, TerminalCore};
|
||||||
@@ -21,30 +22,27 @@ use crossterm::cursor::SetCursorStyle;
|
|||||||
|
|
||||||
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 theme = Theme::from_str(&config.colors.theme);
|
||||||
let mut terminal = TerminalCore::new()?;
|
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 mut auth_state = AuthState::default();
|
|
||||||
let mut register_state = RegisterState::default();
|
|
||||||
let mut login_state = LoginState::default();
|
|
||||||
let mut admin_state = AdminState::default();
|
|
||||||
|
|
||||||
// Initialize app_state first
|
let mut event_handler = EventHandler::new().await?;
|
||||||
|
let event_reader = EventReader::new();
|
||||||
|
|
||||||
|
let mut auth_state = AuthState::default();
|
||||||
|
let mut login_state = LoginState::default();
|
||||||
|
let mut register_state = RegisterState::default();
|
||||||
|
let mut intro_state = IntroState::default();
|
||||||
|
let mut admin_state = AdminState::default();
|
||||||
let mut app_state = AppState::new()?;
|
let mut app_state = AppState::new()?;
|
||||||
|
|
||||||
// Initialize app state with profile tree and table structure
|
// Initialize app state with profile tree and table structure
|
||||||
let column_names =
|
let column_names =
|
||||||
UiService::initialize_app_state(&mut grpc_client, &mut app_state)
|
UiService::initialize_app_state(&mut grpc_client, &mut app_state)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Initialize FormState with dynamic fields
|
|
||||||
let mut form_state = FormState::new(column_names);
|
let mut form_state = FormState::new(column_names);
|
||||||
|
|
||||||
// Initialize EventHandler (which now contains AuthClient)
|
|
||||||
let mut event_handler = EventHandler::new().await?;
|
|
||||||
let event_reader = EventReader::new();
|
|
||||||
|
|
||||||
// Fetch the total count of Adresar entries
|
// Fetch the total count of Adresar entries
|
||||||
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state)
|
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -61,6 +59,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
&mut auth_state,
|
&mut auth_state,
|
||||||
&login_state,
|
&login_state,
|
||||||
®ister_state,
|
®ister_state,
|
||||||
|
&intro_state,
|
||||||
&mut admin_state,
|
&mut admin_state,
|
||||||
&theme,
|
&theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
@@ -121,6 +120,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
&mut auth_state,
|
&mut auth_state,
|
||||||
&mut login_state,
|
&mut login_state,
|
||||||
&mut register_state,
|
&mut register_state,
|
||||||
|
&mut intro_state,
|
||||||
&mut admin_state,
|
&mut admin_state,
|
||||||
&mut app_state,
|
&mut app_state,
|
||||||
total_count,
|
total_count,
|
||||||
|
|||||||
Reference in New Issue
Block a user