needs bug fixing
This commit is contained in:
@@ -1,21 +1,49 @@
|
||||
// src/components/admin/admin_panel.rs
|
||||
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||
style::Style,
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
text::{Line, Span, Text},
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
Frame,
|
||||
};
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::config::colors::Theme;
|
||||
|
||||
pub struct AdminPanelState;
|
||||
pub struct AdminPanelState {
|
||||
pub list_state: ListState,
|
||||
pub profiles: Vec<String>,
|
||||
}
|
||||
|
||||
impl AdminPanelState {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
pub fn new(profiles: Vec<String>) -> Self {
|
||||
let mut list_state = ListState::default();
|
||||
if !profiles.is_empty() {
|
||||
list_state.select(Some(0));
|
||||
}
|
||||
Self { list_state, profiles }
|
||||
}
|
||||
|
||||
pub fn render(&self, f: &mut Frame, area: Rect, theme: &Theme) {
|
||||
pub fn next(&mut self) {
|
||||
let i = self.list_state.selected().map_or(0, |i|
|
||||
if i >= self.profiles.len() - 1 { 0 } else { i + 1 });
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
|
||||
pub fn previous(&mut self) {
|
||||
let i = self.list_state.selected().map_or(0, |i|
|
||||
if i == 0 { self.profiles.len() - 1 } else { i - 1 });
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
&mut self,
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
profile_tree: &ProfileTreeResponse,
|
||||
selected_profile: &Option<String>,
|
||||
) {
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
@@ -27,18 +55,64 @@ impl AdminPanelState {
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(3), // Title
|
||||
Constraint::Min(1), // Content
|
||||
])
|
||||
.constraints([Constraint::Length(3), Constraint::Min(1)])
|
||||
.split(inner_area);
|
||||
|
||||
// Title
|
||||
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
||||
let title_para = Paragraph::new(title)
|
||||
.alignment(Alignment::Center);
|
||||
f.render_widget(title_para, chunks[0]);
|
||||
Paragraph::new(title)
|
||||
.alignment(Alignment::Center)
|
||||
.render(f, chunks[0]);
|
||||
|
||||
let content = Paragraph::new("Admin panel content goes here");
|
||||
f.render_widget(content, chunks[1]);
|
||||
// Content
|
||||
let content_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||
.split(chunks[1]);
|
||||
|
||||
// Profile list
|
||||
let items: Vec<ListItem> = self.profiles.iter()
|
||||
.map(|p| ListItem::new(Line::from(vec![
|
||||
Span::styled(
|
||||
if Some(p) == selected_profile { "✓ " } else { " " },
|
||||
Style::default().fg(theme.accent)
|
||||
),
|
||||
Span::styled(p, Style::default().fg(theme.fg)),
|
||||
])))
|
||||
.collect();
|
||||
|
||||
List::new(items)
|
||||
.block(Block::default().title("Profiles"))
|
||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg))
|
||||
.render_stateful(f, content_chunks[0], &mut self.list_state);
|
||||
|
||||
// Profile details
|
||||
if let Some(profile) = self.list_state.selected()
|
||||
.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));
|
||||
}
|
||||
|
||||
Paragraph::new(text)
|
||||
.block(Block::default().title("Details"))
|
||||
.render(f, content_chunks[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user