buttons are now added in the admin panel

This commit is contained in:
filipriec
2025-04-16 21:43:21 +02:00
parent 6505e18b0b
commit 93a3c246c6
3 changed files with 86 additions and 44 deletions

View File

@@ -75,11 +75,11 @@ pub fn render_admin_panel_admin(
Style::default().fg(theme.fg) Style::default().fg(theme.fg)
}; };
ListItem::new(Line::from(vec![ ListItem::new(Line::from(vec![
Span::styled(prefix, style), Span::styled(prefix, style),
Span::styled(&profile.name, style) Span::styled(&profile.name, style)
])) ]))
}) })
.collect(); .collect();
// Build and render profile list inside the block's inner area // Build and render profile list inside the block's inner area
let profile_list = List::new(profile_list_items) let profile_list = List::new(profile_list_items)
@@ -89,7 +89,7 @@ pub fn render_admin_panel_admin(
} else { } else {
Style::default() Style::default()
}) })
.highlight_symbol(if profile_focus { "> " } else { " " }); .highlight_symbol(if profile_focus { "> " } else { " " });
f.render_stateful_widget(profile_list, profiles_inner_area, &mut admin_state.profile_list_state); f.render_stateful_widget(profile_list, profiles_inner_area, &mut admin_state.profile_list_state);
@@ -127,7 +127,7 @@ pub fn render_admin_panel_admin(
.iter() .iter()
.enumerate() .enumerate()
.map(|(idx, table)| { // Renamed i to idx for clarity .map(|(idx, table)| { // Renamed i to idx for clarity
// Check persistent selection for prefix, navigation state for style/highlight // Check persistent selection for prefix, navigation state for style/highlight
let is_selected = admin_state.selected_table_index == Some(idx); // Use persistent state for [*] let is_selected = admin_state.selected_table_index == Some(idx); // Use persistent state for [*]
let is_navigated = admin_state.table_list_state.selected() == Some(idx); // Use nav state for highlight/> let is_navigated = admin_state.table_list_state.selected() == Some(idx); // Use nav state for highlight/>
let prefix = if is_selected { "[*] " } else { "[ ] " }; let prefix = if is_selected { "[*] " } else { "[ ] " };
@@ -137,11 +137,11 @@ pub fn render_admin_panel_admin(
Style::default().fg(theme.fg) Style::default().fg(theme.fg)
}; };
ListItem::new(Line::from(vec![ ListItem::new(Line::from(vec![
Span::styled(prefix, style), Span::styled(prefix, style),
Span::styled(&table.name, style), Span::styled(&table.name, style),
])) ]))
}) })
.collect(); .collect();
// Get dependencies only for the PERSISTENTLY selected table in the PERSISTENTLY selected profile // Get dependencies only for the PERSISTENTLY selected table in the PERSISTENTLY selected profile
let chosen_profile_idx = admin_state.selected_profile_index; // Use persistent profile selection let chosen_profile_idx = admin_state.selected_profile_index; // Use persistent profile selection
@@ -164,7 +164,7 @@ pub fn render_admin_panel_admin(
} else { } else {
Style::default() Style::default()
}) })
.highlight_symbol(if table_focus { "> " } else { " " }); // Focus indicator .highlight_symbol(if table_focus { "> " } else { " " }); // Focus indicator
f.render_stateful_widget(table_list, tables_inner_area, &mut admin_state.table_list_state); f.render_stateful_widget(table_list, tables_inner_area, &mut admin_state.table_list_state);
@@ -188,8 +188,8 @@ pub fn render_admin_panel_admin(
// Prepare content for the dependencies paragraph // Prepare content for the dependencies paragraph
let mut deps_content = Text::default(); let mut deps_content = Text::default();
deps_content.lines.push(Line::from(Span::styled( deps_content.lines.push(Line::from(Span::styled(
"Depends On:", "Depends On:",
Style::default().fg(theme.accent), // Use accent color for the label Style::default().fg(theme.accent), // Use accent color for the label
))); )));
if !selected_table_deps.is_empty() { if !selected_table_deps.is_empty() {
@@ -216,10 +216,27 @@ pub fn render_admin_panel_admin(
].as_ref()) ].as_ref())
.split(buttons_area); .split(buttons_area);
let btn_style = Style::default().fg(theme.secondary); // Style for button text let btn_base_style = Style::default().fg(theme.secondary);
let btn1 = Paragraph::new("Add Logic").style(btn_style).alignment(Alignment::Center);
let btn2 = Paragraph::new("Add Table").style(btn_style).alignment(Alignment::Center); // Define the helper closure to get style based on focus
let btn3 = Paragraph::new("Change Table").style(btn_style).alignment(Alignment::Center); let get_btn_style = |button_focus: AdminFocus| {
if admin_state.current_focus == button_focus {
// Apply highlight style if this button is focused
btn_base_style.add_modifier(ratatui::style::Modifier::REVERSED)
} else {
btn_base_style // Use base style otherwise
}
};
let btn1 = Paragraph::new("Add Logic")
.style(get_btn_style(AdminFocus::Button1))
.alignment(Alignment::Center);
let btn2 = Paragraph::new("Add Table")
.style(get_btn_style(AdminFocus::Button2))
.alignment(Alignment::Center);
let btn3 = Paragraph::new("Change Table")
.style(get_btn_style(AdminFocus::Button3))
.alignment(Alignment::Center);
f.render_widget(btn1, button_chunks[0]); f.render_widget(btn1, button_chunks[0]);
f.render_widget(btn2, button_chunks[1]); f.render_widget(btn2, button_chunks[1]);
f.render_widget(btn3, button_chunks[2]); f.render_widget(btn3, button_chunks[2]);

