needs bug fixing
This commit is contained in:
@@ -1,21 +1,49 @@
|
|||||||
// src/components/admin/admin_panel.rs
|
// src/components/admin/admin_panel.rs
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||||
style::Style,
|
style::Style,
|
||||||
text::{Line, Span},
|
text::{Line, Span, Text},
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||||
use crate::config::colors::Theme;
|
use crate::config::colors::Theme;
|
||||||
|
|
||||||
pub struct AdminPanelState;
|
pub struct AdminPanelState {
|
||||||
|
pub list_state: ListState,
|
||||||
|
pub profiles: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
impl AdminPanelState {
|
impl AdminPanelState {
|
||||||
pub fn new() -> Self {
|
pub fn new(profiles: Vec<String>) -> Self {
|
||||||
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()
|
let block = Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
@@ -27,18 +55,64 @@ impl AdminPanelState {
|
|||||||
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([Constraint::Length(3), Constraint::Min(1)])
|
||||||
Constraint::Length(3), // Title
|
|
||||||
Constraint::Min(1), // Content
|
|
||||||
])
|
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
|
// Title
|
||||||
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
||||||
let title_para = Paragraph::new(title)
|
Paragraph::new(title)
|
||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center)
|
||||||
f.render_widget(title_para, chunks[0]);
|
.render(f, chunks[0]);
|
||||||
|
|
||||||
let content = Paragraph::new("Admin panel content goes here");
|
// Content
|
||||||
f.render_widget(content, chunks[1]);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,41 +26,51 @@ pub fn calculate_sidebar_layout(show_sidebar: bool, main_content_area: Rect) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_sidebar(f: &mut Frame, area: Rect, theme: &Theme, profile_tree: &ProfileTreeResponse) {
|
pub fn render_sidebar(
|
||||||
let sidebar_block = Block::default()
|
f: &mut Frame,
|
||||||
.style(Style::default().bg(theme.bg));
|
area: Rect,
|
||||||
|
theme: &Theme,
|
||||||
|
profile_tree: &ProfileTreeResponse,
|
||||||
|
selected_profile: &Option<String>,
|
||||||
|
) {
|
||||||
|
let sidebar_block = Block::default().style(Style::default().bg(theme.bg));
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
|
|
||||||
for profile in &profile_tree.profiles {
|
if let Some(profile_name) = selected_profile {
|
||||||
// Profile header
|
if let Some(profile) = profile_tree.profiles.iter()
|
||||||
items.push(ListItem::new(Line::from(vec![
|
.find(|p| &p.name == profile_name)
|
||||||
Span::styled("📁 ", Style::default().fg(theme.accent)),
|
{
|
||||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
// Profile header
|
||||||
])));
|
|
||||||
|
|
||||||
// Profile tables
|
|
||||||
for (table_idx, table) in profile.tables.iter().enumerate() {
|
|
||||||
let is_last_table = table_idx == profile.tables.len() - 1;
|
|
||||||
let tree_prefix = if is_last_table { "└─ " } else { "├─ " };
|
|
||||||
|
|
||||||
// Table name
|
|
||||||
items.push(ListItem::new(Line::from(vec![
|
items.push(ListItem::new(Line::from(vec![
|
||||||
Span::styled(format!(" {}", tree_prefix), Style::default().fg(theme.fg)),
|
Span::styled("📁 ", Style::default().fg(theme.accent)),
|
||||||
Span::styled(&table.name, Style::default().fg(theme.fg)),
|
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
||||||
])));
|
])));
|
||||||
|
|
||||||
// Dependencies
|
// Tables
|
||||||
if !table.depends_on.is_empty() {
|
for (table_idx, table) in profile.tables.iter().enumerate() {
|
||||||
let dep_prefix = if is_last_table { " " } else { "│ " };
|
let is_last = table_idx == profile.tables.len() - 1;
|
||||||
let deps = table.depends_on.join(", ");
|
let prefix = if is_last { "└─ " } else { "├─ " };
|
||||||
|
|
||||||
items.push(ListItem::new(Line::from(vec![
|
let mut line = vec![
|
||||||
Span::styled(format!(" {} └─ ", dep_prefix), Style::default().fg(theme.secondary)),
|
Span::styled(format!(" {}", prefix), Style::default().fg(theme.fg)),
|
||||||
Span::styled(format!("→ {}", deps), Style::default().fg(theme.secondary)),
|
Span::styled(&table.name, Style::default().fg(theme.fg)),
|
||||||
])));
|
];
|
||||||
|
|
||||||
|
if !table.depends_on.is_empty() {
|
||||||
|
line.push(Span::styled(
|
||||||
|
format!(" → {}", table.depends_on.join(", ")),
|
||||||
|
Style::default().fg(theme.secondary)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push(ListItem::new(Line::from(line)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
items.push(ListItem::new(Span::styled(
|
||||||
|
"No profile selected",
|
||||||
|
Style::default().fg(theme.secondary)
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let list = List::new(items)
|
let list = List::new(items)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub struct AppState {
|
|||||||
pub total_count: u64,
|
pub total_count: u64,
|
||||||
pub current_position: u64,
|
pub current_position: u64,
|
||||||
pub profile_tree: ProfileTreeResponse,
|
pub profile_tree: ProfileTreeResponse,
|
||||||
|
pub selected_profile: Option<String>,
|
||||||
|
|
||||||
// UI preferences
|
// UI preferences
|
||||||
pub ui: UiState,
|
pub ui: UiState,
|
||||||
|
|||||||
Reference in New Issue
Block a user