409 lines
11 KiB
Rust
409 lines
11 KiB
Rust
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
|
use crate::app::App;
|
|
use crate::event::Key;
|
|
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EDIT_SERIES_BLOCKS};
|
|
use crate::models::Scrollable;
|
|
use crate::network::sonarr_network::SonarrEvent;
|
|
use crate::{handle_text_box_keys, handle_text_box_left_right_keys};
|
|
|
|
#[cfg(test)]
|
|
#[path = "edit_series_handler_tests.rs"]
|
|
mod edit_series_handler_tests;
|
|
|
|
pub(super) struct EditSeriesHandler<'a, 'b> {
|
|
key: Key,
|
|
app: &'a mut App<'b>,
|
|
active_sonarr_block: ActiveSonarrBlock,
|
|
_context: Option<ActiveSonarrBlock>,
|
|
}
|
|
|
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for EditSeriesHandler<'a, 'b> {
|
|
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
|
EDIT_SERIES_BLOCKS.contains(&active_block)
|
|
}
|
|
|
|
fn with(
|
|
key: Key,
|
|
app: &'a mut App<'b>,
|
|
active_block: ActiveSonarrBlock,
|
|
_context: Option<ActiveSonarrBlock>,
|
|
) -> EditSeriesHandler<'a, 'b> {
|
|
EditSeriesHandler {
|
|
key,
|
|
app,
|
|
active_sonarr_block: active_block,
|
|
_context,
|
|
}
|
|
}
|
|
|
|
fn get_key(&self) -> Key {
|
|
self.key
|
|
}
|
|
|
|
fn is_ready(&self) -> bool {
|
|
!self.app.is_loading && self.app.data.sonarr_data.edit_series_modal.is_some()
|
|
}
|
|
|
|
fn handle_scroll_up(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.series_type_list
|
|
.scroll_up(),
|
|
ActiveSonarrBlock::EditSeriesSelectQualityProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.quality_profile_list
|
|
.scroll_up(),
|
|
ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.language_profile_list
|
|
.scroll_up(),
|
|
ActiveSonarrBlock::EditSeriesPrompt => self.app.data.sonarr_data.selected_block.up(),
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_scroll_down(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.series_type_list
|
|
.scroll_down(),
|
|
ActiveSonarrBlock::EditSeriesSelectQualityProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.quality_profile_list
|
|
.scroll_down(),
|
|
ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.language_profile_list
|
|
.scroll_down(),
|
|
ActiveSonarrBlock::EditSeriesPrompt => self.app.data.sonarr_data.selected_block.down(),
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_home(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.series_type_list
|
|
.scroll_to_top(),
|
|
ActiveSonarrBlock::EditSeriesSelectQualityProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.quality_profile_list
|
|
.scroll_to_top(),
|
|
ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.language_profile_list
|
|
.scroll_to_top(),
|
|
ActiveSonarrBlock::EditSeriesPathInput => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.path
|
|
.scroll_home(),
|
|
ActiveSonarrBlock::EditSeriesTagsInput => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.tags
|
|
.scroll_home(),
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_end(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.series_type_list
|
|
.scroll_to_bottom(),
|
|
ActiveSonarrBlock::EditSeriesSelectQualityProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.quality_profile_list
|
|
.scroll_to_bottom(),
|
|
ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.language_profile_list
|
|
.scroll_to_bottom(),
|
|
ActiveSonarrBlock::EditSeriesPathInput => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.path
|
|
.reset_offset(),
|
|
ActiveSonarrBlock::EditSeriesTagsInput => self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.tags
|
|
.reset_offset(),
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_delete(&mut self) {}
|
|
|
|
fn handle_left_right_action(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesPrompt => handle_prompt_toggle(self.app, self.key),
|
|
ActiveSonarrBlock::EditSeriesPathInput => {
|
|
handle_text_box_left_right_keys!(
|
|
self,
|
|
self.key,
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.path
|
|
)
|
|
}
|
|
ActiveSonarrBlock::EditSeriesTagsInput => {
|
|
handle_text_box_left_right_keys!(
|
|
self,
|
|
self.key,
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.tags
|
|
)
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_submit(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesPrompt => {
|
|
match self.app.data.sonarr_data.selected_block.get_active_block() {
|
|
ActiveSonarrBlock::EditSeriesConfirmPrompt => {
|
|
if self.app.data.sonarr_data.prompt_confirm {
|
|
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::EditSeries(None));
|
|
self.app.should_refresh = true;
|
|
}
|
|
|
|
self.app.pop_navigation_stack();
|
|
}
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType
|
|
| ActiveSonarrBlock::EditSeriesSelectQualityProfile
|
|
| ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self.app.push_navigation_stack(
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.selected_block
|
|
.get_active_block()
|
|
.into(),
|
|
),
|
|
ActiveSonarrBlock::EditSeriesPathInput | ActiveSonarrBlock::EditSeriesTagsInput => {
|
|
self.app.push_navigation_stack(
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.selected_block
|
|
.get_active_block()
|
|
.into(),
|
|
);
|
|
self.app.should_ignore_quit_key = true;
|
|
}
|
|
ActiveSonarrBlock::EditSeriesToggleMonitored => {
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.monitored = Some(
|
|
!self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.monitored
|
|
.unwrap_or_default(),
|
|
)
|
|
}
|
|
ActiveSonarrBlock::EditSeriesToggleSeasonFolder => {
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.use_season_folders = Some(
|
|
!self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.use_season_folders
|
|
.unwrap_or_default(),
|
|
)
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType
|
|
| ActiveSonarrBlock::EditSeriesSelectQualityProfile
|
|
| ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self.app.pop_navigation_stack(),
|
|
ActiveSonarrBlock::EditSeriesPathInput | ActiveSonarrBlock::EditSeriesTagsInput => {
|
|
self.app.pop_navigation_stack();
|
|
self.app.should_ignore_quit_key = false;
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_esc(&mut self) {
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesTagsInput | ActiveSonarrBlock::EditSeriesPathInput => {
|
|
self.app.pop_navigation_stack();
|
|
self.app.should_ignore_quit_key = false;
|
|
}
|
|
ActiveSonarrBlock::EditSeriesPrompt => {
|
|
self.app.pop_navigation_stack();
|
|
self.app.data.sonarr_data.edit_series_modal = None;
|
|
self.app.data.sonarr_data.prompt_confirm = false;
|
|
}
|
|
ActiveSonarrBlock::EditSeriesSelectSeriesType
|
|
| ActiveSonarrBlock::EditSeriesSelectQualityProfile
|
|
| ActiveSonarrBlock::EditSeriesSelectLanguageProfile => self.app.pop_navigation_stack(),
|
|
_ => (),
|
|
}
|
|
}
|
|
|
|
fn handle_char_key_event(&mut self) {
|
|
let key = self.key;
|
|
match self.active_sonarr_block {
|
|
ActiveSonarrBlock::EditSeriesPathInput => {
|
|
handle_text_box_keys!(
|
|
self,
|
|
key,
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.path
|
|
)
|
|
}
|
|
ActiveSonarrBlock::EditSeriesTagsInput => {
|
|
handle_text_box_keys!(
|
|
self,
|
|
key,
|
|
self
|
|
.app
|
|
.data
|
|
.sonarr_data
|
|
.edit_series_modal
|
|
.as_mut()
|
|
.unwrap()
|
|
.tags
|
|
)
|
|
}
|
|
ActiveSonarrBlock::EditSeriesPrompt => {
|
|
if self.app.data.sonarr_data.selected_block.get_active_block()
|
|
== ActiveSonarrBlock::EditSeriesConfirmPrompt
|
|
&& key == DEFAULT_KEYBINDINGS.confirm.key
|
|
{
|
|
self.app.data.sonarr_data.prompt_confirm = true;
|
|
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::EditSeries(None));
|
|
self.app.should_refresh = true;
|
|
|
|
self.app.pop_navigation_stack();
|
|
}
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|