View File

@@ -43,6 +43,7 @@ pub fn handle_admin_navigation(
} }
} }
} }
AdminFocus::Button1 | AdminFocus::Button2 | AdminFocus::Button3 => {}
} }
true // Event handled true // Event handled
} }
@@ -66,6 +67,7 @@ pub fn handle_admin_navigation(
} }
} }
} }
AdminFocus::Button1 | AdminFocus::Button2 | AdminFocus::Button3 => {}
} }
true // Event handled true // Event handled
} }
@@ -73,26 +75,44 @@ pub fn handle_admin_navigation(
// --- Horizontal Navigation (Focus Change) --- // --- Horizontal Navigation (Focus Change) ---
Some("next_option") | Some("previous_option") => { Some("next_option") | Some("previous_option") => {
let old_focus = admin_state.current_focus; let old_focus = admin_state.current_focus;
admin_state.toggle_focus(); let is_next = action == Some("next_option"); // Check if 'l' or 'h'
admin_state.current_focus = match old_focus {
AdminFocus::Profiles => if is_next { AdminFocus::Tables } else { AdminFocus::Button3 }, // P -> T (l) or P -> B3 (h)
AdminFocus::Tables => if is_next { AdminFocus::Button1 } else { AdminFocus::Profiles }, // T -> B1 (l) or T -> P (h)
AdminFocus::Button1 => if is_next { AdminFocus::Button2 } else { AdminFocus::Tables }, // B1 -> B2 (l) or B1 -> T (h)
AdminFocus::Button2 => if is_next { AdminFocus::Button3 } else { AdminFocus::Button1 }, // B2 -> B3 (l) or B2 -> B1 (h)
AdminFocus::Button3 => if is_next { AdminFocus::Profiles } else { AdminFocus::Button2 }, // B3 -> P (l) or B3 -> B2 (h)
};
let new_focus = admin_state.current_focus; let new_focus = admin_state.current_focus;
*command_message = format!("Focus set to {:?}", new_focus); *command_message = format!("Focus set to {:?}", new_focus);
// Auto-select first item only when moving from Profiles to Tables via 'l'
// If focus moved TO Tables, select the first item for navigation if old_focus == AdminFocus::Profiles && new_focus == AdminFocus::Tables && is_next {
if old_focus == AdminFocus::Profiles && new_focus == AdminFocus::Tables { if let Some(profile_idx) = admin_state.profile_list_state.selected() {
if let Some(profile_idx) = admin_state.profile_list_state.selected() { // Use nav state if let Some(profile) = app_state.profile_tree.profiles.get(profile_idx) {
if let Some(profile) = app_state.profile_tree.profiles.get(profile_idx) { if !profile.tables.is_empty() {
if !profile.tables.is_empty() { admin_state.table_list_state.select(Some(0));
admin_state.table_list_state.select(Some(0)); } else {
} else { admin_state.table_list_state.select(None);
admin_state.table_list_state.select(None); }
} } else {
} else { admin_state.table_list_state.select(None);
admin_state.table_list_state.select(None); }
} } else {
} else { admin_state.table_list_state.select(None);
admin_state.table_list_state.select(None); }
}
} }
// Clear table nav selection if moving away from Tables
if old_focus == AdminFocus::Tables && new_focus != AdminFocus::Tables {
admin_state.table_list_state.select(None);
}
// Clear profile nav selection if moving away from Profiles
if old_focus == AdminFocus::Profiles && new_focus != AdminFocus::Profiles {
// Maybe keep profile nav highlight? Let's try clearing it.
// admin_state.profile_list_state.select(None); // Optional: clear profile nav highlight
}
true // Event handled true // Event handled
} }
@@ -104,8 +124,8 @@ pub fn handle_admin_navigation(
if let Some(nav_idx) = admin_state.profile_list_state.selected() { if let Some(nav_idx) = admin_state.profile_list_state.selected() {
admin_state.selected_profile_index = Some(nav_idx); // Set persistent selection admin_state.selected_profile_index = Some(nav_idx); // Set persistent selection
// Move focus to Tables // Move focus to Tables (like pressing 'l')
admin_state.toggle_focus(); // Move focus admin_state.current_focus = AdminFocus::Tables;
// Select the first table for navigation highlight // Select the first table for navigation highlight
admin_state.table_list_state.select(None); // Clear table nav first admin_state.table_list_state.select(None); // Clear table nav first
@@ -132,6 +152,18 @@ pub fn handle_admin_navigation(
} }
// We don't change focus here for now. // We don't change focus here for now.
} }
AdminFocus::Button1 => {
*command_message = "Action: Add Logic (Not Implemented)".to_string();
// TODO: Trigger action for Button 1
}
AdminFocus::Button2 => {
*command_message = "Action: Add Table (Not Implemented)".to_string();
// TODO: Trigger action for Button 2
}
AdminFocus::Button3 => {
*command_message = "Action: Change Table (Not Implemented)".to_string();
// TODO: Trigger action for Button 3
}
} }
true // Event handled true // Event handled
} }
@@ -146,4 +178,3 @@ pub fn handle_admin_navigation(
_ => false, // Event not handled by admin navigation _ => false, // Event not handled by admin navigation
} }
} }

View File

@@ -8,6 +8,9 @@ pub enum AdminFocus {
#[default] // Default focus is on the profiles list #[default] // Default focus is on the profiles list
Profiles, Profiles,
Tables, Tables,
Button1,
Button2,
Button3,
} }
#[derive(Default, Clone, Debug)] #[derive(Default, Clone, Debug)]
@@ -169,14 +172,5 @@ impl AdminState {
}; };
self.select_table(Some(i)); self.select_table(Some(i));
} }
/// Toggles focus between the profile list and the table list.
pub fn toggle_focus(&mut self) {
self.current_focus = match self.current_focus {
AdminFocus::Profiles => AdminFocus::Tables,
AdminFocus::Tables => AdminFocus::Profiles,
};
}
} }