From 049b036e651870b764a0ff2ca276eded8a7d6106 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 17 Jan 2026 14:53:28 -0800 Subject: [PATCH] Post to osTicket on failures too --- core/src/components/select_ticket.rs | 2 +- core/src/osticket.rs | 17 +++- deja_vu/src/app.rs | 123 ++++++++++++++++----------- 3 files changed, 89 insertions(+), 53 deletions(-) diff --git a/core/src/components/select_ticket.rs b/core/src/components/select_ticket.rs index 900d294..b526942 100644 --- a/core/src/components/select_ticket.rs +++ b/core/src/components/select_ticket.rs @@ -87,7 +87,7 @@ impl Component for TicketSelection { KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)), KeyCode::Esc => Some(Action::DisplayPopup( PopupType::Question, - String::from("Disable osTicket integration?\n\nY / N"), + String::from("Disable osTicket integration?\n\n\nY / N"), )), _ => None, }, diff --git a/core/src/osticket.rs b/core/src/osticket.rs index 1ea9111..9c2fbad 100644 --- a/core/src/osticket.rs +++ b/core/src/osticket.rs @@ -28,6 +28,7 @@ pub enum ReportType { pub struct OsTicket { pub connected: bool, pub disabled: bool, + pub error: String, pub server_url: String, pub report: Vec, pub tech_note: String, @@ -44,12 +45,26 @@ impl OsTicket { } } + pub fn add_error(&mut self, text: &str) { + let lines: Vec<&str> = text + .lines() + .filter(|line| { + let line = line.trim(); + !line.is_empty() && !line.eq_ignore_ascii_case("ERROR") + }) + .collect(); + self.error = lines.join("\n"); + } + pub fn disable(&mut self) { self.connected = false; self.disabled = true; } - pub fn get_report(&self) -> String { + pub fn get_report(&mut self) -> String { + if !self.error.is_empty() { + self.report.push(format!("\n\nERROR: {}", self.error)); + } self.report.join("\n") } diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs index cfc3c91..d9d15fc 100644 --- a/deja_vu/src/app.rs +++ b/deja_vu/src/app.rs @@ -411,6 +411,9 @@ impl App { Action::KeyUp => self.list.previous(), Action::KeyDown => self.list.next(), Action::Error(ref msg) => { + if let Ok(mut osticket) = self.osticket_arc.lock() { + osticket.add_error(msg); + } self.action_tx .send(Action::DisplayPopup(popup::Type::Error, msg.clone()))?; self.action_tx.send(Action::SetMode(Mode::Failed))?; @@ -473,61 +476,10 @@ impl App { } } Mode::SelectDisks => { - if two.is_some() - && let Ok(mut osticket) = self.osticket_arc.lock() - && osticket.connected - && !osticket.disabled - { - // Update osTicket report - info!("Updating OST Report (Before)..."); - let disk_list = self.state.disk_list.lock().unwrap(); - if let Some(source_index) = one - && let Some(source_disk) = disk_list.get(source_index) - && let Some(dest_index) = two - && let Some(dest_disk) = disk_list.get(dest_index) - { - osticket.update_report(source_disk, ReportType::Source); - osticket.update_report( - dest_disk, - ReportType::Destination { - label: String::from("Before"), - }, - ); - } - } - - // Update state self.state.disk_index_source = one; self.state.disk_index_dest = two; } Mode::SelectParts => { - if two.is_some() - && let Ok(mut osticket) = self.osticket_arc.lock() - && osticket.connected - && !osticket.disabled - { - // Update osTicket report - info!("Updating OST Report (After)..."); - let disk_list = self.state.disk_list.lock().unwrap(); - if let Some(dest_index) = self.state.disk_index_dest - && let Some(dest_disk) = disk_list.get(dest_index) - { - osticket.update_report( - dest_disk, - ReportType::Destination { - label: String::from("After"), - }, - ); - - // Upload osTicket report - self.action_tx.send(Action::PostResponse { - color: ResponseColor::Normal, - text: osticket.get_report(), - })?; - } - } - - // Update state self.state.part_index_boot = one; self.state.part_index_os = two; } @@ -564,10 +516,15 @@ impl App { _ => {} } self.set_mode(new_mode)?; + + // Update components self.action_tx .send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?; self.action_tx.send(build_left_items(self))?; self.action_tx.send(build_right_items(self))?; + + // Update state + // TODO: Verify this shouldn't be before update components? match new_mode { Mode::SelectTableType | Mode::Confirm => { // Select source/dest disks @@ -593,6 +550,65 @@ impl App { } _ => {} }; + + // Update osTicket + match new_mode { + Mode::Confirm => { + if let Ok(mut osticket) = self.osticket_arc.lock() + && osticket.connected + && !osticket.disabled + { + info!("Updating OST Report (Before)..."); + let disk_list = self.state.disk_list.lock().unwrap(); + if let Some(source_index) = self.state.disk_index_source + && let Some(source_disk) = disk_list.get(source_index) + && let Some(dest_index) = self.state.disk_index_dest + && let Some(dest_disk) = disk_list.get(dest_index) + { + osticket.update_report(source_disk, ReportType::Source); + osticket.update_report( + dest_disk, + ReportType::Destination { + label: String::from("Before"), + }, + ); + } + } + } + Mode::Done | Mode::Failed => { + if let Ok(mut osticket) = self.osticket_arc.lock() + && osticket.connected + && !osticket.disabled + { + info!("Updating OST Report (After)..."); + let disk_list = self.state.disk_list.lock().unwrap(); + if let Some(dest_index) = self.state.disk_index_dest + && let Some(dest_disk) = disk_list.get(dest_index) + { + osticket.update_report( + dest_disk, + ReportType::Destination { + label: String::from("After"), + }, + ); + + // Set color + let color = if new_mode == Mode::Failed { + ResponseColor::DiagFail + } else { + ResponseColor::Normal + }; + + // Upload osTicket report + self.action_tx.send(Action::PostResponse { + color, + text: osticket.get_report(), + })?; + } + } + } + _ => {} + } } Action::TasksComplete => self.action_tx.send(Action::NextScreen)?, Action::UserNo => self.action_tx.send(Action::DismissPopup)?, @@ -912,6 +928,11 @@ fn build_right_items(app: &App) -> Action { line_colors: vec![Color::Cyan], }]); } + start_index += 1; + items.push(vec![DVLine { + line_parts: vec![String::new()], + line_colors: vec![Color::Reset], + }]); if let Some(index) = app.state.disk_index_dest { start_index += 1; let disk_list = app.state.disk_list.lock().unwrap();