// This file is part of Deja-Vu. // // Deja-Vu is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Deja-Vu is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Deja-Vu. If not, see . // use ost_db_connector::Ticket; use sqlx::{MySql, Pool}; use crate::system::disk::Disk; pub enum ReportType { Source, Destination { label: String }, } #[derive(Debug, Default)] pub struct OsTicket { pub connected: bool, pub server_url: String, pub report: Vec, pub tech_note: String, pub ticket: Ticket, } impl OsTicket { pub fn new(ost_server: &str) -> Self { Self { connected: false, server_url: ost_server.to_string(), ..Default::default() } } pub fn set_db_pool(&mut self, pool: Option>) { self.ticket.pool = pool; if self.ticket.pool.is_some() { self.connected = true } } pub fn get_report(&self) -> String { self.report.join("\n") } pub fn update_report(&mut self, disk: &Disk, report_type: ReportType) { // Header if self.report.is_empty() { self.report.push(String::from("[Deja-Vu Report]")); if !self.tech_note.is_empty() { self.report.push(format!("Tech note: {}", self.tech_note)); } } // Disk Label match report_type { ReportType::Source => { self.report.push(String::new()); self.report.push(String::from("Source:")); } ReportType::Destination { label } => { self.report.push(String::new()); self.report.push(String::from("---")); self.report.push(String::new()); self.report.push(format!("Destination ({label}):")); } } // Disk Details self.report.push(format!( "... {:<8} {:>11} {:<4} {:<4} {}", "Disk ID", "Size", "Conn", "Type", "Model (Serial)" )); self.report.push(format!("... {}", disk.description)); self.report.push(String::new()); self.report.push(format!( "... {:<8} {:>11} {:<7} {}", "Part ID", "Size", "(FS)", "\"Label\"" )); disk.parts_description.iter().for_each(|desc| { self.report.push(format!("... {desc}")); }); if disk.parts_description.is_empty() { self.report.push(String::from("... -None-")); }; } }