Close to the ui final version
This commit is contained in:
parent
d614ec4d18
commit
b130c4550d
9 changed files with 46 additions and 69 deletions
|
|
@ -3,21 +3,16 @@ use crate::ui::dashboard::model::DashboardViewState;
|
|||
use crate::ui::dashboard::{MonitorStatus, MonitorViewState};
|
||||
use ratatui::{
|
||||
Frame,
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
layout::{Constraint, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, List, ListItem, Row, Table, TableState},
|
||||
widgets::{Block, Borders, Row, Table},
|
||||
};
|
||||
|
||||
const STATUS_LINE_LENGTH: usize = 100;
|
||||
const MAX_NAME_LENGTH: usize = 30;
|
||||
|
||||
pub fn render_monitor_list(
|
||||
frame: &mut Frame,
|
||||
area: Rect,
|
||||
state: &DashboardViewState,
|
||||
list_state: &mut TableState,
|
||||
) {
|
||||
pub fn render_monitor_list(frame: &mut Frame, area: Rect, state: &DashboardViewState) {
|
||||
let block = Block::default()
|
||||
.title(t("monitors"))
|
||||
.borders(Borders::ALL)
|
||||
|
|
@ -45,8 +40,7 @@ pub fn render_monitor_list(
|
|||
.monitors
|
||||
.iter()
|
||||
.take(visible_items)
|
||||
.enumerate()
|
||||
.map(|(i, m)| create_monitor_item(m, list_state.selected() == Some(i)))
|
||||
.map(|m| create_monitor_item(m))
|
||||
.collect();
|
||||
|
||||
let table = Table::new(rows, constraints)
|
||||
|
|
@ -56,7 +50,7 @@ pub fn render_monitor_list(
|
|||
.highlight_symbol(">> ")
|
||||
.row_highlight_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
|
||||
frame.render_stateful_widget(table, area, list_state);
|
||||
frame.render_widget(table, area);
|
||||
}
|
||||
|
||||
pub fn get_status_char(status: &MonitorStatus) -> char {
|
||||
|
|
@ -83,7 +77,7 @@ pub fn get_status_emoji(status: &MonitorStatus) -> &str {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_monitor_item(monitor: &MonitorViewState, item_selected: bool) -> Row<'_> {
|
||||
fn create_monitor_item(monitor: &MonitorViewState) -> Row<'_> {
|
||||
let status_icon = get_status_emoji(&monitor.status);
|
||||
let status_color = get_status_color(&monitor.status);
|
||||
|
||||
|
|
@ -95,35 +89,55 @@ fn create_monitor_item(monitor: &MonitorViewState, item_selected: bool) -> Row<'
|
|||
|
||||
let response_text = format!("{:>7}ms", monitor.response_time);
|
||||
let uptime_text = format!("{:>7}%", monitor.uptime_24h);
|
||||
let status_line = create_status_line_text(&monitor.status_history);
|
||||
|
||||
let style = if item_selected {
|
||||
Style::default().add_modifier(Modifier::REVERSED)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
let status_line_spans = create_status_line_spans(&monitor.status_history);
|
||||
|
||||
Row::new(vec![
|
||||
format!("{} ", status_icon),
|
||||
display_name,
|
||||
response_text,
|
||||
uptime_text,
|
||||
format!("(1h) {} ({})", status_line, t("now")),
|
||||
get_formated_line(format!("{} ", status_icon), status_color, Modifier::empty()),
|
||||
get_formated_line(display_name, Color::White, Modifier::empty()),
|
||||
get_formated_line(response_text, Color::Cyan, Modifier::empty()),
|
||||
get_formated_line(uptime_text, Color::Magenta, Modifier::empty()),
|
||||
status_line_spans,
|
||||
])
|
||||
.style(style)
|
||||
.style(Style::default())
|
||||
.height(1)
|
||||
}
|
||||
|
||||
fn create_status_line_text(status_history: &[MonitorStatus]) -> String {
|
||||
let mut line = String::new();
|
||||
fn get_formated_line(text: String, color: Color, modifier: Modifier) -> Line<'static> {
|
||||
Line::from(vec![Span::styled(
|
||||
text,
|
||||
Style::default().fg(color).add_modifier(modifier),
|
||||
)])
|
||||
}
|
||||
|
||||
fn create_status_line_spans(status_history: &[MonitorStatus]) -> Line<'_> {
|
||||
let mut spans = Vec::new();
|
||||
let recent_status: Vec<_> = status_history
|
||||
.iter()
|
||||
.rev()
|
||||
.take(STATUS_LINE_LENGTH)
|
||||
.collect();
|
||||
|
||||
spans.push(Span::styled(
|
||||
"(1h)",
|
||||
Style::default()
|
||||
.fg(Color::Gray)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
));
|
||||
spans.push(Span::raw(" "));
|
||||
|
||||
for status in recent_status.iter().rev() {
|
||||
line.push(get_status_char(status));
|
||||
let c = get_status_char(status);
|
||||
let color = get_status_color(status);
|
||||
|
||||
spans.push(Span::styled(c.to_string(), Style::default().fg(color)));
|
||||
}
|
||||
line
|
||||
spans.push(Span::raw(" "));
|
||||
spans.push(Span::styled(
|
||||
t("now"),
|
||||
Style::default()
|
||||
.fg(Color::Gray)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
));
|
||||
Line::from(spans)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue