refactor: Migrated the handle_table_events macro into a trait for better IDE support, created a TableEventAdapter wrapper for the KeyEventHandlers to make it so that the trait can be used properly and a simple function to replace the previous call to the handle_table_events macro
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::matches_key;
|
||||
use crate::models::radarr_models::BlocklistItem;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, BLOCKLIST_BLOCKS};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "blocklist_handler_tests.rs"]
|
||||
@@ -21,13 +21,6 @@ pub(super) struct BlocklistHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl BlocklistHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
blocklist,
|
||||
self.app.data.radarr_data.blocklist,
|
||||
BlocklistItem
|
||||
);
|
||||
|
||||
fn extract_blocklist_item_id(&self) -> i64 {
|
||||
self.app.data.radarr_data.blocklist.current_selection().id
|
||||
}
|
||||
@@ -40,7 +33,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a,
|
||||
.sorting_block(ActiveRadarrBlock::BlocklistSortPrompt.into())
|
||||
.sort_options(blocklist_sorting_options());
|
||||
|
||||
if !self.handle_blocklist_table_events(blocklist_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.blocklist,
|
||||
blocklist_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -176,6 +173,14 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for BlocklistHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
fn blocklist_sorting_options() -> Vec<SortOption<BlocklistItem>> {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::matches_key;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::radarr_models::CollectionMovie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ADD_MOVIE_SELECTION_BLOCKS, ActiveRadarrBlock, COLLECTION_DETAILS_BLOCKS,
|
||||
EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "collection_details_handler_tests.rs"]
|
||||
@@ -22,21 +21,18 @@ pub(super) struct CollectionDetailsHandler<'a, 'b> {
|
||||
_context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl CollectionDetailsHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
collection_movies,
|
||||
self.app.data.radarr_data.collection_movies,
|
||||
CollectionMovie
|
||||
);
|
||||
}
|
||||
impl CollectionDetailsHandler<'_, '_> {}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let collection_movies_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::CollectionDetails.into());
|
||||
|
||||
if !self.handle_collection_movies_table_events(collection_movies_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.collection_movies,
|
||||
collection_movies_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -147,4 +143,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionDetailsHan
|
||||
BlockSelectionState::new(EDIT_COLLECTION_SELECTION_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,4 +371,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditCollectionHandle
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::collections::collection_details_handler::CollectionDetailsHandler;
|
||||
use crate::handlers::radarr_handlers::collections::edit_collection_handler::EditCollectionHandler;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::matches_key;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::radarr_models::Collection;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
@@ -12,7 +13,6 @@ use crate::models::servarr_data::radarr::radarr_data::{
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
mod collection_details_handler;
|
||||
mod edit_collection_handler;
|
||||
@@ -28,14 +28,7 @@ pub(super) struct CollectionsHandler<'a, 'b> {
|
||||
context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl CollectionsHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
collections,
|
||||
self.app.data.radarr_data.collections,
|
||||
Collection
|
||||
);
|
||||
}
|
||||
impl CollectionsHandler<'_, '_> {}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
@@ -50,7 +43,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
.filter_error_block(ActiveRadarrBlock::FilterCollectionsError.into())
|
||||
.filter_field_fn(|collection| &collection.title.text);
|
||||
|
||||
if !self.handle_collections_table_events(collections_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.collections,
|
||||
collections_table_handling_config,
|
||||
) {
|
||||
match self.active_radarr_block {
|
||||
_ if CollectionDetailsHandler::accepts(self.active_radarr_block) => {
|
||||
CollectionDetailsHandler::new(self.key, self.app, self.active_radarr_block, self.context)
|
||||
@@ -177,6 +174,14 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
fn collections_sorting_options() -> Vec<SortOption<Collection>> {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::models::radarr_models::DownloadRecord;
|
||||
use crate::matches_key;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, DOWNLOADS_BLOCKS};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "downloads_handler_tests.rs"]
|
||||
@@ -20,13 +19,6 @@ pub(super) struct DownloadsHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl DownloadsHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
downloads,
|
||||
self.app.data.radarr_data.downloads,
|
||||
DownloadRecord
|
||||
);
|
||||
|
||||
fn extract_download_id(&self) -> i64 {
|
||||
self.app.data.radarr_data.downloads.current_selection().id
|
||||
}
|
||||
@@ -37,7 +29,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a,
|
||||
let downloads_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Downloads.into());
|
||||
|
||||
if !self.handle_downloads_table_events(downloads_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.downloads,
|
||||
downloads_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -163,4 +159,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DownloadsHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,4 +522,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditIndexerHandler<'
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,4 +288,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexerSettingsHandl
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,16 +4,15 @@ use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::radarr_handlers::indexers::edit_indexer_handler::EditIndexerHandler;
|
||||
use crate::handlers::radarr_handlers::indexers::edit_indexer_settings_handler::IndexerSettingsHandler;
|
||||
use crate::handlers::radarr_handlers::indexers::test_all_indexers_handler::TestAllIndexersHandler;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::matches_key;
|
||||
use crate::models::BlockSelectionState;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, EDIT_INDEXER_NZB_SELECTION_BLOCKS, EDIT_INDEXER_TORRENT_SELECTION_BLOCKS,
|
||||
INDEXER_SETTINGS_SELECTION_BLOCKS, INDEXERS_BLOCKS,
|
||||
};
|
||||
use crate::models::servarr_models::Indexer;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
mod edit_indexer_handler;
|
||||
mod edit_indexer_settings_handler;
|
||||
@@ -31,8 +30,6 @@ pub(super) struct IndexersHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl IndexersHandler<'_, '_> {
|
||||
handle_table_events!(self, indexers, self.app.data.radarr_data.indexers, Indexer);
|
||||
|
||||
fn extract_indexer_id(&self) -> i64 {
|
||||
self.app.data.radarr_data.indexers.current_selection().id
|
||||
}
|
||||
@@ -43,7 +40,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a,
|
||||
let indexer_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::Indexers.into());
|
||||
|
||||
if !self.handle_indexers_table_events(indexer_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.indexers,
|
||||
indexer_table_handling_config,
|
||||
) {
|
||||
match self.active_radarr_block {
|
||||
_ if EditIndexerHandler::accepts(self.active_radarr_block) => {
|
||||
EditIndexerHandler::new(self.key, self.app, self.active_radarr_block, self.context)
|
||||
@@ -206,4 +207,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for IndexersHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handle_table_events;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::models::servarr_data::modals::IndexerTestResultModalItem;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -17,27 +15,23 @@ pub(super) struct TestAllIndexersHandler<'a, 'b> {
|
||||
_context: Option<ActiveRadarrBlock>,
|
||||
}
|
||||
|
||||
impl TestAllIndexersHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
indexer_test_all_results,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap(),
|
||||
IndexerTestResultModalItem
|
||||
);
|
||||
}
|
||||
impl TestAllIndexersHandler<'_, '_> {}
|
||||
|
||||
impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for TestAllIndexersHandler<'a, 'b> {
|
||||
fn handle(&mut self) {
|
||||
let test_all_indexers_test_results_table_handler_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::TestAllIndexers.into());
|
||||
|
||||
if !self.handle_indexer_test_all_results_table_events(
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.indexer_test_all_results
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
},
|
||||
test_all_indexers_test_results_table_handler_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
@@ -102,4 +96,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for TestAllIndexersHandl
|
||||
}
|
||||
|
||||
fn handle_char_key_event(&mut self) {}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
|
||||
use crate::models::radarr_models::{
|
||||
AddMovieBody, AddMovieOptions, AddMovieSearchResult, CollectionMovie,
|
||||
@@ -9,9 +9,7 @@ use crate::models::servarr_data::radarr::radarr_data::{
|
||||
};
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{
|
||||
App, Key, handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key,
|
||||
};
|
||||
use crate::{App, Key, handle_text_box_keys, handle_text_box_left_right_keys, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "add_movie_handler_tests.rs"]
|
||||
@@ -25,19 +23,6 @@ pub(super) struct AddMovieHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl AddMovieHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
add_movie_search_results,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.expect("add_searched_movies should be initialized"),
|
||||
AddMovieSearchResult
|
||||
);
|
||||
|
||||
fn build_add_movie_body(&mut self) -> AddMovieBody {
|
||||
let add_movie_modal = self
|
||||
.app
|
||||
@@ -123,7 +108,18 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
let add_movie_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::AddMovieSearchResults.into());
|
||||
|
||||
if !self.handle_add_movie_search_results_table_events(add_movie_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.add_searched_movies
|
||||
.as_mut()
|
||||
.expect("add_searched_movies should be initialized")
|
||||
},
|
||||
add_movie_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -557,4 +553,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for AddMovieHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,4 +136,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for DeleteMovieHandler<'
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,4 +392,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for EditMovieHandler<'a,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ use crate::handlers::radarr_handlers::library::edit_movie_handler::EditMovieHand
|
||||
use crate::handlers::radarr_handlers::library::movie_details_handler::MovieDetailsHandler;
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::matches_key;
|
||||
use crate::models::radarr_models::Movie;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, DELETE_MOVIE_SELECTION_BLOCKS, EDIT_MOVIE_SELECTION_BLOCKS, LIBRARY_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText};
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Route};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
mod add_movie_handler;
|
||||
mod delete_movie_handler;
|
||||
@@ -34,7 +34,6 @@ pub(super) struct LibraryHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl LibraryHandler<'_, '_> {
|
||||
handle_table_events!(self, movies, self.app.data.radarr_data.movies, Movie);
|
||||
fn extract_movie_id(&self) -> i64 {
|
||||
self.app.data.radarr_data.movies.current_selection().id
|
||||
}
|
||||
@@ -52,7 +51,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, '
|
||||
.filter_error_block(ActiveRadarrBlock::FilterMoviesError.into())
|
||||
.filter_field_fn(|movie| &movie.title.text);
|
||||
|
||||
if !self.handle_movies_table_events(movie_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.movies,
|
||||
movie_table_handling_config,
|
||||
) {
|
||||
match self.active_radarr_block {
|
||||
_ if AddMovieHandler::accepts(self.active_radarr_block) => {
|
||||
AddMovieHandler::new(self.key, self.app, self.active_radarr_block, self.context).handle();
|
||||
@@ -215,6 +218,14 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for LibraryHandler<'a, '
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
fn movies_sorting_options() -> Vec<SortOption<Movie>> {
|
||||
|
||||
@@ -2,11 +2,10 @@ use serde_json::Number;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
|
||||
use crate::models::radarr_models::{
|
||||
Credit, MovieHistoryItem, RadarrRelease, RadarrReleaseDownloadBody,
|
||||
};
|
||||
use crate::matches_key;
|
||||
use crate::models::radarr_models::{RadarrRelease, RadarrReleaseDownloadBody};
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, EDIT_MOVIE_SELECTION_BLOCKS, MOVIE_DETAILS_BLOCKS,
|
||||
};
|
||||
@@ -14,7 +13,6 @@ use crate::models::servarr_models::Language;
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, Scrollable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{handle_table_events, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "movie_details_handler_tests.rs"]
|
||||
@@ -28,59 +26,6 @@ pub(super) struct MovieDetailsHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl MovieDetailsHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_releases,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_releases,
|
||||
RadarrRelease
|
||||
);
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_history,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_history,
|
||||
MovieHistoryItem
|
||||
);
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_cast,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_cast,
|
||||
Credit
|
||||
);
|
||||
handle_table_events!(
|
||||
self,
|
||||
movie_crew,
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_crew,
|
||||
Credit
|
||||
);
|
||||
|
||||
fn build_radarr_release_download_body(&self) -> RadarrReleaseDownloadBody {
|
||||
let movie_id = self.app.data.radarr_data.movies.current_selection().id;
|
||||
let (guid, indexer_id) = {
|
||||
@@ -122,11 +67,55 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
let movie_cast_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::Cast.into());
|
||||
let movie_crew_table_handling_config = TableHandlingConfig::new(ActiveRadarrBlock::Crew.into());
|
||||
|
||||
if !self.handle_movie_history_table_events(movie_history_table_handling_config)
|
||||
&& !self.handle_movie_releases_table_events(movie_releases_table_handling_config)
|
||||
&& !self.handle_movie_cast_table_events(movie_cast_table_handling_config)
|
||||
&& !self.handle_movie_crew_table_events(movie_crew_table_handling_config)
|
||||
{
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_history
|
||||
},
|
||||
movie_history_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_releases
|
||||
},
|
||||
movie_releases_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_cast
|
||||
},
|
||||
movie_cast_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
&mut app
|
||||
.data
|
||||
.radarr_data
|
||||
.movie_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.movie_crew
|
||||
},
|
||||
movie_crew_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -385,6 +374,14 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for MovieDetailsHandler<
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
fn releases_sorting_options() -> Vec<SortOption<RadarrRelease>> {
|
||||
|
||||
@@ -107,6 +107,14 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RadarrHandler<'a, 'b
|
||||
fn handle_esc(&mut self) {}
|
||||
|
||||
fn handle_char_key_event(&mut self) {}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_change_tab_left_right_keys(app: &mut App<'_>, key: Key) {
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
use crate::app::App;
|
||||
use crate::event::Key;
|
||||
use crate::handlers::radarr_handlers::handle_change_tab_left_right_keys;
|
||||
use crate::handlers::table_handler::TableHandlingConfig;
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_clear_errors, handle_prompt_toggle};
|
||||
use crate::models::HorizontallyScrollableText;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, ROOT_FOLDERS_BLOCKS};
|
||||
use crate::models::servarr_models::{AddRootFolderBody, RootFolder};
|
||||
use crate::models::servarr_models::AddRootFolderBody;
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::{
|
||||
handle_table_events, handle_text_box_keys, handle_text_box_left_right_keys, matches_key,
|
||||
};
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys, matches_key};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "root_folders_handler_tests.rs"]
|
||||
@@ -23,13 +21,6 @@ pub(super) struct RootFoldersHandler<'a, 'b> {
|
||||
}
|
||||
|
||||
impl RootFoldersHandler<'_, '_> {
|
||||
handle_table_events!(
|
||||
self,
|
||||
root_folders,
|
||||
self.app.data.radarr_data.root_folders,
|
||||
RootFolder
|
||||
);
|
||||
|
||||
fn build_add_root_folder_body(&mut self) -> AddRootFolderBody {
|
||||
let edit_root_folder = self
|
||||
.app
|
||||
@@ -60,7 +51,11 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<'
|
||||
let root_folder_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveRadarrBlock::RootFolders.into());
|
||||
|
||||
if !self.handle_root_folders_table_events(root_folder_table_handling_config) {
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.radarr_data.root_folders,
|
||||
root_folder_table_handling_config,
|
||||
) {
|
||||
self.handle_key_event();
|
||||
}
|
||||
}
|
||||
@@ -231,4 +226,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for RootFoldersHandler<'
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +124,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemHandler<'a, 'b
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,4 +196,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for SystemDetailsHandler
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
|
||||
fn app_mut(&mut self) -> &mut App<'b> {
|
||||
self.app
|
||||
}
|
||||
|
||||
fn current_route(&self) -> crate::models::Route {
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user