feat(handler): Add series support for Sonarr
This commit is contained in:
@@ -0,0 +1,550 @@
|
|||||||
|
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||||
|
use crate::handlers::{handle_prompt_toggle, KeyEventHandler};
|
||||||
|
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||||
|
ActiveSonarrBlock, ADD_SERIES_BLOCKS, ADD_SERIES_SELECTION_BLOCKS,
|
||||||
|
};
|
||||||
|
use crate::models::{BlockSelectionState, Scrollable};
|
||||||
|
use crate::network::sonarr_network::SonarrEvent;
|
||||||
|
use crate::{handle_text_box_keys, handle_text_box_left_right_keys, App, Key};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "add_series_handler_tests.rs"]
|
||||||
|
mod add_series_handler_tests;
|
||||||
|
|
||||||
|
pub(super) struct AddSeriesHandler<'a, 'b> {
|
||||||
|
key: Key,
|
||||||
|
app: &'a mut App<'b>,
|
||||||
|
active_sonarr_block: ActiveSonarrBlock,
|
||||||
|
_context: Option<ActiveSonarrBlock>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for AddSeriesHandler<'a, 'b> {
|
||||||
|
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||||
|
ADD_SERIES_BLOCKS.contains(&active_block)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with(
|
||||||
|
key: Key,
|
||||||
|
app: &'a mut App<'b>,
|
||||||
|
active_block: ActiveSonarrBlock,
|
||||||
|
_context: Option<ActiveSonarrBlock>,
|
||||||
|
) -> AddSeriesHandler<'a, 'b> {
|
||||||
|
AddSeriesHandler {
|
||||||
|
key,
|
||||||
|
app,
|
||||||
|
active_sonarr_block: active_block,
|
||||||
|
_context,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_key(&self) -> Key {
|
||||||
|
self.key
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_ready(&self) -> bool {
|
||||||
|
!self.app.is_loading
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_scroll_up(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_searched_series
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.monitor_list
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectSeriesType => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.series_type_list
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.quality_profile_list
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.language_profile_list
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectRootFolder => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.root_folder_list
|
||||||
|
.scroll_up(),
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt => self.app.data.sonarr_data.selected_block.up(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_scroll_down(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_searched_series
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.monitor_list
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectSeriesType => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.series_type_list
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.quality_profile_list
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.language_profile_list
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectRootFolder => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.root_folder_list
|
||||||
|
.scroll_down(),
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt => self.app.data.sonarr_data.selected_block.down(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_home(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_searched_series
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.monitor_list
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectSeriesType => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.series_type_list
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.quality_profile_list
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.language_profile_list
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectRootFolder => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.root_folder_list
|
||||||
|
.scroll_to_top(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_search
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_home(),
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.tags
|
||||||
|
.scroll_home(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_end(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_searched_series
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.monitor_list
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectSeriesType => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.series_type_list
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.quality_profile_list
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.language_profile_list
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectRootFolder => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.root_folder_list
|
||||||
|
.scroll_to_bottom(),
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_search
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.reset_offset(),
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_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::AddSeriesPrompt => handle_prompt_toggle(self.app, self.key),
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput => {
|
||||||
|
handle_text_box_left_right_keys!(
|
||||||
|
self,
|
||||||
|
self.key,
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_search
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => {
|
||||||
|
handle_text_box_left_right_keys!(
|
||||||
|
self,
|
||||||
|
self.key,
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.tags
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_submit(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
_ if self.active_sonarr_block == ActiveSonarrBlock::AddSeriesSearchInput
|
||||||
|
&& !self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_search
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.text
|
||||||
|
.is_empty() =>
|
||||||
|
{
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.push_navigation_stack(ActiveSonarrBlock::AddSeriesSearchResults.into());
|
||||||
|
self.app.should_ignore_quit_key = false;
|
||||||
|
}
|
||||||
|
_ if self.active_sonarr_block == ActiveSonarrBlock::AddSeriesSearchResults
|
||||||
|
&& self.app.data.sonarr_data.add_searched_series.is_some() =>
|
||||||
|
{
|
||||||
|
let tvdb_id = self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_searched_series
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.current_selection()
|
||||||
|
.tvdb_id;
|
||||||
|
|
||||||
|
if self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.series
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.any(|series| series.tvdb_id == tvdb_id)
|
||||||
|
{
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.push_navigation_stack(ActiveSonarrBlock::AddSeriesAlreadyInLibrary.into());
|
||||||
|
} else {
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.push_navigation_stack(ActiveSonarrBlock::AddSeriesPrompt.into());
|
||||||
|
self.app.data.sonarr_data.add_series_modal = Some((&self.app.data.sonarr_data).into());
|
||||||
|
self.app.data.sonarr_data.selected_block =
|
||||||
|
BlockSelectionState::new(ADD_SERIES_SELECTION_BLOCKS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt => {
|
||||||
|
match self.app.data.sonarr_data.selected_block.get_active_block() {
|
||||||
|
ActiveSonarrBlock::AddSeriesConfirmPrompt => {
|
||||||
|
if self.app.data.sonarr_data.prompt_confirm {
|
||||||
|
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::AddSeries(None));
|
||||||
|
}
|
||||||
|
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectSeriesType
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectQualityProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectLanguageProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectRootFolder => self.app.push_navigation_stack(
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.selected_block
|
||||||
|
.get_active_block()
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => {
|
||||||
|
self.app.push_navigation_stack(
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.selected_block
|
||||||
|
.get_active_block()
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
|
self.app.should_ignore_quit_key = true;
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder => {
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.use_season_folder = !self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.use_season_folder;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectSeriesType
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectQualityProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectLanguageProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectRootFolder => self.app.pop_navigation_stack(),
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.should_ignore_quit_key = false;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_esc(&mut self) {
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.data.sonarr_data.add_series_search = None;
|
||||||
|
self.app.should_ignore_quit_key = false;
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults
|
||||||
|
| ActiveSonarrBlock::AddSeriesEmptySearchResults => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.data.sonarr_data.add_searched_series = None;
|
||||||
|
self.app.should_ignore_quit_key = true;
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.data.sonarr_data.add_series_modal = None;
|
||||||
|
self.app.data.sonarr_data.prompt_confirm = false;
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectSeriesType
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectQualityProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectLanguageProfile
|
||||||
|
| ActiveSonarrBlock::AddSeriesAlreadyInLibrary
|
||||||
|
| ActiveSonarrBlock::AddSeriesSelectRootFolder => self.app.pop_navigation_stack(),
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.should_ignore_quit_key = false;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_char_key_event(&mut self) {
|
||||||
|
let key = self.key;
|
||||||
|
match self.active_sonarr_block {
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput => {
|
||||||
|
handle_text_box_keys!(
|
||||||
|
self,
|
||||||
|
key,
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_search
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput => {
|
||||||
|
handle_text_box_keys!(
|
||||||
|
self,
|
||||||
|
key,
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.data
|
||||||
|
.sonarr_data
|
||||||
|
.add_series_modal
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.tags
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt => {
|
||||||
|
if self.app.data.sonarr_data.selected_block.get_active_block()
|
||||||
|
== ActiveSonarrBlock::AddSeriesConfirmPrompt
|
||||||
|
&& key == DEFAULT_KEYBINDINGS.confirm.key
|
||||||
|
{
|
||||||
|
self.app.data.sonarr_data.prompt_confirm = true;
|
||||||
|
self.app.data.sonarr_data.prompt_confirm_action = Some(SonarrEvent::AddSeries(None));
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ mod tests {
|
|||||||
use crate::handlers::sonarr_handlers::library::{series_sorting_options, LibraryHandler};
|
use crate::handlers::sonarr_handlers::library::{series_sorting_options, LibraryHandler};
|
||||||
use crate::handlers::KeyEventHandler;
|
use crate::handlers::KeyEventHandler;
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||||
ActiveSonarrBlock, DELETE_SERIES_BLOCKS, LIBRARY_BLOCKS,
|
ActiveSonarrBlock, ADD_SERIES_BLOCKS, DELETE_SERIES_BLOCKS, LIBRARY_BLOCKS,
|
||||||
};
|
};
|
||||||
use crate::models::sonarr_models::{Series, SeriesStatus, SeriesType};
|
use crate::models::sonarr_models::{Series, SeriesStatus, SeriesType};
|
||||||
use crate::models::stateful_table::SortOption;
|
use crate::models::stateful_table::SortOption;
|
||||||
@@ -1441,27 +1441,29 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[rstest]
|
#[rstest]
|
||||||
// fn test_delegates_add_series_blocks_to_add_series_handler(
|
fn test_delegates_add_series_blocks_to_add_series_handler(
|
||||||
// #[values(
|
#[values(
|
||||||
// ActiveSonarrBlock::AddSeriesSearchInput,
|
ActiveSonarrBlock::AddSeriesAlreadyInLibrary,
|
||||||
// ActiveSonarrBlock::AddSeriesSearchResults,
|
ActiveSonarrBlock::AddSeriesEmptySearchResults,
|
||||||
// ActiveSonarrBlock::AddSeriesPrompt,
|
ActiveSonarrBlock::AddSeriesPrompt,
|
||||||
// ActiveSonarrBlock::AddSeriesSelectMonitor,
|
ActiveSonarrBlock::AddSeriesSearchInput,
|
||||||
// ActiveSonarrBlock::AddSeriesSelectSeriesType,
|
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||||
// ActiveSonarrBlock::AddSeriesSelectQualityProfile,
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile,
|
||||||
// ActiveSonarrBlock::AddSeriesSelectRootFolder,
|
ActiveSonarrBlock::AddSeriesSelectMonitor,
|
||||||
// ActiveSonarrBlock::AddSeriesAlreadyInLibrary,
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile,
|
||||||
// ActiveSonarrBlock::AddSeriesTagsInput
|
ActiveSonarrBlock::AddSeriesSelectRootFolder,
|
||||||
// )]
|
ActiveSonarrBlock::AddSeriesSelectSeriesType,
|
||||||
// active_sonarr_block: ActiveSonarrBlock,
|
ActiveSonarrBlock::AddSeriesTagsInput
|
||||||
// ) {
|
)]
|
||||||
// test_handler_delegation!(
|
active_sonarr_block: ActiveSonarrBlock,
|
||||||
// LibraryHandler,
|
) {
|
||||||
// ActiveSonarrBlock::Series,
|
test_handler_delegation!(
|
||||||
// active_sonarr_block
|
LibraryHandler,
|
||||||
// );
|
ActiveSonarrBlock::Series,
|
||||||
// }
|
active_sonarr_block
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// #[rstest]
|
// #[rstest]
|
||||||
// fn test_delegates_series_details_blocks_to_series_details_handler(
|
// fn test_delegates_series_details_blocks_to_series_details_handler(
|
||||||
@@ -1705,6 +1707,7 @@ mod tests {
|
|||||||
fn test_library_handler_accepts() {
|
fn test_library_handler_accepts() {
|
||||||
let mut library_handler_blocks = Vec::new();
|
let mut library_handler_blocks = Vec::new();
|
||||||
library_handler_blocks.extend(LIBRARY_BLOCKS);
|
library_handler_blocks.extend(LIBRARY_BLOCKS);
|
||||||
|
library_handler_blocks.extend(ADD_SERIES_BLOCKS);
|
||||||
library_handler_blocks.extend(DELETE_SERIES_BLOCKS);
|
library_handler_blocks.extend(DELETE_SERIES_BLOCKS);
|
||||||
|
|
||||||
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
|
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use add_series_handler::AddSeriesHandler;
|
||||||
use delete_series_handler::DeleteSeriesHandler;
|
use delete_series_handler::DeleteSeriesHandler;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -20,6 +21,7 @@ use crate::{
|
|||||||
use super::handle_change_tab_left_right_keys;
|
use super::handle_change_tab_left_right_keys;
|
||||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||||
|
|
||||||
|
mod add_series_handler;
|
||||||
mod delete_series_handler;
|
mod delete_series_handler;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -36,6 +38,9 @@ pub(super) struct LibraryHandler<'a, 'b> {
|
|||||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, 'b> {
|
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, 'b> {
|
||||||
fn handle(&mut self) {
|
fn handle(&mut self) {
|
||||||
match self.active_sonarr_block {
|
match self.active_sonarr_block {
|
||||||
|
_ if AddSeriesHandler::accepts(self.active_sonarr_block) => {
|
||||||
|
AddSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context).handle();
|
||||||
|
}
|
||||||
_ if DeleteSeriesHandler::accepts(self.active_sonarr_block) => {
|
_ if DeleteSeriesHandler::accepts(self.active_sonarr_block) => {
|
||||||
DeleteSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
|
DeleteSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
|
||||||
.handle();
|
.handle();
|
||||||
@@ -45,7 +50,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||||
DeleteSeriesHandler::accepts(active_block) || LIBRARY_BLOCKS.contains(&active_block)
|
AddSeriesHandler::accepts(active_block)
|
||||||
|
|| DeleteSeriesHandler::accepts(active_block)
|
||||||
|
|| LIBRARY_BLOCKS.contains(&active_block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with(
|
fn with(
|
||||||
|
|||||||
@@ -295,6 +295,33 @@ pub static LIBRARY_BLOCKS: [ActiveSonarrBlock; 7] = [
|
|||||||
ActiveSonarrBlock::UpdateAllSeriesPrompt,
|
ActiveSonarrBlock::UpdateAllSeriesPrompt,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub static ADD_SERIES_BLOCKS: [ActiveSonarrBlock; 13] = [
|
||||||
|
ActiveSonarrBlock::AddSeriesAlreadyInLibrary,
|
||||||
|
ActiveSonarrBlock::AddSeriesConfirmPrompt,
|
||||||
|
ActiveSonarrBlock::AddSeriesEmptySearchResults,
|
||||||
|
ActiveSonarrBlock::AddSeriesPrompt,
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchInput,
|
||||||
|
ActiveSonarrBlock::AddSeriesSearchResults,
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectLanguageProfile,
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectMonitor,
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectQualityProfile,
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectRootFolder,
|
||||||
|
ActiveSonarrBlock::AddSeriesSelectSeriesType,
|
||||||
|
ActiveSonarrBlock::AddSeriesTagsInput,
|
||||||
|
ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder,
|
||||||
|
];
|
||||||
|
|
||||||
|
pub const ADD_SERIES_SELECTION_BLOCKS: &[&[ActiveSonarrBlock]] = &[
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectRootFolder],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectMonitor],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectQualityProfile],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectLanguageProfile],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectSeriesType],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesTagsInput],
|
||||||
|
&[ActiveSonarrBlock::AddSeriesConfirmPrompt],
|
||||||
|
];
|
||||||
|
|
||||||
pub static EDIT_SERIES_BLOCKS: [ActiveSonarrBlock; 9] = [
|
pub static EDIT_SERIES_BLOCKS: [ActiveSonarrBlock; 9] = [
|
||||||
ActiveSonarrBlock::EditSeriesPrompt,
|
ActiveSonarrBlock::EditSeriesPrompt,
|
||||||
ActiveSonarrBlock::EditSeriesConfirmPrompt,
|
ActiveSonarrBlock::EditSeriesConfirmPrompt,
|
||||||
|
|||||||
@@ -202,8 +202,9 @@ mod tests {
|
|||||||
|
|
||||||
mod active_sonarr_block_tests {
|
mod active_sonarr_block_tests {
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||||
ActiveSonarrBlock, DELETE_SERIES_BLOCKS, DELETE_SERIES_SELECTION_BLOCKS, DOWNLOADS_BLOCKS,
|
ActiveSonarrBlock, ADD_SERIES_BLOCKS, ADD_SERIES_SELECTION_BLOCKS, DELETE_SERIES_BLOCKS,
|
||||||
EDIT_SERIES_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS, LIBRARY_BLOCKS,
|
DELETE_SERIES_SELECTION_BLOCKS, DOWNLOADS_BLOCKS, EDIT_SERIES_BLOCKS,
|
||||||
|
EDIT_SERIES_SELECTION_BLOCKS, LIBRARY_BLOCKS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -218,6 +219,63 @@ mod tests {
|
|||||||
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::UpdateAllSeriesPrompt));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::UpdateAllSeriesPrompt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_series_blocks_contents() {
|
||||||
|
assert_eq!(ADD_SERIES_BLOCKS.len(), 13);
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesAlreadyInLibrary));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesConfirmPrompt));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesEmptySearchResults));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesPrompt));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSearchInput));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSearchResults));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSelectLanguageProfile));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSelectMonitor));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSelectQualityProfile));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSelectRootFolder));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesSelectSeriesType));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesTagsInput));
|
||||||
|
assert!(ADD_SERIES_BLOCKS.contains(&ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_add_series_selection_blocks_ordering() {
|
||||||
|
let mut add_series_block_iter = ADD_SERIES_SELECTION_BLOCKS.iter();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectRootFolder]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectMonitor]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectQualityProfile]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectLanguageProfile]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesSelectSeriesType]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesToggleUseSeasonFolder]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesTagsInput]
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
add_series_block_iter.next().unwrap(),
|
||||||
|
&[ActiveSonarrBlock::AddSeriesConfirmPrompt]
|
||||||
|
);
|
||||||
|
assert_eq!(add_series_block_iter.next(), None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_edit_movie_blocks_contents() {
|
fn test_edit_movie_blocks_contents() {
|
||||||
assert_eq!(EDIT_SERIES_BLOCKS.len(), 9);
|
assert_eq!(EDIT_SERIES_BLOCKS.len(), 9);
|
||||||
|
|||||||
Reference in New Issue
Block a user