Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e890c5e810 | |||
| 078c30a592 | |||
| a847674004 | |||
| 2618f6b62f | |||
| c3fc5a181d | |||
| 3f45a172b3 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.25"
|
version = "0.1.31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -291,7 +291,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.25"
|
version = "0.1.31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -314,7 +314,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.25"
|
version = "0.1.31"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.26"
|
version = "0.1.32"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -274,7 +274,6 @@ impl Agent {
|
|||||||
let action_str = match action {
|
let action_str = match action {
|
||||||
ServiceAction::Start => "start",
|
ServiceAction::Start => "start",
|
||||||
ServiceAction::Stop => "stop",
|
ServiceAction::Stop => "stop",
|
||||||
ServiceAction::Restart => "restart",
|
|
||||||
ServiceAction::Status => "status",
|
ServiceAction::Status => "status",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -299,7 +298,7 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Force refresh metrics after service control to update service status
|
// Force refresh metrics after service control to update service status
|
||||||
if matches!(action, ServiceAction::Start | ServiceAction::Stop | ServiceAction::Restart) {
|
if matches!(action, ServiceAction::Start | ServiceAction::Stop) {
|
||||||
info!("Triggering immediate metric refresh after service control");
|
info!("Triggering immediate metric refresh after service control");
|
||||||
if let Err(e) = self.collect_metrics_only().await {
|
if let Err(e) = self.collect_metrics_only().await {
|
||||||
error!("Failed to refresh metrics after service control: {}", e);
|
error!("Failed to refresh metrics after service control: {}", e);
|
||||||
|
|||||||
@@ -136,8 +136,21 @@ impl SystemdCollector {
|
|||||||
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
||||||
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
||||||
debug!("Starting systemd service discovery with status caching");
|
debug!("Starting systemd service discovery with status caching");
|
||||||
// Get all services (includes inactive, running, failed - everything)
|
|
||||||
let units_output = Command::new("systemctl")
|
// First: Get all service unit files (includes services that have never been started)
|
||||||
|
let unit_files_output = Command::new("systemctl")
|
||||||
|
.arg("list-unit-files")
|
||||||
|
.arg("--type=service")
|
||||||
|
.arg("--no-pager")
|
||||||
|
.arg("--plain")
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
if !unit_files_output.status.success() {
|
||||||
|
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second: Get runtime status of all units
|
||||||
|
let units_status_output = Command::new("systemctl")
|
||||||
.arg("list-units")
|
.arg("list-units")
|
||||||
.arg("--type=service")
|
.arg("--type=service")
|
||||||
.arg("--all")
|
.arg("--all")
|
||||||
@@ -145,22 +158,33 @@ impl SystemdCollector {
|
|||||||
.arg("--plain")
|
.arg("--plain")
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !units_output.status.success() {
|
if !units_status_output.status.success() {
|
||||||
return Err(anyhow::anyhow!("systemctl system command failed"));
|
return Err(anyhow::anyhow!("systemctl list-units command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let units_str = String::from_utf8(units_output.stdout)?;
|
let unit_files_str = String::from_utf8(unit_files_output.stdout)?;
|
||||||
|
let units_status_str = String::from_utf8(units_status_output.stdout)?;
|
||||||
let mut services = Vec::new();
|
let mut services = Vec::new();
|
||||||
|
|
||||||
// Use configuration instead of hardcoded values
|
// Use configuration instead of hardcoded values
|
||||||
let excluded_services = &self.config.excluded_services;
|
let excluded_services = &self.config.excluded_services;
|
||||||
let service_name_filters = &self.config.service_name_filters;
|
let service_name_filters = &self.config.service_name_filters;
|
||||||
|
|
||||||
// Parse all services and cache their status information
|
// Parse all service unit files to get complete service list
|
||||||
let mut all_service_names = std::collections::HashSet::new();
|
let mut all_service_names = std::collections::HashSet::new();
|
||||||
let mut status_cache = std::collections::HashMap::new();
|
|
||||||
|
|
||||||
for line in units_str.lines() {
|
for line in unit_files_str.lines() {
|
||||||
|
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||||
|
if fields.len() >= 2 && fields[0].ends_with(".service") {
|
||||||
|
let service_name = fields[0].trim_end_matches(".service");
|
||||||
|
all_service_names.insert(service_name.to_string());
|
||||||
|
debug!("Found service unit file: {}", service_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse runtime status for all units
|
||||||
|
let mut status_cache = std::collections::HashMap::new();
|
||||||
|
for line in units_status_str.lines() {
|
||||||
let fields: Vec<&str> = line.split_whitespace().collect();
|
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||||
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
||||||
let service_name = fields[0].trim_end_matches(".service");
|
let service_name = fields[0].trim_end_matches(".service");
|
||||||
@@ -177,8 +201,19 @@ impl SystemdCollector {
|
|||||||
sub_state: sub_state.clone(),
|
sub_state: sub_state.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
all_service_names.insert(service_name.to_string());
|
debug!("Got runtime status for service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
|
||||||
debug!("Parsed service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For services found in unit files but not in runtime status, set default inactive status
|
||||||
|
for service_name in &all_service_names {
|
||||||
|
if !status_cache.contains_key(service_name) {
|
||||||
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
|
load_state: "not-loaded".to_string(),
|
||||||
|
active_state: "inactive".to_string(),
|
||||||
|
sub_state: "dead".to_string(),
|
||||||
|
});
|
||||||
|
debug!("Service {} found in unit files but not runtime - marked as inactive", service_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,5 @@ pub enum AgentCommand {
|
|||||||
pub enum ServiceAction {
|
pub enum ServiceAction {
|
||||||
Start,
|
Start,
|
||||||
Stop,
|
Stop,
|
||||||
Restart,
|
|
||||||
Status,
|
Status,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.26"
|
version = "0.1.32"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -294,14 +294,6 @@ impl Dashboard {
|
|||||||
/// Execute a UI command by sending it to the appropriate agent
|
/// Execute a UI command by sending it to the appropriate agent
|
||||||
async fn execute_ui_command(&self, command: UiCommand) -> Result<()> {
|
async fn execute_ui_command(&self, command: UiCommand) -> Result<()> {
|
||||||
match command {
|
match command {
|
||||||
UiCommand::ServiceRestart { hostname, service_name } => {
|
|
||||||
info!("Sending restart command for service {} on {}", service_name, hostname);
|
|
||||||
let agent_command = AgentCommand::ServiceControl {
|
|
||||||
service_name,
|
|
||||||
action: ServiceAction::Restart,
|
|
||||||
};
|
|
||||||
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
|
|
||||||
}
|
|
||||||
UiCommand::ServiceStart { hostname, service_name } => {
|
UiCommand::ServiceStart { hostname, service_name } => {
|
||||||
info!("Sending start command for service {} on {}", service_name, hostname);
|
info!("Sending start command for service {} on {}", service_name, hostname);
|
||||||
let agent_command = AgentCommand::ServiceControl {
|
let agent_command = AgentCommand::ServiceControl {
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ pub enum AgentCommand {
|
|||||||
pub enum ServiceAction {
|
pub enum ServiceAction {
|
||||||
Start,
|
Start,
|
||||||
Stop,
|
Stop,
|
||||||
Restart,
|
|
||||||
Status,
|
Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use app::Dashboard;
|
|||||||
|
|
||||||
/// Get hardcoded version
|
/// Get hardcoded version
|
||||||
fn get_version() -> &'static str {
|
fn get_version() -> &'static str {
|
||||||
"v0.1.26"
|
"v0.1.32"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if running inside tmux session
|
/// Check if running inside tmux session
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget};
|
|||||||
/// Commands that can be triggered from the UI
|
/// Commands that can be triggered from the UI
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UiCommand {
|
pub enum UiCommand {
|
||||||
ServiceRestart { hostname: String, service_name: String },
|
|
||||||
ServiceStart { hostname: String, service_name: String },
|
ServiceStart { hostname: String, service_name: String },
|
||||||
ServiceStop { hostname: String, service_name: String },
|
ServiceStop { hostname: String, service_name: String },
|
||||||
TriggerBackup { hostname: String },
|
TriggerBackup { hostname: String },
|
||||||
@@ -32,7 +31,6 @@ pub enum UiCommand {
|
|||||||
/// Types of commands for status tracking
|
/// Types of commands for status tracking
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum CommandType {
|
pub enum CommandType {
|
||||||
ServiceRestart,
|
|
||||||
ServiceStart,
|
ServiceStart,
|
||||||
ServiceStop,
|
ServiceStop,
|
||||||
BackupTrigger,
|
BackupTrigger,
|
||||||
@@ -256,35 +254,20 @@ impl TuiApp {
|
|||||||
self.navigate_host(1);
|
self.navigate_host(1);
|
||||||
}
|
}
|
||||||
KeyCode::Char('r') => {
|
KeyCode::Char('r') => {
|
||||||
match self.focused_panel {
|
// System rebuild command - works on any panel for current host
|
||||||
PanelType::System => {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
// Simple tmux popup with SSH rebuild using configured user and alias
|
// Launch tmux popup with SSH using config values
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
let ssh_command = format!(
|
||||||
// Launch tmux popup with SSH using config values
|
"ssh -tt {}@{} 'bash -ic {}'",
|
||||||
let ssh_command = format!(
|
self.config.ssh.rebuild_user,
|
||||||
"ssh -tt {}@{} 'bash -ic {}'",
|
hostname,
|
||||||
self.config.ssh.rebuild_user,
|
self.config.ssh.rebuild_alias
|
||||||
hostname,
|
);
|
||||||
self.config.ssh.rebuild_alias
|
std::process::Command::new("tmux")
|
||||||
);
|
.arg("display-popup")
|
||||||
std::process::Command::new("tmux")
|
.arg(&ssh_command)
|
||||||
.arg("display-popup")
|
.spawn()
|
||||||
.arg(&ssh_command)
|
.ok(); // Ignore errors, tmux will handle them
|
||||||
.spawn()
|
|
||||||
.ok(); // Ignore errors, tmux will handle them
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PanelType::Services => {
|
|
||||||
// Service restart command
|
|
||||||
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
|
||||||
if self.start_command(&hostname, CommandType::ServiceRestart, service_name.clone()) {
|
|
||||||
return Ok(Some(UiCommand::ServiceRestart { hostname, service_name }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
info!("Manual refresh requested");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('s') => {
|
KeyCode::Char('s') => {
|
||||||
@@ -431,7 +414,6 @@ impl TuiApp {
|
|||||||
let should_execute = match (&command_type, current_status.as_deref()) {
|
let should_execute = match (&command_type, current_status.as_deref()) {
|
||||||
(CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true,
|
(CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true,
|
||||||
(CommandType::ServiceStop, Some("active")) => true,
|
(CommandType::ServiceStop, Some("active")) => true,
|
||||||
(CommandType::ServiceRestart, Some("active") | Some("inactive") | Some("failed") | Some("dead")) => true,
|
|
||||||
(CommandType::ServiceStart, Some("active")) => {
|
(CommandType::ServiceStart, Some("active")) => {
|
||||||
// Already running - don't execute
|
// Already running - don't execute
|
||||||
false
|
false
|
||||||
@@ -462,15 +444,9 @@ impl TuiApp {
|
|||||||
fn clear_completed_transitions(&mut self, hostname: &str, service_metrics: &[&Metric]) {
|
fn clear_completed_transitions(&mut self, hostname: &str, service_metrics: &[&Metric]) {
|
||||||
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
||||||
let mut completed_services = Vec::new();
|
let mut completed_services = Vec::new();
|
||||||
let now = Instant::now();
|
|
||||||
|
|
||||||
// Check each pending transition to see if real status has changed or timed out
|
// Check each pending transition to see if real status has changed
|
||||||
for (service_name, (command_type, original_status, start_time)) in &host_widgets.pending_service_transitions {
|
for (service_name, (command_type, original_status, _start_time)) in &host_widgets.pending_service_transitions {
|
||||||
// Clear if too much time has passed (3 seconds for redundant commands)
|
|
||||||
if now.duration_since(*start_time).as_secs() > 3 {
|
|
||||||
completed_services.push(service_name.clone());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look for status metric for this service
|
// Look for status metric for this service
|
||||||
for metric in service_metrics {
|
for metric in service_metrics {
|
||||||
@@ -483,7 +459,6 @@ impl TuiApp {
|
|||||||
let expected_change = match command_type {
|
let expected_change = match command_type {
|
||||||
CommandType::ServiceStart => &new_status == "active",
|
CommandType::ServiceStart => &new_status == "active",
|
||||||
CommandType::ServiceStop => &new_status != "active",
|
CommandType::ServiceStop => &new_status != "active",
|
||||||
CommandType::ServiceRestart => true, // Any change indicates restart completed
|
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -760,19 +735,19 @@ impl TuiApp {
|
|||||||
// Scroll shortcuts (always available)
|
// Scroll shortcuts (always available)
|
||||||
shortcuts.push("↑↓: Scroll".to_string());
|
shortcuts.push("↑↓: Scroll".to_string());
|
||||||
|
|
||||||
|
// Global rebuild shortcut (works on any panel)
|
||||||
|
shortcuts.push("R: Rebuild Host".to_string());
|
||||||
|
|
||||||
// Panel-specific shortcuts
|
// Panel-specific shortcuts
|
||||||
match self.focused_panel {
|
match self.focused_panel {
|
||||||
PanelType::System => {
|
|
||||||
shortcuts.push("R: Rebuild".to_string());
|
|
||||||
}
|
|
||||||
PanelType::Services => {
|
PanelType::Services => {
|
||||||
shortcuts.push("S: Start".to_string());
|
shortcuts.push("S: Start".to_string());
|
||||||
shortcuts.push("Shift+S: Stop".to_string());
|
shortcuts.push("Shift+S: Stop".to_string());
|
||||||
shortcuts.push("R: Restart".to_string());
|
|
||||||
}
|
}
|
||||||
PanelType::Backup => {
|
PanelType::Backup => {
|
||||||
shortcuts.push("B: Trigger Backup".to_string());
|
shortcuts.push("B: Trigger Backup".to_string());
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always show quit
|
// Always show quit
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ impl ServicesWidget {
|
|||||||
if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) {
|
if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) {
|
||||||
// Show transitional icons for pending commands
|
// Show transitional icons for pending commands
|
||||||
let (icon, status_text) = match command_type {
|
let (icon, status_text) = match command_type {
|
||||||
CommandType::ServiceRestart => ("↻", "restarting"),
|
|
||||||
CommandType::ServiceStart => ("↑", "starting"),
|
CommandType::ServiceStart => ("↑", "starting"),
|
||||||
CommandType::ServiceStop => ("↓", "stopping"),
|
CommandType::ServiceStop => ("↓", "stopping"),
|
||||||
_ => return (StatusIcons::get_icon(info.widget_status).to_string(), info.status.clone(), Theme::status_color(info.widget_status)), // Not a service command
|
_ => return (StatusIcons::get_icon(info.widget_status).to_string(), info.status.clone(), Theme::status_color(info.widget_status)), // Not a service command
|
||||||
@@ -233,13 +232,14 @@ impl ServicesWidget {
|
|||||||
/// Get currently selected service name (for actions)
|
/// Get currently selected service name (for actions)
|
||||||
pub fn get_selected_service(&self) -> Option<String> {
|
pub fn get_selected_service(&self) -> Option<String> {
|
||||||
// Build the same display list to find the selected service
|
// Build the same display list to find the selected service
|
||||||
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>)> = Vec::new();
|
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>, String)> = Vec::new();
|
||||||
|
|
||||||
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
||||||
parent_services.sort_by(|(a, _), (b, _)| a.cmp(b));
|
parent_services.sort_by(|(a, _), (b, _)| a.cmp(b));
|
||||||
|
|
||||||
for (parent_name, parent_info) in parent_services {
|
for (parent_name, parent_info) in parent_services {
|
||||||
display_lines.push((parent_name.clone(), parent_info.widget_status, false, None));
|
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
||||||
|
display_lines.push((parent_line, parent_info.widget_status, false, None, parent_name.clone()));
|
||||||
|
|
||||||
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
||||||
let mut sorted_subs = sub_list.clone();
|
let mut sorted_subs = sub_list.clone();
|
||||||
@@ -247,17 +247,19 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
||||||
let is_last_sub = i == sorted_subs.len() - 1;
|
let is_last_sub = i == sorted_subs.len() - 1;
|
||||||
|
let full_sub_name = format!("{}_{}", parent_name, sub_name);
|
||||||
display_lines.push((
|
display_lines.push((
|
||||||
format!("{}_{}", parent_name, sub_name), // Use parent_sub format for sub-services
|
sub_name.clone(),
|
||||||
sub_info.widget_status,
|
sub_info.widget_status,
|
||||||
true,
|
true,
|
||||||
Some((sub_info.clone(), is_last_sub)),
|
Some((sub_info.clone(), is_last_sub)),
|
||||||
|
full_sub_name,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display_lines.get(self.selected_index).map(|(name, _, _, _)| name.clone())
|
display_lines.get(self.selected_index).map(|(_, _, _, _, raw_name)| raw_name.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get total count of selectable services (parent services only, not sub-services)
|
/// Get total count of selectable services (parent services only, not sub-services)
|
||||||
@@ -475,8 +477,8 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
/// Render services list with pending transitions awareness
|
/// Render services list with pending transitions awareness
|
||||||
fn render_services_with_transitions(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>) {
|
fn render_services_with_transitions(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>) {
|
||||||
// Build hierarchical service list for display (same as existing logic)
|
// Build hierarchical service list for display - include raw service name for pending transition lookups
|
||||||
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>)> = Vec::new();
|
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>, String)> = Vec::new(); // Added raw service name
|
||||||
|
|
||||||
// Sort parent services alphabetically for consistent order
|
// Sort parent services alphabetically for consistent order
|
||||||
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
||||||
@@ -485,7 +487,7 @@ impl ServicesWidget {
|
|||||||
for (parent_name, parent_info) in parent_services {
|
for (parent_name, parent_info) in parent_services {
|
||||||
// Add parent service line
|
// Add parent service line
|
||||||
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
||||||
display_lines.push((parent_line, parent_info.widget_status, false, None)); // false = not sub-service
|
display_lines.push((parent_line, parent_info.widget_status, false, None, parent_name.clone())); // Include raw name
|
||||||
|
|
||||||
// Add sub-services for this parent (if any)
|
// Add sub-services for this parent (if any)
|
||||||
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
||||||
@@ -495,12 +497,14 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
||||||
let is_last_sub = i == sorted_subs.len() - 1;
|
let is_last_sub = i == sorted_subs.len() - 1;
|
||||||
|
let full_sub_name = format!("{}_{}", parent_name, sub_name);
|
||||||
// Store sub-service info for custom span rendering
|
// Store sub-service info for custom span rendering
|
||||||
display_lines.push((
|
display_lines.push((
|
||||||
sub_name.clone(),
|
sub_name.clone(),
|
||||||
sub_info.widget_status,
|
sub_info.widget_status,
|
||||||
true,
|
true,
|
||||||
Some((sub_info.clone(), is_last_sub)),
|
Some((sub_info.clone(), is_last_sub)),
|
||||||
|
full_sub_name, // Raw service name for pending transition lookup
|
||||||
)); // true = sub-service, with is_last info
|
)); // true = sub-service, with is_last info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -533,7 +537,7 @@ impl ServicesWidget {
|
|||||||
.constraints(vec![Constraint::Length(1); lines_to_show])
|
.constraints(vec![Constraint::Length(1); lines_to_show])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
for (i, (line_text, line_status, is_sub, sub_info)) in visible_lines.iter().enumerate()
|
for (i, (line_text, line_status, is_sub, sub_info, raw_service_name)) in visible_lines.iter().enumerate()
|
||||||
{
|
{
|
||||||
let actual_index = effective_scroll + i; // Real index in the full list
|
let actual_index = effective_scroll + i; // Real index in the full list
|
||||||
|
|
||||||
@@ -551,20 +555,28 @@ impl ServicesWidget {
|
|||||||
let (service_info, is_last) = sub_info.as_ref().unwrap();
|
let (service_info, is_last) = sub_info.as_ref().unwrap();
|
||||||
self.create_sub_service_spans_with_transitions(line_text, service_info, *is_last, pending_transitions)
|
self.create_sub_service_spans_with_transitions(line_text, service_info, *is_last, pending_transitions)
|
||||||
} else {
|
} else {
|
||||||
// Parent services - check if this parent service has a pending transition
|
// Parent services - check if this parent service has a pending transition using RAW service name
|
||||||
if pending_transitions.contains_key(line_text) {
|
if pending_transitions.contains_key(raw_service_name) {
|
||||||
// Create spans with transitional status
|
// Create spans with transitional status
|
||||||
let (icon, status_text, status_color) = self.get_service_icon_and_status(line_text, &ServiceInfo {
|
let (icon, status_text, _) = self.get_service_icon_and_status(raw_service_name, &ServiceInfo {
|
||||||
status: "".to_string(),
|
status: "".to_string(),
|
||||||
memory_mb: None,
|
memory_mb: None,
|
||||||
disk_gb: None,
|
disk_gb: None,
|
||||||
latency_ms: None,
|
latency_ms: None,
|
||||||
widget_status: *line_status
|
widget_status: *line_status
|
||||||
}, pending_transitions);
|
}, pending_transitions);
|
||||||
|
|
||||||
|
// Use blue for transitional icons when not selected, background color when selected
|
||||||
|
let icon_color = if is_selected && !*is_sub && is_focused {
|
||||||
|
Theme::background() // Dark background color for visibility against blue selection
|
||||||
|
} else {
|
||||||
|
Theme::highlight() // Blue for normal case
|
||||||
|
};
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
ratatui::text::Span::styled(format!("{} ", icon), Style::default().fg(status_color)),
|
ratatui::text::Span::styled(format!("{} ", icon), Style::default().fg(icon_color)),
|
||||||
ratatui::text::Span::styled(line_text.clone(), Style::default().fg(Theme::primary_text())),
|
ratatui::text::Span::styled(line_text.clone(), Style::default().fg(Theme::primary_text())),
|
||||||
ratatui::text::Span::styled(format!(" {}", status_text), Style::default().fg(status_color)),
|
ratatui::text::Span::styled(format!(" {}", status_text), Style::default().fg(icon_color)),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
StatusIcons::create_status_spans(*line_status, line_text)
|
StatusIcons::create_status_spans(*line_status, line_text)
|
||||||
@@ -573,8 +585,8 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
// Apply selection highlighting to parent services only, preserving status icon color
|
// Apply selection highlighting to parent services only, preserving status icon color
|
||||||
// Only show selection when Services panel is focused
|
// Only show selection when Services panel is focused
|
||||||
// IMPORTANT: Don't override transitional icons that show pending commands
|
// Show selection highlighting even when transitional icons are present
|
||||||
if is_selected && !*is_sub && is_focused && !pending_transitions.contains_key(line_text) {
|
if is_selected && !*is_sub && is_focused {
|
||||||
for (i, span) in spans.iter_mut().enumerate() {
|
for (i, span) in spans.iter_mut().enumerate() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
// First span is the status icon - preserve its color
|
// First span is the status icon - preserve its color
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.26"
|
version = "0.1.32"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user