admin panel from scratch
This commit is contained in:
@@ -11,16 +11,7 @@ use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph, Wrap},
|
||||
Frame,
|
||||
};
|
||||
|
||||
/// 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]);
|
||||
}
|
||||
use super::admin_panel_admin::render_admin_panel_admin;
|
||||
|
||||
pub fn render_admin_panel(
|
||||
f: &mut Frame,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// src/components/admin/admin_panel_admin.rs
|
||||
|
||||
// Add necessary imports that were previously in admin_panel.rs
|
||||
// and are used by this function
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::pages::admin::{AdminFocus, AdminState};
|
||||
use crate::state::app::state::AppState;
|
||||
@@ -14,114 +12,11 @@ use ratatui::{
|
||||
};
|
||||
|
||||
/// Renders the view specific to admin users.
|
||||
/// Implements the two-pane layout for profile and table browsing.
|
||||
// Make it public (`pub`) if called from outside this module,
|
||||
// or keep it private (no `pub`) if only called from admin_panel.rs
|
||||
// For now, let's assume it's only called from admin_panel.rs
|
||||
pub(super) fn render_admin_panel_admin( // Use pub(super) or pub based on need
|
||||
f: &mut Frame,
|
||||
admin_state: &mut AdminState,
|
||||
app_state: &AppState,
|
||||
content_chunks: &[Rect],
|
||||
theme: &Theme,
|
||||
) {
|
||||
let profile_tree = &app_state.profile_tree;
|
||||
let selected_profile_index = admin_state.get_selected_profile_index();
|
||||
|
||||
// --- Profile List (Left Pane) ---
|
||||
let profile_items: Vec<ListItem> = profile_tree
|
||||
.profiles
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, p)| {
|
||||
let is_selected = selected_profile_index == Some(i);
|
||||
let style = if is_selected && admin_state.current_focus == AdminFocus::Profiles {
|
||||
Style::default().fg(theme.bg).bg(theme.highlight)
|
||||
} else if is_selected {
|
||||
Style::default().fg(theme.fg).bg(theme.inactive_highlight_bg)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
ListItem::new(Line::from(Span::styled(&p.name, style)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let profile_list_block = Block::default()
|
||||
.title(" Profiles ")
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Plain)
|
||||
.border_style(if admin_state.current_focus == AdminFocus::Profiles {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.border)
|
||||
});
|
||||
|
||||
let profile_list = List::new(profile_items).block(profile_list_block);
|
||||
|
||||
f.render_stateful_widget(
|
||||
profile_list,
|
||||
content_chunks[0],
|
||||
&mut admin_state.profile_list_state,
|
||||
);
|
||||
|
||||
// --- Table List & Details (Right Pane) ---
|
||||
let table_list_block = Block::default()
|
||||
.title(" Tables & Dependencies ")
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Plain)
|
||||
.border_style(if admin_state.current_focus == AdminFocus::Tables {
|
||||
Style::default().fg(theme.accent)
|
||||
} else {
|
||||
Style::default().fg(theme.border)
|
||||
});
|
||||
|
||||
if let Some(profile_idx) = selected_profile_index {
|
||||
if let Some(profile) = profile_tree.profiles.get(profile_idx) {
|
||||
let selected_table_index = admin_state.get_selected_table_index();
|
||||
let table_items: Vec<ListItem> = profile
|
||||
.tables
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, table)| {
|
||||
let is_selected = selected_table_index == Some(i);
|
||||
let base_style = if is_selected && admin_state.current_focus == AdminFocus::Tables {
|
||||
Style::default().fg(theme.bg).bg(theme.highlight)
|
||||
} else if is_selected {
|
||||
Style::default().fg(theme.fg).bg(theme.inactive_highlight_bg)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
};
|
||||
|
||||
let mut line_spans = vec![Span::styled(&table.name, base_style)];
|
||||
if !table.depends_on.is_empty() {
|
||||
line_spans.push(Span::styled(" -> ", base_style.fg(theme.secondary)));
|
||||
line_spans.push(Span::styled(
|
||||
format!("[{}]", table.depends_on.join(", ")),
|
||||
base_style.fg(theme.secondary),
|
||||
));
|
||||
}
|
||||
ListItem::new(Line::from(line_spans))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let table_list = List::new(table_items);
|
||||
|
||||
f.render_stateful_widget(
|
||||
table_list.block(table_list_block),
|
||||
content_chunks[1],
|
||||
&mut admin_state.table_list_state,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let placeholder = Paragraph::new("Select a profile to see tables.")
|
||||
.style(Style::default().fg(theme.secondary))
|
||||
pub 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);
|
||||
|
||||
f.render_widget(
|
||||
placeholder.block(table_list_block),
|
||||
content_chunks[1],
|
||||
);
|
||||
// Render only in the right pane for now, leaving left empty
|
||||
f.render_widget(admin_message, content_chunks[1]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user