feat(handler): Edit series support

This commit is contained in:
2024-12-02 14:58:51 -07:00
parent 82e51be096
commit adb1f07fd0
5 changed files with 1762 additions and 28 deletions
@@ -535,9 +535,7 @@ mod tests {
use rstest::rstest;
use crate::models::servarr_data::radarr::modals::EditMovieModal;
use crate::models::servarr_data::radarr::radarr_data::{
EDIT_COLLECTION_SELECTION_BLOCKS, EDIT_MOVIE_SELECTION_BLOCKS,
};
use crate::models::servarr_data::radarr::radarr_data::EDIT_MOVIE_SELECTION_BLOCKS;
use crate::models::{BlockSelectionState, Route};
use crate::network::radarr_network::RadarrEvent;
@@ -626,7 +624,7 @@ mod tests {
.data
.radarr_data
.selected_block
.set_index(0, EDIT_COLLECTION_SELECTION_BLOCKS.len() - 1);
.set_index(0, EDIT_MOVIE_SELECTION_BLOCKS.len() - 1);
EditMovieHandler::with(
SUBMIT_KEY,
@@ -652,7 +650,7 @@ mod tests {
.data
.radarr_data
.selected_block
.set_index(0, EDIT_COLLECTION_SELECTION_BLOCKS.len() - 1);
.set_index(0, EDIT_MOVIE_SELECTION_BLOCKS.len() - 1);
EditMovieHandler::with(
SUBMIT_KEY,
@@ -936,10 +934,7 @@ mod tests {
use super::*;
use crate::{
models::{
servarr_data::radarr::{
modals::EditMovieModal,
radarr_data::{EDIT_COLLECTION_SELECTION_BLOCKS, EDIT_MOVIE_SELECTION_BLOCKS},
},
servarr_data::radarr::{modals::EditMovieModal, radarr_data::EDIT_MOVIE_SELECTION_BLOCKS},
BlockSelectionState,
},
network::radarr_network::RadarrEvent,
@@ -1066,7 +1061,7 @@ mod tests {
.data
.radarr_data
.selected_block
.set_index(0, EDIT_COLLECTION_SELECTION_BLOCKS.len() - 1);
.set_index(0, EDIT_MOVIE_SELECTION_BLOCKS.len() - 1);
EditMovieHandler::with(
DEFAULT_KEYBINDINGS.confirm.key,
@@ -0,0 +1,408 @@
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();
}
}
_ => (),
}
}
}
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::KeyEventHandler;
use crate::models::servarr_data::sonarr::sonarr_data::{
ActiveSonarrBlock, ADD_SERIES_BLOCKS, DELETE_SERIES_BLOCKS, LIBRARY_BLOCKS,
ActiveSonarrBlock, ADD_SERIES_BLOCKS, DELETE_SERIES_BLOCKS, EDIT_SERIES_BLOCKS, LIBRARY_BLOCKS,
};
use crate::models::sonarr_models::{Series, SeriesStatus, SeriesType};
use crate::models::stateful_table::SortOption;
@@ -1487,23 +1487,24 @@ mod tests {
// );
// }
// #[rstest]
// fn test_delegates_edit_series_blocks_to_edit_series_handler(
// #[values(
// ActiveSonarrBlock::EditSeriesPrompt,
// ActiveSonarrBlock::EditSeriesPathInput,
// ActiveSonarrBlock::EditSeriesSelectMinimumAvailability,
// ActiveSonarrBlock::EditSeriesSelectQualityProfile,
// ActiveSonarrBlock::EditSeriesTagsInput
// )]
// active_sonarr_block: ActiveSonarrBlock,
// ) {
// test_handler_delegation!(
// LibraryHandler,
// ActiveSonarrBlock::Series,
// active_sonarr_block
// );
// }
#[rstest]
fn test_delegates_edit_series_blocks_to_edit_series_handler(
#[values(
ActiveSonarrBlock::EditSeriesPrompt,
ActiveSonarrBlock::EditSeriesPathInput,
ActiveSonarrBlock::EditSeriesSelectSeriesType,
ActiveSonarrBlock::EditSeriesSelectQualityProfile,
ActiveSonarrBlock::EditSeriesSelectLanguageProfile,
ActiveSonarrBlock::EditSeriesTagsInput
)]
active_sonarr_block: ActiveSonarrBlock,
) {
test_handler_delegation!(
LibraryHandler,
ActiveSonarrBlock::Series,
active_sonarr_block
);
}
#[test]
fn test_delegates_delete_series_blocks_to_delete_series_handler() {
@@ -1709,6 +1710,7 @@ mod tests {
library_handler_blocks.extend(LIBRARY_BLOCKS);
library_handler_blocks.extend(ADD_SERIES_BLOCKS);
library_handler_blocks.extend(DELETE_SERIES_BLOCKS);
library_handler_blocks.extend(EDIT_SERIES_BLOCKS);
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
if library_handler_blocks.contains(&active_sonarr_block) {
@@ -1,5 +1,7 @@
use add_series_handler::AddSeriesHandler;
mod edit_series_handler;
use delete_series_handler::DeleteSeriesHandler;
use edit_series_handler::EditSeriesHandler;
use crate::{
app::App,
@@ -45,6 +47,10 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
DeleteSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
.handle();
}
_ if EditSeriesHandler::accepts(self.active_sonarr_block) => {
EditSeriesHandler::with(self.key, self.app, self.active_sonarr_block, self.context)
.handle();
}
_ => self.handle_key_event(),
}
}
@@ -52,6 +58,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
fn accepts(active_block: ActiveSonarrBlock) -> bool {
AddSeriesHandler::accepts(active_block)
|| DeleteSeriesHandler::accepts(active_block)
|| EditSeriesHandler::accepts(active_block)
|| LIBRARY_BLOCKS.contains(&active_block)
}