Move relevant code to osticket.rs
This commit is contained in:
parent
6878e539c8
commit
d906232bf9
9 changed files with 237 additions and 164 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
|
@ -540,6 +540,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"signal-hook",
|
"signal-hook",
|
||||||
|
"sqlx",
|
||||||
"strip-ansi-escapes",
|
"strip-ansi-escapes",
|
||||||
"strum 0.26.3",
|
"strum 0.26.3",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
|
@ -935,7 +936,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2327,7 +2328,7 @@ dependencies = [
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
"portable-atomic-util",
|
"portable-atomic-util",
|
||||||
"serde_core",
|
"serde_core",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2675,7 +2676,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ost-db-connector"
|
name = "ost-db-connector"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+ssh://git@git.1201.com:2222/1201/ost-db-connector.git#8cfec8b5456c0b6b713f4b9c5463219f06c05fd5"
|
source = "git+ssh://git@git.1201.com:2222/1201/ost-db-connector.git#8078a52efaf8bcdb93705d8fbdd99e17a94998d7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
@ -3154,7 +3155,7 @@ dependencies = [
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.11.0",
|
"linux-raw-sys 0.11.0",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -3752,7 +3753,7 @@ dependencies = [
|
||||||
"getrandom 0.3.4",
|
"getrandom 0.3.4",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.1.3",
|
"rustix 1.1.3",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -4394,7 +4395,7 @@ version = "0.1.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ regex = "1.11.1"
|
||||||
serde = { version = "1.0.217", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
serde_json = "1.0.125"
|
serde_json = "1.0.125"
|
||||||
signal-hook = "0.3.17"
|
signal-hook = "0.3.17"
|
||||||
|
sqlx = { version = "0.8", features = ["mysql", "runtime-tokio"] }
|
||||||
strip-ansi-escapes = "0.2.0"
|
strip-ansi-escapes = "0.2.0"
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
tempfile = "3.13.0"
|
tempfile = "3.13.0"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//
|
//
|
||||||
|
use ost_db_connector::ResponseColor;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
|
|
||||||
|
|
@ -60,6 +61,7 @@ pub enum Action {
|
||||||
FindWimNetwork,
|
FindWimNetwork,
|
||||||
SetUserName(String),
|
SetUserName(String),
|
||||||
// osTicket
|
// osTicket
|
||||||
|
PostResponse { color: ResponseColor, text: String },
|
||||||
ResetTicket,
|
ResetTicket,
|
||||||
SelectTicket(u16),
|
SelectTicket(u16),
|
||||||
// Screens
|
// Screens
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,6 @@ pub struct Cli {
|
||||||
/// Frame rate, i.e. number of frames per second
|
/// Frame rate, i.e. number of frames per second
|
||||||
#[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)]
|
#[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)]
|
||||||
pub frame_rate: f64,
|
pub frame_rate: f64,
|
||||||
|
|
||||||
/// osTicket server
|
|
||||||
#[arg(
|
|
||||||
short,
|
|
||||||
long,
|
|
||||||
value_name = "IP_OR_FQDN",
|
|
||||||
default_value_t = String::from("ost.1201.com"),
|
|
||||||
)]
|
|
||||||
pub ost_server: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const VERSION_MESSAGE: &str = concat!(
|
const VERSION_MESSAGE: &str = concat!(
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::event::KeyCode;
|
use crossterm::event::KeyCode;
|
||||||
use ost_db_connector::Ticket;
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
widgets::{Block, Borders, Clear, Paragraph},
|
widgets::{Block, Borders, Clear, Paragraph},
|
||||||
|
|
@ -24,7 +23,7 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||||
use tui_input::{Input, InputRequest};
|
use tui_input::{Input, InputRequest};
|
||||||
|
|
||||||
use super::Component;
|
use super::Component;
|
||||||
use crate::{action::Action, config::Config, state::Mode, tui::Event};
|
use crate::{action::Action, config::Config, osticket::OsTicket, state::Mode, tui::Event};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TicketSelection {
|
pub struct TicketSelection {
|
||||||
|
|
@ -32,16 +31,14 @@ pub struct TicketSelection {
|
||||||
config: Config,
|
config: Config,
|
||||||
input: Input,
|
input: Input,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
ost_status: Arc<Mutex<String>>,
|
osticket_arc: Arc<Mutex<OsTicket>>,
|
||||||
ost_ticket: Arc<Mutex<Ticket>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TicketSelection {
|
impl TicketSelection {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(ost_status: Arc<Mutex<String>>, ost_ticket: Arc<Mutex<Ticket>>) -> Self {
|
pub fn new(osticket_arc: Arc<Mutex<OsTicket>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ost_status,
|
osticket_arc,
|
||||||
ost_ticket,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,8 +95,8 @@ impl Component for TicketSelection {
|
||||||
self.mode = mode;
|
self.mode = mode;
|
||||||
self.input.reset();
|
self.input.reset();
|
||||||
if self.mode == Mode::SelectTicket
|
if self.mode == Mode::SelectTicket
|
||||||
&& let Ok(ost_ticket) = self.ost_ticket.lock()
|
&& let Ok(osticket) = self.osticket_arc.lock()
|
||||||
&& let Some(id) = &ost_ticket.id
|
&& let Some(id) = &osticket.ticket.id
|
||||||
{
|
{
|
||||||
id.to_string().chars().for_each(|c| {
|
id.to_string().chars().for_each(|c| {
|
||||||
let _ = self.input.handle(InputRequest::InsertChar(c));
|
let _ = self.input.handle(InputRequest::InsertChar(c));
|
||||||
|
|
@ -143,25 +140,22 @@ impl Component for TicketSelection {
|
||||||
frame.render_widget(input, input_area);
|
frame.render_widget(input, input_area);
|
||||||
|
|
||||||
// Info Box
|
// Info Box
|
||||||
let mut ost_connected = false;
|
let mut lines = Vec::with_capacity(4);
|
||||||
if let Ok(ost_status) = self.ost_status.lock() {
|
if let Ok(osticket) = self.osticket_arc.lock() {
|
||||||
ost_connected = !ost_status.is_empty();
|
if !osticket.connected {
|
||||||
}
|
|
||||||
let mut lines = Vec::with_capacity(3);
|
|
||||||
if !ost_connected {
|
|
||||||
lines.push(Line::from("Connecting...").style(Style::new().yellow()));
|
lines.push(Line::from("Connecting...").style(Style::new().yellow()));
|
||||||
} else if let Ok(ost_ticket) = self.ost_ticket.lock() {
|
} else {
|
||||||
let ticket_id = if let Some(id) = &ost_ticket.id {
|
let ticket_id = if let Some(id) = &osticket.ticket.id {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
} else {
|
} else {
|
||||||
String::from("...")
|
String::from("...")
|
||||||
};
|
};
|
||||||
let ticket_name = if let Some(name) = &ost_ticket.name {
|
let ticket_name = if let Some(name) = &osticket.ticket.name {
|
||||||
name.clone()
|
name.clone()
|
||||||
} else {
|
} else {
|
||||||
String::from("...")
|
String::from("...")
|
||||||
};
|
};
|
||||||
let ticket_subject = if let Some(subject) = &ost_ticket.subject {
|
let ticket_subject = if let Some(subject) = &osticket.ticket.subject {
|
||||||
subject.clone()
|
subject.clone()
|
||||||
} else {
|
} else {
|
||||||
String::from("...")
|
String::from("...")
|
||||||
|
|
@ -179,6 +173,7 @@ impl Component for TicketSelection {
|
||||||
Span::from(ticket_subject),
|
Span::from(ticket_subject),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let info = Paragraph::new(lines)
|
let info = Paragraph::new(lines)
|
||||||
.white()
|
.white()
|
||||||
.block(Block::new().borders(Borders::NONE).title("Ticket Info"));
|
.block(Block::new().borders(Borders::NONE).title("Ticket Info"));
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ pub mod config;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod line;
|
pub mod line;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
|
pub mod osticket;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
|
|
|
||||||
97
core/src/osticket.rs
Normal file
97
core/src/osticket.rs
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
|
||||||
|
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<String>,
|
||||||
|
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<Pool<MySql>>) {
|
||||||
|
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-"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,11 +27,12 @@ use core::{
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
line::{DVLine, get_disk_description_right, get_part_description},
|
line::{DVLine, get_disk_description_right, get_part_description},
|
||||||
|
osticket::{OsTicket, ReportType},
|
||||||
state::Mode,
|
state::Mode,
|
||||||
system::{
|
system::{
|
||||||
boot,
|
boot,
|
||||||
cpu::get_cpu_name,
|
cpu::get_cpu_name,
|
||||||
disk::{Disk, PartitionTableType},
|
disk::PartitionTableType,
|
||||||
diskpart::{FormatUseCase, build_dest_format_script},
|
diskpart::{FormatUseCase, build_dest_format_script},
|
||||||
drivers,
|
drivers,
|
||||||
},
|
},
|
||||||
|
|
@ -46,7 +47,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use ost_db_connector::{ResponseColor, Ticket};
|
use ost_db_connector::ResponseColor;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
crossterm::event::KeyEvent,
|
crossterm::event::KeyEvent,
|
||||||
layout::{Constraint, Direction, Layout},
|
layout::{Constraint, Direction, Layout},
|
||||||
|
|
@ -71,10 +72,7 @@ pub struct App {
|
||||||
tick_rate: f64,
|
tick_rate: f64,
|
||||||
// osTicket
|
// osTicket
|
||||||
connected: bool,
|
connected: bool,
|
||||||
ost_server: String,
|
osticket_arc: Arc<Mutex<OsTicket>>,
|
||||||
ost_status: Arc<Mutex<String>>,
|
|
||||||
ost_ticket: Arc<Mutex<Ticket>>,
|
|
||||||
report: Vec<String>,
|
|
||||||
// App
|
// App
|
||||||
cur_mode: Mode,
|
cur_mode: Mode,
|
||||||
list: StatefulList<usize>,
|
list: StatefulList<usize>,
|
||||||
|
|
@ -85,13 +83,13 @@ pub struct App {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn new(tick_rate: f64, frame_rate: f64, ost_server: &str) -> Result<Self> {
|
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
|
||||||
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
||||||
|
let config = Config::new()?;
|
||||||
let disk_list_arc = Arc::new(Mutex::new(Vec::new()));
|
let disk_list_arc = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
let osticket = OsTicket::new(&config.ost_server);
|
||||||
|
let osticket_arc = Arc::new(Mutex::new(osticket));
|
||||||
let tasks = Tasks::new(action_tx.clone(), disk_list_arc.clone());
|
let tasks = Tasks::new(action_tx.clone(), disk_list_arc.clone());
|
||||||
let ost_server = String::from(ost_server);
|
|
||||||
let ost_status = Arc::new(Mutex::new(String::new()));
|
|
||||||
let ost_ticket = Arc::new(Mutex::new(Ticket::new()));
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
// TUI
|
// TUI
|
||||||
action_rx,
|
action_rx,
|
||||||
|
|
@ -101,7 +99,7 @@ impl App {
|
||||||
Box::new(Left::new()),
|
Box::new(Left::new()),
|
||||||
Box::new(Right::new()),
|
Box::new(Right::new()),
|
||||||
Box::new(Footer::new()),
|
Box::new(Footer::new()),
|
||||||
Box::new(TicketSelection::new(ost_status.clone(), ost_ticket.clone())),
|
Box::new(TicketSelection::new(osticket_arc.clone())),
|
||||||
Box::new(popup::Popup::new()),
|
Box::new(popup::Popup::new()),
|
||||||
],
|
],
|
||||||
config: Config::new()?,
|
config: Config::new()?,
|
||||||
|
|
@ -112,10 +110,7 @@ impl App {
|
||||||
tick_rate,
|
tick_rate,
|
||||||
// osTicket
|
// osTicket
|
||||||
connected: false,
|
connected: false,
|
||||||
ost_server,
|
osticket_arc,
|
||||||
ost_status,
|
|
||||||
ost_ticket,
|
|
||||||
report: Vec::new(),
|
|
||||||
// App
|
// App
|
||||||
state: State::new(disk_list_arc),
|
state: State::new(disk_list_arc),
|
||||||
cur_mode: Mode::default(),
|
cur_mode: Mode::default(),
|
||||||
|
|
@ -195,7 +190,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_mode(&mut self, new_mode: Mode) -> Result<()> {
|
pub fn set_mode(&mut self, new_mode: Mode) -> Result<()> {
|
||||||
info!("Setting mode to {new_mode:?}");
|
info!("Setting mode to {new_mode:?}");
|
||||||
self.cur_mode = new_mode;
|
self.cur_mode = new_mode;
|
||||||
match new_mode {
|
match new_mode {
|
||||||
|
|
@ -216,22 +211,6 @@ impl App {
|
||||||
String::from("Formatting destination disk"),
|
String::from("Formatting destination disk"),
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
// Update osTicket report
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
self.report.push(String::from("[Deja-Vu Report]"));
|
|
||||||
self.report.push(String::new());
|
|
||||||
self.report.push(String::from("Source Disk:"));
|
|
||||||
self.report.append(&mut build_disk_report(source_disk));
|
|
||||||
self.report.push(String::new());
|
|
||||||
self.report.push(String::from("Dest Disk (before):"));
|
|
||||||
self.report.append(&mut build_disk_report(dest_disk));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get System32 path
|
// Get System32 path
|
||||||
let system32 = get_system32_path(&self.action_tx);
|
let system32 = get_system32_path(&self.action_tx);
|
||||||
|
|
||||||
|
|
@ -271,34 +250,6 @@ impl App {
|
||||||
String::from("Updating boot configuration"),
|
String::from("Updating boot configuration"),
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
// Update osTicket report
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
self.report.push(String::from("[Deja-Vu Report]"));
|
|
||||||
self.report.push(String::new());
|
|
||||||
self.report.push(String::from("Dest Disk (After):"));
|
|
||||||
self.report.append(&mut build_disk_report(dest_disk));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload osTicket report
|
|
||||||
if let Ok(ticket) = self.ost_ticket.lock() {
|
|
||||||
if ticket.pool.is_some() {
|
|
||||||
let result = ticket
|
|
||||||
.post_response(ResponseColor::Normal, &self.report.join("\n"))
|
|
||||||
.await;
|
|
||||||
match result {
|
|
||||||
Ok(_) => {
|
|
||||||
info!("Posted results to osTicket!");
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
warn!("Failed to post results to osTicket: {err}");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get System32 path
|
// Get System32 path
|
||||||
let system32 = get_system32_path(&self.action_tx);
|
let system32 = get_system32_path(&self.action_tx);
|
||||||
|
|
||||||
|
|
@ -341,12 +292,6 @@ impl App {
|
||||||
)))?;
|
)))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post to ticket
|
|
||||||
//self.tasks.add(TaskType::CommandWait(
|
|
||||||
// PathBuf::from("X:/Windows/System32/sync64.exe"),
|
|
||||||
// vec![String::from("-r")],
|
|
||||||
//));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::Done => {
|
Mode::Done => {
|
||||||
|
|
@ -376,12 +321,13 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start background task to connect to osTicket
|
// Start background task to connect to osTicket
|
||||||
let ost_ticket_arc = self.ost_ticket.clone();
|
let osticket_arc = self.osticket_arc.clone();
|
||||||
let ost_server = self.ost_server.clone();
|
let ost_server = self.config.ost_server.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let pool = ost_db_connector::connect(Some(&ost_server)).await;
|
let pool = ost_db_connector::connect(Some(ost_server), true).await;
|
||||||
let mut ticket = ost_ticket_arc.lock().unwrap();
|
if let Ok(mut osticket) = osticket_arc.lock() {
|
||||||
ticket.pool = pool.ok();
|
osticket.set_db_pool(pool);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let action_tx = self.action_tx.clone();
|
let action_tx = self.action_tx.clone();
|
||||||
|
|
@ -461,13 +407,10 @@ impl App {
|
||||||
}
|
}
|
||||||
if self.cur_mode == Mode::SelectTicket
|
if self.cur_mode == Mode::SelectTicket
|
||||||
&& !self.connected
|
&& !self.connected
|
||||||
&& let Ok(ticket) = self.ost_ticket.try_lock()
|
&& let Ok(osticket) = self.osticket_arc.try_lock()
|
||||||
&& ticket.pool.is_some()
|
&& osticket.ticket.pool.is_some()
|
||||||
{
|
{
|
||||||
self.connected = true;
|
self.connected = true;
|
||||||
if let Ok(mut ost_status) = self.ost_status.lock() {
|
|
||||||
*ost_status = String::from("Connected");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::Quit => self.should_quit = true,
|
Action::Quit => self.should_quit = true,
|
||||||
|
|
@ -495,6 +438,21 @@ impl App {
|
||||||
},
|
},
|
||||||
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
Action::Resize(w, h) => self.handle_resize(tui, w, h)?,
|
||||||
Action::Render => self.render(tui)?,
|
Action::Render => self.render(tui)?,
|
||||||
|
Action::PostResponse { color, ref text } => {
|
||||||
|
if let Ok(osticket) = self.osticket_arc.lock()
|
||||||
|
&& osticket.connected
|
||||||
|
{
|
||||||
|
let result = osticket.ticket.post_response(color, &text).await;
|
||||||
|
match result {
|
||||||
|
Ok(_) => {
|
||||||
|
info!("Posted results to osTicket!");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
warn!("Failed to post results to osTicket: {err}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Action::PrevScreen => {
|
Action::PrevScreen => {
|
||||||
if let Some(new_mode) = self.prev_mode() {
|
if let Some(new_mode) = self.prev_mode() {
|
||||||
self.prev_mode = new_mode;
|
self.prev_mode = new_mode;
|
||||||
|
|
@ -523,10 +481,59 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Mode::SelectDisks => {
|
Mode::SelectDisks => {
|
||||||
|
if two.is_some()
|
||||||
|
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||||
|
&& osticket.connected
|
||||||
|
{
|
||||||
|
// 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_source = one;
|
||||||
self.state.disk_index_dest = two;
|
self.state.disk_index_dest = two;
|
||||||
}
|
}
|
||||||
Mode::SelectParts => {
|
Mode::SelectParts => {
|
||||||
|
if two.is_some()
|
||||||
|
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||||
|
&& osticket.connected
|
||||||
|
{
|
||||||
|
// 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_boot = one;
|
||||||
self.state.part_index_os = two;
|
self.state.part_index_os = two;
|
||||||
}
|
}
|
||||||
|
|
@ -551,8 +558,8 @@ impl App {
|
||||||
self.selections[1] = two;
|
self.selections[1] = two;
|
||||||
}
|
}
|
||||||
Action::SelectTicket(id) => {
|
Action::SelectTicket(id) => {
|
||||||
let mut ticket = self.ost_ticket.lock().unwrap();
|
let mut osticket = self.osticket_arc.lock().unwrap();
|
||||||
let _ = ticket.select_id(id).await;
|
let _ = osticket.ticket.select_id(id).await;
|
||||||
}
|
}
|
||||||
Action::SetMode(new_mode) => {
|
Action::SetMode(new_mode) => {
|
||||||
// Clear TableType selection
|
// Clear TableType selection
|
||||||
|
|
@ -562,7 +569,7 @@ impl App {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.set_mode(new_mode).await?;
|
self.set_mode(new_mode)?;
|
||||||
self.action_tx
|
self.action_tx
|
||||||
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
|
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
|
||||||
self.action_tx.send(build_left_items(self))?;
|
self.action_tx.send(build_left_items(self))?;
|
||||||
|
|
@ -720,28 +727,6 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||||
chunks
|
chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_disk_report(disk: &Disk) -> Vec<String> {
|
|
||||||
let mut report = Vec::with_capacity(8);
|
|
||||||
report.push(format!(
|
|
||||||
"... {:<8} {:>11} {:<4} {:<4} {}",
|
|
||||||
"Disk ID", "Size", "Conn", "Type", "Model (Serial)"
|
|
||||||
));
|
|
||||||
report.push(format!("... {}", disk.description));
|
|
||||||
report.push(String::new());
|
|
||||||
report.push(format!(
|
|
||||||
"... {:<8} {:>11} {:<7} {}",
|
|
||||||
"Part ID", "Size", "(FS)", "\"Label\""
|
|
||||||
));
|
|
||||||
report.append(&mut disk.parts_description.clone());
|
|
||||||
disk.parts_description.iter().for_each(|desc| {
|
|
||||||
report.push(format!("... {desc}"));
|
|
||||||
});
|
|
||||||
if disk.parts_description.is_empty() {
|
|
||||||
report.push(String::from("... -None-"));
|
|
||||||
};
|
|
||||||
report
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_footer_string(cur_mode: Mode) -> String {
|
fn build_footer_string(cur_mode: Mode) -> String {
|
||||||
match cur_mode {
|
match cur_mode {
|
||||||
Mode::Home | Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
Mode::Home | Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||||
|
|
@ -859,15 +844,15 @@ fn build_right_items(app: &App) -> Action {
|
||||||
let mut labels: Vec<Vec<DVLine>> = Vec::new();
|
let mut labels: Vec<Vec<DVLine>> = Vec::new();
|
||||||
let mut start_index = 0;
|
let mut start_index = 0;
|
||||||
if app.connected
|
if app.connected
|
||||||
&& let Ok(ticket) = app.ost_ticket.lock()
|
&& let Ok(osticket) = app.osticket_arc.lock()
|
||||||
&& let Some(name) = &ticket.name
|
&& let Some(name) = &osticket.ticket.name
|
||||||
{
|
{
|
||||||
items.push(vec![DVLine {
|
items.push(vec![DVLine {
|
||||||
line_parts: vec![
|
line_parts: vec![
|
||||||
format!("osTicket: #{} ", ticket.id.unwrap()),
|
format!("osTicket: #{} ", osticket.ticket.id.unwrap()),
|
||||||
name.clone(),
|
name.clone(),
|
||||||
String::from(" // "),
|
String::from(" // "),
|
||||||
ticket.subject.clone().unwrap(),
|
osticket.ticket.subject.clone().unwrap(),
|
||||||
],
|
],
|
||||||
line_colors: vec![Color::Reset, Color::Cyan, Color::Reset, Color::Reset],
|
line_colors: vec![Color::Reset, Color::Cyan, Color::Reset, Color::Reset],
|
||||||
}]);
|
}]);
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ async fn main() -> Result<()> {
|
||||||
core::logging::init()?;
|
core::logging::init()?;
|
||||||
|
|
||||||
let args = core::cli::Cli::parse();
|
let args = core::cli::Cli::parse();
|
||||||
let mut app = App::new(args.tick_rate, args.frame_rate, &args.ost_server)?;
|
let mut app = App::new(args.tick_rate, args.frame_rate)?;
|
||||||
app.run().await?;
|
app.run().await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue