admin panel now distinguish admin and other roles of the user
This commit is contained in:
@@ -12,6 +12,16 @@ use ratatui::{
|
|||||||
Frame,
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_admin_panel(
|
pub fn render_admin_panel(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
auth_state: &AuthState,
|
auth_state: &AuthState,
|
||||||
@@ -47,66 +57,81 @@ pub fn render_admin_panel(
|
|||||||
.split(chunks[1]);
|
.split(chunks[1]);
|
||||||
|
|
||||||
if auth_state.role.as_deref() != Some("admin") {
|
if auth_state.role.as_deref() != Some("admin") {
|
||||||
// Profile list - Use data from admin_state
|
render_admin_panel_non_admin(
|
||||||
let items: Vec<ListItem> = admin_state
|
f,
|
||||||
.profiles
|
admin_state,
|
||||||
.iter()
|
&content_chunks,
|
||||||
.map(|p| {
|
theme,
|
||||||
ListItem::new(Line::from(vec![
|
profile_tree,
|
||||||
Span::styled(
|
selected_profile,
|
||||||
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
);
|
||||||
Style::default().fg(theme.accent),
|
|
||||||
),
|
|
||||||
Span::styled(p, Style::default().fg(theme.fg)),
|
|
||||||
]))
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let list = List::new(items)
|
|
||||||
.block(Block::default().title("Profiles"))
|
|
||||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
|
||||||
|
|
||||||
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()
|
|
||||||
.and_then(|i| profile_tree.profiles.get(i))
|
|
||||||
{
|
|
||||||
let mut text = Text::default();
|
|
||||||
text.lines.push(Line::from(vec![
|
|
||||||
Span::styled("Profile: ", Style::default().fg(theme.accent)),
|
|
||||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
|
||||||
]));
|
|
||||||
|
|
||||||
text.lines.push(Line::from(""));
|
|
||||||
text.lines.push(Line::from(Span::styled(
|
|
||||||
"Tables:",
|
|
||||||
Style::default().fg(theme.accent),
|
|
||||||
)));
|
|
||||||
|
|
||||||
for table in &profile.tables {
|
|
||||||
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
|
|
||||||
if !table.depends_on.is_empty() {
|
|
||||||
line.push(Span::styled(
|
|
||||||
format!(" → {}", table.depends_on.join(", ")),
|
|
||||||
Style::default().fg(theme.secondary),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
text.lines.push(Line::from(line));
|
|
||||||
}
|
|
||||||
|
|
||||||
let details_widget = Paragraph::new(text)
|
|
||||||
.block(Block::default().title("Details"))
|
|
||||||
.wrap(Wrap { trim: true });
|
|
||||||
f.render_widget(details_widget, content_chunks[1]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Admin-specific view
|
render_admin_panel_admin(f, &content_chunks, theme);
|
||||||
let admin_message = Paragraph::new("Admin-specific view. Profile selection not applicable.")
|
}
|
||||||
.style(Style::default().fg(theme.fg))
|
}
|
||||||
.alignment(Alignment::Center);
|
|
||||||
f.render_widget(admin_message, content_chunks[1]);
|
/// 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
|
||||||
|
.iter()
|
||||||
|
.map(|p| {
|
||||||
|
ListItem::new(Line::from(vec![
|
||||||
|
Span::styled(
|
||||||
|
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
||||||
|
Style::default().fg(theme.accent),
|
||||||
|
),
|
||||||
|
Span::styled(p, Style::default().fg(theme.fg)),
|
||||||
|
]))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let list = List::new(items)
|
||||||
|
.block(Block::default().title("Profiles"))
|
||||||
|
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
||||||
|
|
||||||
|
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()
|
||||||
|
.and_then(|i| profile_tree.profiles.get(i))
|
||||||
|
{
|
||||||
|
let mut text = Text::default();
|
||||||
|
text.lines.push(Line::from(vec![
|
||||||
|
Span::styled("Profile: ", Style::default().fg(theme.accent)),
|
||||||
|
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
||||||
|
]));
|
||||||
|
|
||||||
|
text.lines.push(Line::from(""));
|
||||||
|
text.lines.push(Line::from(Span::styled(
|
||||||
|
"Tables:",
|
||||||
|
Style::default().fg(theme.accent),
|
||||||
|
)));
|
||||||
|
|
||||||
|
for table in &profile.tables {
|
||||||
|
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
|
||||||
|
if !table.depends_on.is_empty() {
|
||||||
|
line.push(Span::styled(
|
||||||
|
format!(" → {}", table.depends_on.join(", ")),
|
||||||
|
Style::default().fg(theme.secondary),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
text.lines.push(Line::from(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
let details_widget = Paragraph::new(text)
|
||||||
|
.block(Block::default().title("Details"))
|
||||||
|
.wrap(Wrap { trim: true });
|
||||||
|
f.render_widget(details_widget, content_chunks[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user