Show vertical scrollbar only if height is lower than total monitors
This commit is contained in:
parent
d4e3ce6e27
commit
142f76684b
3 changed files with 105 additions and 63 deletions
|
|
@ -1,8 +1,11 @@
|
|||
use crate::core::models::{UnifiedData, UnifiedGroupData};
|
||||
use crate::data::heartbeat::model::HeartbeatEntry;
|
||||
use crate::i18n::t;
|
||||
use ratatui::widgets::ScrollbarState;
|
||||
use rayon::prelude::*;
|
||||
|
||||
const BORDER_LINES_VIEW: usize = 3;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum MonitorStatus {
|
||||
Up,
|
||||
|
|
@ -33,6 +36,7 @@ pub struct DashboardViewState {
|
|||
pub is_loading: bool,
|
||||
pub error_message: Option<String>,
|
||||
pub auto_refresh_interval: u32,
|
||||
pub scroll_state: ScrollbarState,
|
||||
}
|
||||
|
||||
impl DashboardViewState {
|
||||
|
|
@ -44,6 +48,7 @@ impl DashboardViewState {
|
|||
is_loading: true,
|
||||
error_message: None,
|
||||
auto_refresh_interval: 300,
|
||||
scroll_state: ScrollbarState::new(0),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,6 +62,11 @@ impl DashboardViewState {
|
|||
});
|
||||
}
|
||||
|
||||
let content_length = groups
|
||||
.iter()
|
||||
.map(|g| g.monitors.len() + BORDER_LINES_VIEW)
|
||||
.sum::<usize>();
|
||||
|
||||
Self {
|
||||
title: data.title,
|
||||
descriptions: data.description,
|
||||
|
|
@ -64,12 +74,17 @@ impl DashboardViewState {
|
|||
is_loading: false,
|
||||
error_message: None,
|
||||
auto_refresh_interval: data.auto_refresh_interval.max(30),
|
||||
scroll_state: ScrollbarState::new(content_length.saturating_sub(1)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_monitors(&self) -> Vec<&MonitorViewState> {
|
||||
self.groups.iter().flat_map(|g| g.monitors.iter()).collect()
|
||||
}
|
||||
|
||||
pub fn show_vertical_scrollbar(&self, height: u16) -> bool {
|
||||
height < self.get_all_monitors().len() as u16
|
||||
}
|
||||
}
|
||||
|
||||
fn get_status_history(heartbeats: &[HeartbeatEntry]) -> Vec<MonitorStatus> {
|
||||
|
|
@ -94,36 +109,39 @@ fn get_status_history(heartbeats: &[HeartbeatEntry]) -> Vec<MonitorStatus> {
|
|||
|
||||
fn add_monitor_view_state(group: UnifiedGroupData) -> Vec<MonitorViewState> {
|
||||
let mut monitors = Vec::with_capacity(group.monitors.len());
|
||||
group.monitors.into_par_iter().map(|monitor| {
|
||||
group
|
||||
.monitors
|
||||
.into_par_iter()
|
||||
.map(|monitor| {
|
||||
let status_history = get_status_history(&monitor.heartbeats);
|
||||
|
||||
let status_history = get_status_history(&monitor.heartbeats);
|
||||
let status = match monitor.heartbeats.last().map(|h| h.status) {
|
||||
Some(1) => MonitorStatus::Up,
|
||||
Some(0) => MonitorStatus::Down,
|
||||
_ => MonitorStatus::Unknown,
|
||||
};
|
||||
|
||||
let status = match monitor.heartbeats.last().map(|h| h.status) {
|
||||
Some(1) => MonitorStatus::Up,
|
||||
Some(0) => MonitorStatus::Down,
|
||||
_ => MonitorStatus::Unknown,
|
||||
};
|
||||
let response_time = monitor
|
||||
.heartbeats
|
||||
.last()
|
||||
.and_then(|h| h.ping)
|
||||
.map(|ms| format!("{}", ms))
|
||||
.unwrap_or_else(|| t("unknown").to_string() + " ");
|
||||
|
||||
let response_time = monitor
|
||||
.heartbeats
|
||||
.last()
|
||||
.and_then(|h| h.ping)
|
||||
.map(|ms| format!("{}", ms))
|
||||
.unwrap_or_else(|| t("unknown").to_string() + " ");
|
||||
let uptime_24h = monitor
|
||||
.uptime_data
|
||||
.map(|u| u.get_perc_formated())
|
||||
.unwrap_or_else(|| t("unknown").to_string());
|
||||
|
||||
let uptime_24h = monitor
|
||||
.uptime_data
|
||||
.map(|u| u.get_perc_formated())
|
||||
.unwrap_or_else(|| t("unknown").to_string());
|
||||
|
||||
MonitorViewState {
|
||||
name: monitor.name,
|
||||
status,
|
||||
response_time,
|
||||
uptime_24h,
|
||||
status_history,
|
||||
}
|
||||
}).collect_into_vec(&mut monitors);
|
||||
MonitorViewState {
|
||||
name: monitor.name,
|
||||
status,
|
||||
response_time,
|
||||
uptime_24h,
|
||||
status_history,
|
||||
}
|
||||
})
|
||||
.collect_into_vec(&mut monitors);
|
||||
|
||||
monitors.sort_by_key(|m| m.name.clone());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue