Add option to disable osTicket integration
This commit is contained in:
parent
d906232bf9
commit
33774da89c
3 changed files with 32 additions and 17 deletions
|
|
@ -81,7 +81,13 @@ impl Component for TicketSelection {
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
KeyCode::Enter | KeyCode::Esc => Some(Action::SetMode(Mode::ScanDisks)),
|
KeyCode::Enter => Some(Action::SetMode(Mode::ScanDisks)),
|
||||||
|
KeyCode::Esc => {
|
||||||
|
if let Ok(mut osticket) = self.osticket_arc.lock() {
|
||||||
|
osticket.disable();
|
||||||
|
}
|
||||||
|
Some(Action::NextScreen)
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
Some(Event::Mouse(_)) => None,
|
Some(Event::Mouse(_)) => None,
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ pub enum ReportType {
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct OsTicket {
|
pub struct OsTicket {
|
||||||
pub connected: bool,
|
pub connected: bool,
|
||||||
|
pub disabled: bool,
|
||||||
pub server_url: String,
|
pub server_url: String,
|
||||||
pub report: Vec<String>,
|
pub report: Vec<String>,
|
||||||
pub tech_note: String,
|
pub tech_note: String,
|
||||||
|
|
@ -37,22 +38,36 @@ impl OsTicket {
|
||||||
pub fn new(ost_server: &str) -> Self {
|
pub fn new(ost_server: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
connected: false,
|
connected: false,
|
||||||
|
disabled: false,
|
||||||
server_url: ost_server.to_string(),
|
server_url: ost_server.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_db_pool(&mut self, pool: Option<Pool<MySql>>) {
|
pub fn disable(&mut self) {
|
||||||
self.ticket.pool = pool;
|
self.connected = false;
|
||||||
if self.ticket.pool.is_some() {
|
self.disabled = true;
|
||||||
self.connected = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_report(&self) -> String {
|
pub fn get_report(&self) -> String {
|
||||||
self.report.join("\n")
|
self.report.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_db_pool(&mut self, pool: Option<Pool<MySql>>) {
|
||||||
|
if self.disabled {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
match pool {
|
||||||
|
Some(pool) => {
|
||||||
|
self.connected = true;
|
||||||
|
self.ticket.pool = Some(pool);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
self.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_report(&mut self, disk: &Disk, report_type: ReportType) {
|
pub fn update_report(&mut self, disk: &Disk, report_type: ReportType) {
|
||||||
// Header
|
// Header
|
||||||
if self.report.is_empty() {
|
if self.report.is_empty() {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,6 @@ pub struct App {
|
||||||
should_suspend: bool,
|
should_suspend: bool,
|
||||||
tick_rate: f64,
|
tick_rate: f64,
|
||||||
// osTicket
|
// osTicket
|
||||||
connected: bool,
|
|
||||||
osticket_arc: Arc<Mutex<OsTicket>>,
|
osticket_arc: Arc<Mutex<OsTicket>>,
|
||||||
// App
|
// App
|
||||||
cur_mode: Mode,
|
cur_mode: Mode,
|
||||||
|
|
@ -109,7 +108,6 @@ impl App {
|
||||||
should_suspend: false,
|
should_suspend: false,
|
||||||
tick_rate,
|
tick_rate,
|
||||||
// osTicket
|
// osTicket
|
||||||
connected: false,
|
|
||||||
osticket_arc,
|
osticket_arc,
|
||||||
// App
|
// App
|
||||||
state: State::new(disk_list_arc),
|
state: State::new(disk_list_arc),
|
||||||
|
|
@ -405,13 +403,6 @@ impl App {
|
||||||
if let Some(task) = self.tasks.poll()? {
|
if let Some(task) = self.tasks.poll()? {
|
||||||
self.handle_task(&task)?;
|
self.handle_task(&task)?;
|
||||||
}
|
}
|
||||||
if self.cur_mode == Mode::SelectTicket
|
|
||||||
&& !self.connected
|
|
||||||
&& let Ok(osticket) = self.osticket_arc.try_lock()
|
|
||||||
&& osticket.ticket.pool.is_some()
|
|
||||||
{
|
|
||||||
self.connected = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Action::Quit => self.should_quit = true,
|
Action::Quit => self.should_quit = true,
|
||||||
Action::Suspend => self.should_suspend = true,
|
Action::Suspend => self.should_suspend = true,
|
||||||
|
|
@ -441,6 +432,7 @@ impl App {
|
||||||
Action::PostResponse { color, ref text } => {
|
Action::PostResponse { color, ref text } => {
|
||||||
if let Ok(osticket) = self.osticket_arc.lock()
|
if let Ok(osticket) = self.osticket_arc.lock()
|
||||||
&& osticket.connected
|
&& osticket.connected
|
||||||
|
&& !osticket.disabled
|
||||||
{
|
{
|
||||||
let result = osticket.ticket.post_response(color, &text).await;
|
let result = osticket.ticket.post_response(color, &text).await;
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -484,6 +476,7 @@ impl App {
|
||||||
if two.is_some()
|
if two.is_some()
|
||||||
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||||
&& osticket.connected
|
&& osticket.connected
|
||||||
|
&& !osticket.disabled
|
||||||
{
|
{
|
||||||
// Update osTicket report
|
// Update osTicket report
|
||||||
info!("Updating OST Report (Before)...");
|
info!("Updating OST Report (Before)...");
|
||||||
|
|
@ -511,6 +504,7 @@ impl App {
|
||||||
if two.is_some()
|
if two.is_some()
|
||||||
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||||
&& osticket.connected
|
&& osticket.connected
|
||||||
|
&& !osticket.disabled
|
||||||
{
|
{
|
||||||
// Update osTicket report
|
// Update osTicket report
|
||||||
info!("Updating OST Report (After)...");
|
info!("Updating OST Report (After)...");
|
||||||
|
|
@ -843,8 +837,8 @@ fn build_right_items(app: &App) -> Action {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
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 let Ok(osticket) = app.osticket_arc.lock()
|
||||||
&& let Ok(osticket) = app.osticket_arc.lock()
|
&& !osticket.disabled
|
||||||
&& let Some(name) = &osticket.ticket.name
|
&& let Some(name) = &osticket.ticket.name
|
||||||
{
|
{
|
||||||
items.push(vec![DVLine {
|
items.push(vec![DVLine {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue