Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f42790980d | ||
|
|
779683de4b | ||
|
|
aa8887318f | ||
|
|
3ad8dc6490 | ||
|
|
20f9fae141 | ||
|
|
ec062bbf24 | ||
|
|
8745c9ea2f | ||
|
|
0917654361 | ||
|
|
d892d1cfa0 |
@@ -10,6 +10,7 @@ next_option = ["l", "Right"]
|
||||
previous_option = ["h", "Left"]
|
||||
select = ["Enter"]
|
||||
toggle_sidebar = ["ctrl+t"]
|
||||
toggle_buffer_list = ["ctrl+b"]
|
||||
next_field = ["Tab"]
|
||||
prev_field = ["Shift+Tab"]
|
||||
|
||||
@@ -24,6 +25,7 @@ save_and_quit = ["ctrl+shift+s"]
|
||||
move_up = ["Up"]
|
||||
move_down = ["Down"]
|
||||
toggle_sidebar = ["ctrl+t"]
|
||||
toggle_buffer_list = ["ctrl+b"]
|
||||
|
||||
# MODE SPECIFIC
|
||||
# READ ONLY MODE
|
||||
|
||||
@@ -1,24 +1,35 @@
|
||||
// src/components/admin/admin_panel.rs
|
||||
|
||||
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 ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::Style, // Added Modifier
|
||||
style::Style,
|
||||
text::{Line, Span, Text},
|
||||
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph, Wrap},
|
||||
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(
|
||||
f: &mut Frame,
|
||||
admin_state: &AdminState, // Accept the persistent state (immutable borrow is enough for rendering)
|
||||
auth_state: &AuthState,
|
||||
admin_state: &AdminState,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
profile_tree: &ProfileTreeResponse,
|
||||
selected_profile: &Option<String>, // The globally selected profile for the checkmark
|
||||
selected_profile: &Option<String>,
|
||||
) {
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
@@ -45,14 +56,36 @@ pub fn render_admin_panel(
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||
.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
|
||||
let items: Vec<ListItem> = admin_state
|
||||
.profiles // Use profiles from the persistent state
|
||||
.profiles
|
||||
.iter()
|
||||
.map(|p| {
|
||||
ListItem::new(Line::from(vec![
|
||||
Span::styled(
|
||||
// Check against the globally selected profile for the checkmark
|
||||
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
||||
Style::default().fg(theme.accent),
|
||||
),
|
||||
@@ -65,15 +98,12 @@ pub fn render_admin_panel(
|
||||
.block(Block::default().title("Profiles"))
|
||||
.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();
|
||||
f.render_stateful_widget(list, content_chunks[0], &mut list_state_clone);
|
||||
|
||||
// Profile details - Use selection info from 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))
|
||||
{
|
||||
let mut text = Text::default();
|
||||
@@ -101,8 +131,7 @@ pub fn render_admin_panel(
|
||||
|
||||
let details_widget = Paragraph::new(text)
|
||||
.block(Block::default().title("Details"))
|
||||
.wrap(Wrap { trim: true }); // Add wrapping
|
||||
.wrap(Wrap { trim: true });
|
||||
f.render_widget(details_widget, content_chunks[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// src/components/handlers.rs
|
||||
pub mod canvas;
|
||||
pub mod sidebar;
|
||||
pub mod buffer_list;
|
||||
|
||||
pub use canvas::*;
|
||||
pub use sidebar::*;
|
||||
pub use buffer_list::*;
|
||||
|
||||
63
client/src/components/handlers/buffer_list.rs
Normal file
63
client/src/components/handlers/buffer_list.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
// src/components/handlers/buffer_list.rs
|
||||
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::state::AppState;
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
style::{Style, Stylize},
|
||||
text::{Line, Span},
|
||||
widgets::Paragraph,
|
||||
Frame,
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
pub fn render_buffer_list(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
app_state: &AppState,
|
||||
) {
|
||||
// --- Style Definitions ---
|
||||
let active_style = Style::default()
|
||||
.fg(theme.bg)
|
||||
.bg(theme.highlight);
|
||||
|
||||
let inactive_style = Style::default()
|
||||
.fg(theme.fg)
|
||||
.bg(theme.bg);
|
||||
|
||||
// --- Create Spans ---
|
||||
let mut spans = Vec::new();
|
||||
let history = &app_state.ui.buffer_history;
|
||||
let mut current_width = 0;
|
||||
|
||||
for (i, view) in history.iter().enumerate() {
|
||||
let is_active = i == app_state.ui.active_buffer_index;
|
||||
let buffer_name = view.display_name();
|
||||
let buffer_text = format!(" {} ", buffer_name);
|
||||
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
|
||||
|
||||
// Calculate width needed for this buffer (separator + text)
|
||||
let needed_width = text_width;
|
||||
if current_width + needed_width > area.width as usize {
|
||||
break;
|
||||
}
|
||||
|
||||
// Add the buffer text itself
|
||||
let text_style = if is_active { active_style } else { inactive_style };
|
||||
spans.push(Span::styled(buffer_text, text_style));
|
||||
current_width += text_width;
|
||||
}
|
||||
|
||||
// --- Filler Span ---
|
||||
let remaining_width = area.width.saturating_sub(current_width as u16);
|
||||
spans.push(Span::styled(
|
||||
" ".repeat(remaining_width as usize),
|
||||
inactive_style,
|
||||
));
|
||||
|
||||
// --- Render ---
|
||||
let buffer_line = Line::from(spans);
|
||||
let paragraph = Paragraph::new(buffer_line).alignment(Alignment::Left);
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
@@ -43,12 +43,6 @@ pub async fn handle_navigation_event(
|
||||
previous_option(app_state, intro_state);
|
||||
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(form_state);
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
@@ -140,10 +134,6 @@ pub fn previous_option(app_state: &mut AppState, intro_state: &mut IntroState) {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if !form_state.fields.is_empty() {
|
||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::modes::{
|
||||
};
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::modes::handlers::mode_manager::{ModeManager, AppMode};
|
||||
use crate::state::app::state::AppView;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -80,6 +81,21 @@ impl EventHandler {
|
||||
let current_mode = ModeManager::derive_mode(app_state, self);
|
||||
app_state.update_mode(current_mode);
|
||||
|
||||
// Determine the current view, including dynamic names
|
||||
let current_view = {
|
||||
let ui = &app_state.ui;
|
||||
if ui.show_intro { AppView::Intro }
|
||||
else if ui.show_login { AppView::Login }
|
||||
else if ui.show_register { AppView::Register }
|
||||
else if ui.show_admin { AppView::Admin }
|
||||
else if ui.show_form {
|
||||
let form_name = app_state.selected_profile.clone().unwrap_or_else(|| "Data Form".to_string());
|
||||
AppView::Form(form_name)
|
||||
}
|
||||
else { AppView::Scratch }
|
||||
};
|
||||
app_state.ui.update_buffer_history(current_view);
|
||||
|
||||
// --- DIALOG MODALITY ---
|
||||
if app_state.ui.dialog.dialog_show {
|
||||
if let Some(dialog_result) = dialog::handle_dialog_event(
|
||||
@@ -101,6 +117,13 @@ impl EventHandler {
|
||||
);
|
||||
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 {
|
||||
AppMode::General => {
|
||||
|
||||
@@ -5,6 +5,31 @@ use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::modes::handlers::mode_manager::AppMode;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
|
||||
/// Represents the distinct views or "buffers" the user can navigate.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AppView {
|
||||
Intro,
|
||||
Login,
|
||||
Register,
|
||||
Admin,
|
||||
Form(String),
|
||||
Scratch,
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
/// Returns the display name for the view.
|
||||
pub fn display_name(&self) -> &str {
|
||||
match self {
|
||||
AppView::Intro => "Intro",
|
||||
AppView::Login => "Login",
|
||||
AppView::Register => "Register",
|
||||
AppView::Admin => "Admin Panel",
|
||||
AppView::Form(name) => name.as_str(),
|
||||
AppView::Scratch => "*scratch*",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DialogState {
|
||||
pub dialog_show: bool,
|
||||
pub dialog_title: String,
|
||||
@@ -16,12 +41,15 @@ pub struct DialogState {
|
||||
|
||||
pub struct UiState {
|
||||
pub show_sidebar: bool,
|
||||
pub show_buffer_list: bool,
|
||||
pub show_intro: bool,
|
||||
pub show_admin: bool,
|
||||
pub show_form: bool,
|
||||
pub show_login: bool,
|
||||
pub show_register: bool,
|
||||
pub focus_outside_canvas: bool,
|
||||
pub buffer_history: Vec<AppView>,
|
||||
pub active_buffer_index: usize,
|
||||
pub dialog: DialogState,
|
||||
}
|
||||
|
||||
@@ -136,7 +164,10 @@ impl Default for UiState {
|
||||
show_form: false,
|
||||
show_login: false,
|
||||
show_register: false,
|
||||
show_buffer_list: false,
|
||||
focus_outside_canvas: false,
|
||||
buffer_history: vec![AppView::Intro],
|
||||
active_buffer_index: 0,
|
||||
dialog: DialogState::default(),
|
||||
}
|
||||
}
|
||||
@@ -155,3 +186,20 @@ impl Default for DialogState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
/// Updates the buffer history and active index.
|
||||
pub fn update_buffer_history(&mut self, view: AppView) {
|
||||
let existing_pos = self.buffer_history.iter().position(|v| v == &view);
|
||||
|
||||
match existing_pos {
|
||||
Some(pos) => {
|
||||
self.active_buffer_index = pos;
|
||||
}
|
||||
None => {
|
||||
self.buffer_history.push(view.clone());
|
||||
self.active_buffer_index = self.buffer_history.len() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,18 @@ impl UiStateHandler {
|
||||
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,6 +2,7 @@
|
||||
|
||||
use crate::components::{
|
||||
render_background,
|
||||
render_buffer_list,
|
||||
render_command_line,
|
||||
render_status_line,
|
||||
intro::intro::render_intro,
|
||||
@@ -40,16 +41,44 @@ pub fn render_ui(
|
||||
) {
|
||||
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(1), // 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()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.constraints(constraints)
|
||||
.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 {
|
||||
render_intro(f, intro_state, main_content_area, theme);
|
||||
} else if app_state.ui.show_register {
|
||||
@@ -61,18 +90,19 @@ pub fn render_ui(
|
||||
app_state,
|
||||
register_state.current_field < 4
|
||||
);
|
||||
}else if app_state.ui.show_login {
|
||||
} else if app_state.ui.show_login {
|
||||
render_login(
|
||||
f,
|
||||
main_content_area,
|
||||
theme,
|
||||
f,
|
||||
main_content_area,
|
||||
theme,
|
||||
login_state,
|
||||
app_state,
|
||||
login_state.current_field < 2
|
||||
);
|
||||
} else if app_state.ui.show_admin {
|
||||
crate::components::admin::admin_panel::render_admin_panel(
|
||||
crate::components::admin::admin_panel::render_admin_panel(
|
||||
f,
|
||||
auth_state,
|
||||
admin_state,
|
||||
main_content_area,
|
||||
theme,
|
||||
@@ -135,10 +165,14 @@ pub fn render_ui(
|
||||
total_count,
|
||||
current_position,
|
||||
);
|
||||
} else{
|
||||
|
||||
}
|
||||
|
||||
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
||||
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
|
||||
// Render buffer list if enabled and area is available
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user