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
|
||||
}
|
||||
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,
|
||||
},
|
||||
Some(Event::Mouse(_)) => None,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ pub enum ReportType {
|
|||
#[derive(Debug, Default)]
|
||||
pub struct OsTicket {
|
||||
pub connected: bool,
|
||||
pub disabled: bool,
|
||||
pub server_url: String,
|
||||
pub report: Vec<String>,
|
||||
pub tech_note: String,
|
||||
|
|
@ -37,22 +38,36 @@ impl OsTicket {
|
|||
pub fn new(ost_server: &str) -> Self {
|
||||
Self {
|
||||
connected: false,
|
||||
disabled: 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 disable(&mut self) {
|
||||
self.connected = false;
|
||||
self.disabled = true;
|
||||
}
|
||||
|
||||
pub fn get_report(&self) -> String {
|
||||
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) {
|
||||
// Header
|
||||
if self.report.is_empty() {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,6 @@ pub struct App {
|
|||
should_suspend: bool,
|
||||
tick_rate: f64,
|
||||
// osTicket
|
||||
connected: bool,
|
||||
osticket_arc: Arc<Mutex<OsTicket>>,
|
||||
// App
|
||||
cur_mode: Mode,
|
||||
|
|
@ -109,7 +108,6 @@ impl App {
|
|||
should_suspend: false,
|
||||
tick_rate,
|
||||
// osTicket
|
||||
connected: false,
|
||||
osticket_arc,
|
||||
// App
|
||||
state: State::new(disk_list_arc),
|
||||
|
|
@ -405,13 +403,6 @@ impl App {
|
|||
if let Some(task) = self.tasks.poll()? {
|
||||
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::Suspend => self.should_suspend = true,
|
||||
|
|
@ -441,6 +432,7 @@ impl App {
|
|||
Action::PostResponse { color, ref text } => {
|
||||
if let Ok(osticket) = self.osticket_arc.lock()
|
||||
&& osticket.connected
|
||||
&& !osticket.disabled
|
||||
{
|
||||
let result = osticket.ticket.post_response(color, &text).await;
|
||||
match result {
|
||||
|
|
@ -484,6 +476,7 @@ impl App {
|
|||
if two.is_some()
|
||||
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||
&& osticket.connected
|
||||
&& !osticket.disabled
|
||||
{
|
||||
// Update osTicket report
|
||||
info!("Updating OST Report (Before)...");
|
||||
|
|
@ -511,6 +504,7 @@ impl App {
|
|||
if two.is_some()
|
||||
&& let Ok(mut osticket) = self.osticket_arc.lock()
|
||||
&& osticket.connected
|
||||
&& !osticket.disabled
|
||||
{
|
||||
// Update osTicket report
|
||||
info!("Updating OST Report (After)...");
|
||||
|
|
@ -843,8 +837,8 @@ 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(osticket) = app.osticket_arc.lock()
|
||||
if let Ok(osticket) = app.osticket_arc.lock()
|
||||
&& !osticket.disabled
|
||||
&& let Some(name) = &osticket.ticket.name
|
||||
{
|
||||
items.push(vec![DVLine {
|
||||
|
|
|
|||
Loading…
Reference in a new issue