Integrate ost-db-connector
This commit is contained in:
parent
6e3a0a582f
commit
105ed229c8
13 changed files with 2516 additions and 761 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
/target
|
||||
/*/target
|
||||
.data/*.log
|
||||
/*/target
|
||||
/pw
|
||||
/target
|
||||
|
|
|
|||
2859
Cargo.lock
generated
2859
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -45,6 +45,12 @@
|
|||
"<Ctrl-c>": "Quit",
|
||||
"<Ctrl-z>": "Suspend"
|
||||
},
|
||||
"SelectTicket": {
|
||||
"<q>": "Quit",
|
||||
"<Ctrl-d>": "Quit",
|
||||
"<Ctrl-c>": "Quit",
|
||||
"<Ctrl-z>": "Suspend"
|
||||
},
|
||||
"Confirm": {
|
||||
"<b>": "PrevScreen",
|
||||
"<Enter>": "Process",
|
||||
|
|
@ -227,5 +233,6 @@
|
|||
"network_server": "SERVER",
|
||||
"network_share": "SHARE",
|
||||
"network_user": "USER",
|
||||
"network_pass": "PASS"
|
||||
"network_pass": "PASS",
|
||||
"ost_server": "ost.1201.com"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,8 +56,12 @@ tokio-util = "0.7.11"
|
|||
tracing = "0.1.41"
|
||||
tracing-error = "0.2.0"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
||||
tui-input = "*"
|
||||
walkdir = "2.5.0"
|
||||
|
||||
[dependencies.ost-db-connector]
|
||||
git = "ssh://git@git.1201.com:2222/1201/ost-db-connector.git"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.86"
|
||||
vergen-gix = { version = "1.0.0", features = ["build", "cargo"] }
|
||||
|
|
|
|||
|
|
@ -59,6 +59,9 @@ pub enum Action {
|
|||
FindWimBackups,
|
||||
FindWimNetwork,
|
||||
SetUserName(String),
|
||||
// osTicket
|
||||
ResetTicket,
|
||||
SelectTicket(u16),
|
||||
// Screens
|
||||
DismissPopup,
|
||||
DisplayPopup(PopupType, String),
|
||||
|
|
|
|||
|
|
@ -27,6 +27,15 @@ pub struct Cli {
|
|||
/// Frame rate, i.e. number of frames per second
|
||||
#[arg(short, long, value_name = "FLOAT", default_value_t = 60.0)]
|
||||
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!(
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ pub mod footer;
|
|||
pub mod left;
|
||||
pub mod popup;
|
||||
pub mod right;
|
||||
pub mod select_ticket;
|
||||
pub mod state;
|
||||
pub mod title;
|
||||
|
||||
|
|
|
|||
195
core/src/components/select_ticket.rs
Normal file
195
core/src/components/select_ticket.rs
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
// 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 color_eyre::Result;
|
||||
use crossterm::event::KeyCode;
|
||||
use ost_db_connector::Ticket;
|
||||
use ratatui::{
|
||||
prelude::*,
|
||||
widgets::{Block, Borders, Clear, Paragraph},
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tui_input::{Input, InputRequest};
|
||||
|
||||
use super::Component;
|
||||
use crate::{action::Action, config::Config, state::Mode, tui::Event};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TicketSelection {
|
||||
command_tx: Option<UnboundedSender<Action>>,
|
||||
config: Config,
|
||||
input: Input,
|
||||
mode: Mode,
|
||||
ost_status: Arc<Mutex<String>>,
|
||||
ost_ticket: Arc<Mutex<Ticket>>,
|
||||
}
|
||||
|
||||
impl TicketSelection {
|
||||
#[must_use]
|
||||
pub fn new(ost_status: Arc<Mutex<String>>, ost_ticket: Arc<Mutex<Ticket>>) -> Self {
|
||||
Self {
|
||||
ost_status,
|
||||
ost_ticket,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for TicketSelection {
|
||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
||||
self.command_tx = Some(tx);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||
self.config = config;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_events(&mut self, event: Option<Event>) -> Result<Option<Action>> {
|
||||
if self.mode != Mode::SelectTicket {
|
||||
return Ok(None);
|
||||
}
|
||||
let action = match event {
|
||||
Some(Event::Key(key_event)) => match key_event.code {
|
||||
KeyCode::Backspace => {
|
||||
self.input.handle(InputRequest::DeletePrevChar);
|
||||
if let Ok(id) = self.input.value().parse::<u16>() {
|
||||
Some(Action::SelectTicket(id))
|
||||
} else {
|
||||
Some(Action::ResetTicket)
|
||||
}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
let mut result = None;
|
||||
if c.is_ascii_digit() {
|
||||
self.input.handle(InputRequest::InsertChar(c));
|
||||
if let Ok(id) = self.input.value().parse::<u16>() {
|
||||
result = Some(Action::SelectTicket(id));
|
||||
} else {
|
||||
result = Some(Action::ResetTicket);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
KeyCode::Enter | KeyCode::Esc => Some(Action::SetMode(Mode::ScanDisks)),
|
||||
_ => None,
|
||||
},
|
||||
Some(Event::Mouse(_)) => None,
|
||||
_ => None,
|
||||
};
|
||||
Ok(action)
|
||||
}
|
||||
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
if let Action::SetMode(mode) = action {
|
||||
self.mode = mode;
|
||||
self.input.reset();
|
||||
if self.mode == Mode::SelectTicket
|
||||
&& let Ok(ost_ticket) = self.ost_ticket.lock()
|
||||
&& let Some(id) = &ost_ticket.id
|
||||
{
|
||||
id.to_string().chars().for_each(|c| {
|
||||
let _ = self.input.handle(InputRequest::InsertChar(c));
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
||||
if self.mode != Mode::SelectTicket {
|
||||
// Bail early
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let [_, center_area, _] = Layout::horizontal([
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.areas(area);
|
||||
let [_, input_area, info_area, _] = Layout::vertical([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(3),
|
||||
Constraint::Min(1),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.areas(center_area);
|
||||
|
||||
frame.render_widget(Clear, area);
|
||||
let outer_block = Block::bordered().cyan().bold();
|
||||
frame.render_widget(outer_block, area);
|
||||
|
||||
// Input Box
|
||||
let width = input_area.width.max(3) - 3; // keep 2 for borders and 1 for cursor
|
||||
let scroll = self.input.visual_scroll(width as usize);
|
||||
let input = Paragraph::new(self.input.value())
|
||||
.scroll((0, scroll as u16))
|
||||
.white()
|
||||
.block(Block::new().borders(Borders::BOTTOM).title("Enter ID"));
|
||||
frame.render_widget(input, input_area);
|
||||
|
||||
// Info Box
|
||||
let mut ost_connected = false;
|
||||
if let Ok(ost_status) = self.ost_status.lock() {
|
||||
ost_connected = !ost_status.is_empty();
|
||||
}
|
||||
let mut lines = Vec::with_capacity(3);
|
||||
if !ost_connected {
|
||||
lines.push(Line::from("Connecting...").style(Style::new().yellow()));
|
||||
} else if let Ok(ost_ticket) = self.ost_ticket.lock() {
|
||||
let ticket_id = if let Some(id) = &ost_ticket.id {
|
||||
id.to_string()
|
||||
} else {
|
||||
String::from("...")
|
||||
};
|
||||
let ticket_name = if let Some(name) = &ost_ticket.name {
|
||||
name.clone()
|
||||
} else {
|
||||
String::from("...")
|
||||
};
|
||||
let ticket_subject = if let Some(subject) = &ost_ticket.subject {
|
||||
subject.clone()
|
||||
} else {
|
||||
String::from("...")
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::from("Ticket ID: ").bold(),
|
||||
Span::from(ticket_id),
|
||||
]));
|
||||
lines.push(Line::from(vec![
|
||||
Span::from("Customer Name: ").bold(),
|
||||
Span::from(ticket_name),
|
||||
]));
|
||||
lines.push(Line::from(vec![
|
||||
Span::from("Subject: ").bold(),
|
||||
Span::from(ticket_subject),
|
||||
]));
|
||||
}
|
||||
let info = Paragraph::new(lines)
|
||||
.white()
|
||||
.block(Block::new().borders(Borders::NONE).title("Ticket Info"));
|
||||
frame.render_widget(info, info_area);
|
||||
|
||||
// Ratatui hides the cursor unless it's explicitly set. Position the cursor past the
|
||||
// end of the input text and one line down from the border to the input line
|
||||
let x = self.input.visual_cursor().max(scroll) - scroll;
|
||||
frame.set_cursor_position((input_area.x + x as u16, input_area.y + 1));
|
||||
|
||||
// Done
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,8 @@ pub struct Config {
|
|||
pub network_user: String,
|
||||
#[serde(default)]
|
||||
pub network_pass: String,
|
||||
#[serde(default)]
|
||||
pub ost_server: String,
|
||||
}
|
||||
|
||||
pub static PROJECT_NAME: &str = "DEJA-VU";
|
||||
|
|
@ -84,14 +86,15 @@ impl Config {
|
|||
let config_dir = get_config_dir();
|
||||
let mut builder = config::Config::builder()
|
||||
.set_default("app_title", default_config.app_title.as_str())?
|
||||
.set_default("clone_app_path", default_config.app_title.as_str())?
|
||||
.set_default("conemu_path", default_config.app_title.as_str())?
|
||||
.set_default("clone_app_path", default_config.clone_app_path.to_str())?
|
||||
.set_default("conemu_path", default_config.conemu_path.to_str())?
|
||||
.set_default("config_dir", config_dir.to_str().unwrap())?
|
||||
.set_default("data_dir", data_dir.to_str().unwrap())?
|
||||
.set_default("network_server", default_config.app_title.as_str())?
|
||||
.set_default("network_share", default_config.app_title.as_str())?
|
||||
.set_default("network_user", default_config.app_title.as_str())?
|
||||
.set_default("network_pass", default_config.app_title.as_str())?;
|
||||
.set_default("network_server", default_config.network_server.as_str())?
|
||||
.set_default("network_share", default_config.network_share.as_str())?
|
||||
.set_default("network_user", default_config.network_user.as_str())?
|
||||
.set_default("network_pass", default_config.network_pass.as_str())?
|
||||
.set_default("ost_server", default_config.ost_server.as_str())?;
|
||||
|
||||
let config_files = [
|
||||
("config.json5", config::FileFormat::Json5),
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ pub enum Mode {
|
|||
Clone,
|
||||
SelectParts,
|
||||
PostClone,
|
||||
// osTicket
|
||||
SelectTicket,
|
||||
// Windows Installer
|
||||
ScanWinSources,
|
||||
SelectWinSource,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ tracing-error = "0.2.0"
|
|||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "serde"] }
|
||||
check_elevation = "0.2.4"
|
||||
|
||||
[dependencies.ost-db-connector]
|
||||
git = "ssh://git@git.1201.com:2222/1201/ost-db-connector.git"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.86"
|
||||
vergen-gix = { version = "1.0.0", features = ["build", "cargo"] }
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use core::{
|
|||
left::{Left, SelectionType},
|
||||
popup,
|
||||
right::Right,
|
||||
select_ticket::TicketSelection,
|
||||
state::StatefulList,
|
||||
title::Title,
|
||||
},
|
||||
|
|
@ -30,7 +31,7 @@ use core::{
|
|||
system::{
|
||||
boot,
|
||||
cpu::get_cpu_name,
|
||||
disk::PartitionTableType,
|
||||
disk::{Disk, PartitionTableType},
|
||||
diskpart::{FormatUseCase, build_dest_format_script},
|
||||
drivers,
|
||||
},
|
||||
|
|
@ -45,6 +46,7 @@ use std::{
|
|||
};
|
||||
|
||||
use color_eyre::Result;
|
||||
use ost_db_connector::{ResponseColor, Ticket};
|
||||
use ratatui::{
|
||||
crossterm::event::KeyEvent,
|
||||
layout::{Constraint, Direction, Layout},
|
||||
|
|
@ -52,7 +54,7 @@ use ratatui::{
|
|||
style::Color,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
use tracing::{debug, info};
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
|
|
@ -67,6 +69,12 @@ pub struct App {
|
|||
should_quit: bool,
|
||||
should_suspend: bool,
|
||||
tick_rate: f64,
|
||||
// osTicket
|
||||
connected: bool,
|
||||
ost_server: String,
|
||||
ost_status: Arc<Mutex<String>>,
|
||||
ost_ticket: Arc<Mutex<Ticket>>,
|
||||
report: Vec<String>,
|
||||
// App
|
||||
cur_mode: Mode,
|
||||
list: StatefulList<usize>,
|
||||
|
|
@ -77,10 +85,13 @@ pub struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
pub fn new(tick_rate: f64, frame_rate: f64) -> Result<Self> {
|
||||
pub fn new(tick_rate: f64, frame_rate: f64, ost_server: &str) -> Result<Self> {
|
||||
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
||||
let disk_list_arc = Arc::new(Mutex::new(Vec::new()));
|
||||
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 {
|
||||
// TUI
|
||||
action_rx,
|
||||
|
|
@ -90,6 +101,7 @@ impl App {
|
|||
Box::new(Left::new()),
|
||||
Box::new(Right::new()),
|
||||
Box::new(Footer::new()),
|
||||
Box::new(TicketSelection::new(ost_status.clone(), ost_ticket.clone())),
|
||||
Box::new(popup::Popup::new()),
|
||||
],
|
||||
config: Config::new()?,
|
||||
|
|
@ -98,6 +110,12 @@ impl App {
|
|||
should_quit: false,
|
||||
should_suspend: false,
|
||||
tick_rate,
|
||||
// osTicket
|
||||
connected: false,
|
||||
ost_server,
|
||||
ost_status,
|
||||
ost_ticket,
|
||||
report: Vec::new(),
|
||||
// App
|
||||
state: State::new(disk_list_arc),
|
||||
cur_mode: Mode::default(),
|
||||
|
|
@ -110,7 +128,7 @@ impl App {
|
|||
|
||||
pub fn prev_mode(&mut self) -> Option<Mode> {
|
||||
match self.cur_mode {
|
||||
Mode::Home => Some(Mode::Home),
|
||||
Mode::Home | Mode::SelectTicket => Some(Mode::Home),
|
||||
Mode::Failed => Some(Mode::Failed),
|
||||
Mode::Done => Some(Mode::Done),
|
||||
Mode::SelectParts => Some(Mode::SelectParts),
|
||||
|
|
@ -142,7 +160,8 @@ impl App {
|
|||
|
||||
pub fn next_mode(&mut self) -> Option<Mode> {
|
||||
let new_mode = match self.cur_mode {
|
||||
Mode::Home | Mode::InstallDrivers => Mode::ScanDisks,
|
||||
Mode::Home => Mode::SelectTicket,
|
||||
Mode::SelectTicket | Mode::InstallDrivers => Mode::ScanDisks,
|
||||
Mode::ScanDisks => Mode::SelectDisks,
|
||||
Mode::SelectDisks => Mode::SelectTableType,
|
||||
Mode::SelectTableType => Mode::Confirm,
|
||||
|
|
@ -176,7 +195,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_mode(&mut self, new_mode: Mode) -> Result<()> {
|
||||
pub async fn set_mode(&mut self, new_mode: Mode) -> Result<()> {
|
||||
info!("Setting mode to {new_mode:?}");
|
||||
self.cur_mode = new_mode;
|
||||
match new_mode {
|
||||
|
|
@ -197,6 +216,22 @@ impl App {
|
|||
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
|
||||
let system32 = get_system32_path(&self.action_tx);
|
||||
|
||||
|
|
@ -236,6 +271,34 @@ impl App {
|
|||
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
|
||||
let system32 = get_system32_path(&self.action_tx);
|
||||
|
||||
|
|
@ -278,6 +341,12 @@ impl App {
|
|||
)))?;
|
||||
}
|
||||
}
|
||||
|
||||
// Post to ticket
|
||||
//self.tasks.add(TaskType::CommandWait(
|
||||
// PathBuf::from("X:/Windows/System32/sync64.exe"),
|
||||
// vec![String::from("-r")],
|
||||
//));
|
||||
}
|
||||
}
|
||||
Mode::Done => {
|
||||
|
|
@ -306,11 +375,20 @@ impl App {
|
|||
component.init(tui.size()?)?;
|
||||
}
|
||||
|
||||
// Start background task to connect to osTicket
|
||||
let ost_ticket_arc = self.ost_ticket.clone();
|
||||
let ost_server = self.ost_server.clone();
|
||||
tokio::spawn(async move {
|
||||
let pool = ost_db_connector::connect(Some(&ost_server)).await;
|
||||
let mut ticket = ost_ticket_arc.lock().unwrap();
|
||||
ticket.pool = pool.ok();
|
||||
});
|
||||
|
||||
let action_tx = self.action_tx.clone();
|
||||
action_tx.send(Action::SetMode(Mode::ScanDisks))?;
|
||||
action_tx.send(Action::SetMode(Mode::SelectTicket))?;
|
||||
loop {
|
||||
self.handle_events(&mut tui).await?;
|
||||
self.handle_actions(&mut tui)?;
|
||||
self.handle_actions(&mut tui).await?;
|
||||
if self.should_suspend {
|
||||
tui.suspend()?;
|
||||
action_tx.send(Action::Resume)?;
|
||||
|
|
@ -369,7 +447,7 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_actions(&mut self, tui: &mut Tui) -> Result<()> {
|
||||
async fn handle_actions(&mut self, tui: &mut Tui) -> Result<()> {
|
||||
while let Ok(action) = self.action_rx.try_recv() {
|
||||
if action != Action::Tick && action != Action::Render {
|
||||
debug!("{action:?}");
|
||||
|
|
@ -381,6 +459,16 @@ impl App {
|
|||
if let Some(task) = self.tasks.poll()? {
|
||||
self.handle_task(&task)?;
|
||||
}
|
||||
if self.cur_mode == Mode::SelectTicket
|
||||
&& !self.connected
|
||||
&& let Ok(ticket) = self.ost_ticket.try_lock()
|
||||
&& ticket.pool.is_some()
|
||||
{
|
||||
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::Suspend => self.should_suspend = true,
|
||||
|
|
@ -462,6 +550,10 @@ impl App {
|
|||
self.selections[0] = one;
|
||||
self.selections[1] = two;
|
||||
}
|
||||
Action::SelectTicket(id) => {
|
||||
let mut ticket = self.ost_ticket.lock().unwrap();
|
||||
let _ = ticket.select_id(id).await;
|
||||
}
|
||||
Action::SetMode(new_mode) => {
|
||||
// Clear TableType selection
|
||||
match new_mode {
|
||||
|
|
@ -470,7 +562,7 @@ impl App {
|
|||
}
|
||||
_ => {}
|
||||
}
|
||||
self.set_mode(new_mode)?;
|
||||
self.set_mode(new_mode).await?;
|
||||
self.action_tx
|
||||
.send(Action::UpdateFooter(build_footer_string(self.cur_mode)))?;
|
||||
self.action_tx.send(build_left_items(self))?;
|
||||
|
|
@ -554,8 +646,10 @@ impl App {
|
|||
|
||||
fn render(&mut self, tui: &mut Tui) -> Result<()> {
|
||||
tui.draw(|frame| {
|
||||
if let [header, _body, footer, left, right, popup] = get_chunks(frame.area())[..] {
|
||||
let component_areas = vec![header, left, right, footer, popup];
|
||||
if let [header, _body, footer, left, right, select_ticket, popup] =
|
||||
get_chunks(frame.area())[..]
|
||||
{
|
||||
let component_areas = vec![header, left, right, footer, select_ticket, popup];
|
||||
for (component, area) in zip(self.components.iter_mut(), component_areas) {
|
||||
if let Err(err) = component.draw(frame, area) {
|
||||
let _ = self
|
||||
|
|
@ -594,7 +688,7 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
|||
fn get_chunks(r: Rect) -> Vec<Rect> {
|
||||
let mut chunks: Vec<Rect> = Vec::with_capacity(6);
|
||||
|
||||
// Main sections
|
||||
// Main sections (Title, body, footer)
|
||||
chunks.extend(
|
||||
Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
|
@ -616,6 +710,9 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
|||
.to_vec(),
|
||||
);
|
||||
|
||||
// Ticket Selection
|
||||
chunks.push(centered_rect(60, 40, r));
|
||||
|
||||
// Popup
|
||||
chunks.push(centered_rect(60, 25, r));
|
||||
|
||||
|
|
@ -623,6 +720,28 @@ fn get_chunks(r: Rect) -> Vec<Rect> {
|
|||
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 {
|
||||
match cur_mode {
|
||||
Mode::Home | Mode::ScanDisks | Mode::PreClone | Mode::Clone | Mode::PostClone => {
|
||||
|
|
@ -635,7 +754,7 @@ fn build_footer_string(cur_mode: Mode) -> String {
|
|||
),
|
||||
Mode::SelectTableType => String::from("(Enter) to select / (b) to go back / (q) to quit"),
|
||||
Mode::Confirm => String::from("(Enter) to confirm / (b) to go back / (q) to quit"),
|
||||
Mode::Done | Mode::Failed => String::from("(Enter) or (q) to quit"),
|
||||
Mode::Done | Mode::Failed | Mode::SelectTicket => String::from("(Enter) or (q) to quit"),
|
||||
// Invalid states
|
||||
Mode::BootDiags
|
||||
| Mode::BootScan
|
||||
|
|
@ -709,6 +828,10 @@ fn build_left_items(app: &App) -> Action {
|
|||
});
|
||||
}
|
||||
}
|
||||
Mode::SelectTicket => {
|
||||
title = String::new();
|
||||
select_type = SelectionType::Loop;
|
||||
}
|
||||
Mode::Done | Mode::Failed => {
|
||||
select_type = SelectionType::Loop;
|
||||
title = String::from("Done");
|
||||
|
|
@ -735,6 +858,21 @@ fn build_right_items(app: &App) -> Action {
|
|||
let mut items = Vec::new();
|
||||
let mut labels: Vec<Vec<DVLine>> = Vec::new();
|
||||
let mut start_index = 0;
|
||||
if app.connected
|
||||
&& let Ok(ticket) = app.ost_ticket.lock()
|
||||
&& let Some(name) = &ticket.name
|
||||
{
|
||||
items.push(vec![DVLine {
|
||||
line_parts: vec![
|
||||
format!("osTicket: #{} ", ticket.id.unwrap()),
|
||||
name.clone(),
|
||||
String::from(" // "),
|
||||
ticket.subject.clone().unwrap(),
|
||||
],
|
||||
line_colors: vec![Color::Reset, Color::Cyan, Color::Reset, Color::Reset],
|
||||
}]);
|
||||
start_index += 1;
|
||||
}
|
||||
match app.cur_mode {
|
||||
Mode::InstallDrivers => {
|
||||
items.push(vec![DVLine {
|
||||
|
|
@ -745,7 +883,7 @@ fn build_right_items(app: &App) -> Action {
|
|||
line_parts: vec![get_cpu_name()],
|
||||
line_colors: vec![Color::Reset],
|
||||
}]);
|
||||
start_index = 2;
|
||||
start_index += 2;
|
||||
}
|
||||
Mode::SelectDisks | Mode::SelectTableType | Mode::Confirm => {
|
||||
// Labels
|
||||
|
|
@ -789,7 +927,7 @@ fn build_right_items(app: &App) -> Action {
|
|||
}]);
|
||||
}
|
||||
if let Some(index) = app.state.disk_index_dest {
|
||||
start_index = 1;
|
||||
start_index += 1;
|
||||
let disk_list = app.state.disk_list.lock().unwrap();
|
||||
if let Some(disk) = disk_list.get(index) {
|
||||
// Disk Details
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ async fn main() -> Result<()> {
|
|||
core::logging::init()?;
|
||||
|
||||
let args = core::cli::Cli::parse();
|
||||
let mut app = App::new(args.tick_rate, args.frame_rate)?;
|
||||
let mut app = App::new(args.tick_rate, args.frame_rate, &args.ost_server)?;
|
||||
app.run().await?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue