Refactored the UI module and the handlers module to do a more chain-of-responsibility method to manage the UI's and handlers for different key events. Also, initial work for indexer settings as well

This commit is contained in:
2023-08-08 10:50:07 -06:00
parent 718613d59f
commit cf11527fef
67 changed files with 5255 additions and 2216 deletions
+5
View File
@@ -22,6 +22,7 @@ generate_keybindings! {
edit,
logs,
tasks,
restrictions,
refresh,
update,
events,
@@ -95,6 +96,10 @@ pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
key: Key::Char('t'),
desc: "Tasks",
},
restrictions: KeyBinding {
key: Key::Char('t'),
desc: "Restrictions",
},
refresh: KeyBinding {
key: Key::Char('r'),
desc: "Refresh",
+187 -133
View File
@@ -1,6 +1,7 @@
use bimap::BiMap;
use chrono::{DateTime, Utc};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
use crate::app::{App, Route};
use crate::models::radarr_models::{
@@ -250,134 +251,134 @@ impl<'a> RadarrData<'a> {
impl<'a> Default for RadarrData<'a> {
fn default() -> RadarrData<'a> {
RadarrData {
root_folders: StatefulTable::default(),
disk_space_vec: Vec::new(),
version: String::default(),
start_time: DateTime::default(),
movies: StatefulTable::default(),
add_searched_movies: StatefulTable::default(),
monitor_list: StatefulList::default(),
minimum_availability_list: StatefulList::default(),
quality_profile_list: StatefulList::default(),
root_folder_list: StatefulList::default(),
selected_block: BlockSelectionState::default(),
filtered_movies: StatefulTable::default(),
downloads: StatefulTable::default(),
indexers: StatefulTable::default(),
indexer_settings: None,
quality_profile_map: BiMap::default(),
tags_map: BiMap::default(),
file_details: String::default(),
audio_details: String::default(),
video_details: String::default(),
movie_details: ScrollableText::default(),
movie_history: StatefulTable::default(),
movie_cast: StatefulTable::default(),
movie_crew: StatefulTable::default(),
movie_releases: StatefulTable::default(),
movie_releases_sort: StatefulList::default(),
collections: StatefulTable::default(),
filtered_collections: StatefulTable::default(),
collection_movies: StatefulTable::default(),
logs: StatefulList::default(),
log_details: StatefulList::default(),
tasks: StatefulTable::default(),
queued_events: StatefulTable::default(),
updates: ScrollableText::default(),
prompt_confirm_action: None,
search: HorizontallyScrollableText::default(),
filter: HorizontallyScrollableText::default(),
edit_path: HorizontallyScrollableText::default(),
edit_tags: HorizontallyScrollableText::default(),
edit_monitored: None,
edit_search_on_add: None,
sort_ascending: None,
is_searching: false,
is_filtering: false,
prompt_confirm: false,
delete_movie_files: false,
add_list_exclusion: false,
main_tabs: TabState::new(vec![
TabRoute {
title: "Library",
route: ActiveRadarrBlock::Movies.into(),
help: "",
contextual_help: Some("<a> add | <e> edit | <del> delete | <s> search | <f> filter | <r> refresh | <u> update all | <enter> details | <esc> cancel filter"),
},
TabRoute {
title: "Downloads",
route: ActiveRadarrBlock::Downloads.into(),
help: "",
contextual_help: Some("<r> refresh | <del> delete"),
},
TabRoute {
title: "Collections",
route: ActiveRadarrBlock::Collections.into(),
help: "",
contextual_help: Some("<s> search | <e> edit | <f> filter | <r> refresh | <u> update all | <enter> details | <esc> cancel filter"),
},
TabRoute {
title: "Root Folders",
route: ActiveRadarrBlock::RootFolders.into(),
help: "",
contextual_help: Some("<a> add | <del> delete | <r> refresh"),
},
TabRoute {
title: "Indexers",
route: ActiveRadarrBlock::Indexers.into(),
help: "",
contextual_help: Some("<enter> edit | <s> settings | <del> delete | <r> refresh"),
},
TabRoute {
title: "System",
route: ActiveRadarrBlock::System.into(),
help: "",
contextual_help: Some("<t> open tasks | <e> open events | <l> open logs | <u> open updates | <r> refresh")
}
]),
movie_info_tabs: TabState::new(vec![
TabRoute {
title: "Details",
route: ActiveRadarrBlock::MovieDetails.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None
},
TabRoute {
title: "History",
route: ActiveRadarrBlock::MovieHistory.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None
},
TabRoute {
title: "File",
route: ActiveRadarrBlock::FileInfo.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Cast",
route: ActiveRadarrBlock::Cast.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Crew",
route: ActiveRadarrBlock::Crew.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Manual Search",
route: ActiveRadarrBlock::ManualSearch.into(),
help: "<r> refresh | <u> update | <e> edit | <o> sort | <s> auto search | <esc> close",
contextual_help: Some("<enter> details")
}
]),
}
root_folders: StatefulTable::default(),
disk_space_vec: Vec::new(),
version: String::default(),
start_time: DateTime::default(),
movies: StatefulTable::default(),
add_searched_movies: StatefulTable::default(),
monitor_list: StatefulList::default(),
minimum_availability_list: StatefulList::default(),
quality_profile_list: StatefulList::default(),
root_folder_list: StatefulList::default(),
selected_block: BlockSelectionState::default(),
filtered_movies: StatefulTable::default(),
downloads: StatefulTable::default(),
indexers: StatefulTable::default(),
indexer_settings: None,
quality_profile_map: BiMap::default(),
tags_map: BiMap::default(),
file_details: String::default(),
audio_details: String::default(),
video_details: String::default(),
movie_details: ScrollableText::default(),
movie_history: StatefulTable::default(),
movie_cast: StatefulTable::default(),
movie_crew: StatefulTable::default(),
movie_releases: StatefulTable::default(),
movie_releases_sort: StatefulList::default(),
collections: StatefulTable::default(),
filtered_collections: StatefulTable::default(),
collection_movies: StatefulTable::default(),
logs: StatefulList::default(),
log_details: StatefulList::default(),
tasks: StatefulTable::default(),
queued_events: StatefulTable::default(),
updates: ScrollableText::default(),
prompt_confirm_action: None,
search: HorizontallyScrollableText::default(),
filter: HorizontallyScrollableText::default(),
edit_path: HorizontallyScrollableText::default(),
edit_tags: HorizontallyScrollableText::default(),
edit_monitored: None,
edit_search_on_add: None,
sort_ascending: None,
is_searching: false,
is_filtering: false,
prompt_confirm: false,
delete_movie_files: false,
add_list_exclusion: false,
main_tabs: TabState::new(vec![
TabRoute {
title: "Library",
route: ActiveRadarrBlock::Movies.into(),
help: "",
contextual_help: Some("<a> add | <e> edit | <del> delete | <s> search | <f> filter | <r> refresh | <u> update all | <enter> details | <esc> cancel filter"),
},
TabRoute {
title: "Downloads",
route: ActiveRadarrBlock::Downloads.into(),
help: "",
contextual_help: Some("<r> refresh | <del> delete"),
},
TabRoute {
title: "Collections",
route: ActiveRadarrBlock::Collections.into(),
help: "",
contextual_help: Some("<s> search | <e> edit | <f> filter | <r> refresh | <u> update all | <enter> details | <esc> cancel filter"),
},
TabRoute {
title: "Root Folders",
route: ActiveRadarrBlock::RootFolders.into(),
help: "",
contextual_help: Some("<a> add | <del> delete | <r> refresh"),
},
TabRoute {
title: "Indexers",
route: ActiveRadarrBlock::Indexers.into(),
help: "",
contextual_help: Some("<a> add | <enter> edit | <s> settings | <t> restrictions | <del> delete | <r> refresh"),
},
TabRoute {
title: "System",
route: ActiveRadarrBlock::System.into(),
help: "",
contextual_help: Some("<t> open tasks | <e> open events | <l> open logs | <u> open updates | <r> refresh"),
},
]),
movie_info_tabs: TabState::new(vec![
TabRoute {
title: "Details",
route: ActiveRadarrBlock::MovieDetails.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "History",
route: ActiveRadarrBlock::MovieHistory.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "File",
route: ActiveRadarrBlock::FileInfo.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Cast",
route: ActiveRadarrBlock::Cast.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Crew",
route: ActiveRadarrBlock::Crew.into(),
help: "<r> refresh | <u> update | <e> edit | <s> auto search | <esc> close",
contextual_help: None,
},
TabRoute {
title: "Manual Search",
route: ActiveRadarrBlock::ManualSearch.into(),
help: "<r> refresh | <u> update | <e> edit | <o> sort | <s> auto search | <esc> close",
contextual_help: Some("<enter> details"),
},
]),
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, EnumIter)]
pub enum ActiveRadarrBlock {
AddIndexer,
AddMovieAlreadyInLibrary,
@@ -424,7 +425,16 @@ pub enum ActiveRadarrBlock {
FilterCollections,
FilterMovies,
Indexers,
IndexerSettings,
IndexerSettingsPrompt,
IndexerSettingsAvailabilityDelayInput,
IndexerSettingsConfirmPrompt,
IndexerSettingsMaximumSizeInput,
IndexerSettingsMinimumAgeInput,
IndexerSettingsRetentionInput,
IndexerSettingsRssSyncIntervalInput,
IndexerSettingsToggleAllowHardcodedSubs,
IndexerSettingsTogglePreferIndexerFlags,
IndexerSettingsWhitelistedSubtitleTagsInput,
ManualSearch,
ManualSearchSortPrompt,
ManualSearchConfirmPrompt,
@@ -448,6 +458,29 @@ pub enum ActiveRadarrBlock {
ViewMovieOverview,
}
pub static LIBRARY_BLOCKS: [ActiveRadarrBlock; 4] = [
ActiveRadarrBlock::Movies,
ActiveRadarrBlock::SearchMovie,
ActiveRadarrBlock::FilterMovies,
ActiveRadarrBlock::UpdateAllMoviesPrompt,
];
pub static COLLECTIONS_BLOCKS: [ActiveRadarrBlock; 4] = [
ActiveRadarrBlock::Collections,
ActiveRadarrBlock::SearchCollection,
ActiveRadarrBlock::FilterCollections,
ActiveRadarrBlock::UpdateAllCollectionsPrompt,
];
pub static INDEXERS_BLOCKS: [ActiveRadarrBlock; 4] = [
ActiveRadarrBlock::AddIndexer,
ActiveRadarrBlock::EditIndexer,
ActiveRadarrBlock::DeleteIndexerPrompt,
ActiveRadarrBlock::Indexers,
];
pub static ROOT_FOLDERS_BLOCKS: [ActiveRadarrBlock; 3] = [
ActiveRadarrBlock::RootFolders,
ActiveRadarrBlock::AddRootFolderPrompt,
ActiveRadarrBlock::DeleteRootFolderPrompt,
];
pub static ADD_MOVIE_BLOCKS: [ActiveRadarrBlock; 10] = [
ActiveRadarrBlock::AddMovieSearchInput,
ActiveRadarrBlock::AddMovieSearchResults,
@@ -502,6 +535,11 @@ pub static EDIT_MOVIE_SELECTION_BLOCKS: [ActiveRadarrBlock; 6] = [
ActiveRadarrBlock::EditMovieTagsInput,
ActiveRadarrBlock::EditMovieConfirmPrompt,
];
pub static DOWNLOADS_BLOCKS: [ActiveRadarrBlock; 3] = [
ActiveRadarrBlock::Downloads,
ActiveRadarrBlock::DeleteDownloadPrompt,
ActiveRadarrBlock::UpdateDownloadsPrompt,
];
pub static MOVIE_DETAILS_BLOCKS: [ActiveRadarrBlock; 10] = [
ActiveRadarrBlock::MovieDetails,
ActiveRadarrBlock::MovieHistory,
@@ -537,12 +575,28 @@ pub static DELETE_MOVIE_SELECTION_BLOCKS: [ActiveRadarrBlock; 3] = [
ActiveRadarrBlock::DeleteMovieToggleAddListExclusion,
ActiveRadarrBlock::DeleteMovieConfirmPrompt,
];
pub static INDEXER_BLOCKS: [ActiveRadarrBlock; 5] = [
ActiveRadarrBlock::Indexers,
ActiveRadarrBlock::IndexerSettings,
ActiveRadarrBlock::AddIndexer,
ActiveRadarrBlock::EditIndexer,
ActiveRadarrBlock::DeleteIndexerPrompt,
pub static INDEXER_SETTINGS_BLOCKS: [ActiveRadarrBlock; 10] = [
ActiveRadarrBlock::IndexerSettingsPrompt,
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
ActiveRadarrBlock::IndexerSettingsConfirmPrompt,
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
ActiveRadarrBlock::IndexerSettingsRetentionInput,
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs,
ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags,
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
];
pub static INDEXER_SETTINGS_SELECTION_BLOCKS: [ActiveRadarrBlock; 9] = [
ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
ActiveRadarrBlock::IndexerSettingsRetentionInput,
ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags,
ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs,
ActiveRadarrBlock::IndexerSettingsConfirmPrompt,
];
pub static SYSTEM_DETAILS_BLOCKS: [ActiveRadarrBlock; 5] = [
ActiveRadarrBlock::SystemLogs,
@@ -600,7 +654,7 @@ impl<'a> App<'a> {
.dispatch_network_event(RadarrEvent::GetIndexers.into())
.await;
}
ActiveRadarrBlock::IndexerSettings => {
ActiveRadarrBlock::IndexerSettingsPrompt => {
self
.dispatch_network_event(RadarrEvent::GetIndexerSettings.into())
.await;
+49 -3
View File
@@ -30,7 +30,7 @@ mod tests {
)),
Route::Radarr(
ActiveRadarrBlock::AddMoviePrompt,
Some(ActiveRadarrBlock::AddMovieSearchResults)
Some(ActiveRadarrBlock::AddMovieSearchResults),
)
);
}
@@ -358,7 +358,9 @@ mod tests {
assert!(radarr_data.main_tabs.tabs[4].help.is_empty());
assert_eq!(
radarr_data.main_tabs.tabs[4].contextual_help,
Some("<enter> edit | <s> settings | <del> delete | <r> refresh")
Some(
"<a> add | <enter> edit | <s> settings | <t> restrictions | <del> delete | <r> refresh"
)
);
assert_str_eq!(radarr_data.main_tabs.tabs[5].title, "System");
@@ -461,6 +463,7 @@ mod tests {
use crate::app::radarr::{
ActiveRadarrBlock, ADD_MOVIE_SELECTION_BLOCKS, DELETE_MOVIE_SELECTION_BLOCKS,
EDIT_COLLECTION_SELECTION_BLOCKS, EDIT_MOVIE_SELECTION_BLOCKS,
INDEXER_SETTINGS_SELECTION_BLOCKS,
};
#[test]
@@ -556,6 +559,7 @@ mod tests {
#[test]
fn test_delete_movie_prompt_block_order() {
let mut delete_movie_block_iter = DELETE_MOVIE_SELECTION_BLOCKS.iter();
assert_eq!(
delete_movie_block_iter.next().unwrap(),
&ActiveRadarrBlock::DeleteMovieToggleDeleteFile
@@ -569,6 +573,48 @@ mod tests {
&ActiveRadarrBlock::DeleteMovieConfirmPrompt
);
}
#[test]
fn test_indexer_settings_prompt_block_order() {
let mut indexer_settings_block_iter = INDEXER_SETTINGS_SELECTION_BLOCKS.iter();
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsMinimumAgeInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsRetentionInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsMaximumSizeInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs
);
assert_eq!(
indexer_settings_block_iter.next().unwrap(),
&ActiveRadarrBlock::IndexerSettingsConfirmPrompt
);
}
}
mod radarr_tests {
@@ -719,7 +765,7 @@ mod tests {
let (mut app, mut sync_network_rx) = construct_app_unit();
app
.dispatch_by_radarr_block(&ActiveRadarrBlock::IndexerSettings)
.dispatch_by_radarr_block(&ActiveRadarrBlock::IndexerSettingsPrompt)
.await;
assert!(app.is_loading);