feat: Implemented the manual artist discography search tab in Lidarr's artist details UI
This commit is contained in:
@@ -5,13 +5,17 @@ use crate::handlers::lidarr_handlers::library::delete_album_handler::DeleteAlbum
|
||||
use crate::handlers::table_handler::{TableHandlingConfig, handle_table};
|
||||
use crate::handlers::{KeyEventHandler, handle_prompt_toggle};
|
||||
use crate::matches_key;
|
||||
use crate::models::lidarr_models::{Album, LidarrHistoryItem};
|
||||
use crate::models::lidarr_models::{
|
||||
Album, LidarrHistoryItem, LidarrRelease, LidarrReleaseDownloadBody,
|
||||
};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_SELECTION_BLOCKS,
|
||||
EDIT_ARTIST_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::SortOption;
|
||||
use crate::models::{BlockSelectionState, Route};
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
use serde_json::Number;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "artist_details_handler_tests.rs"]
|
||||
@@ -53,21 +57,23 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
.filter_error_block(ActiveLidarrBlock::FilterArtistHistoryError.into())
|
||||
.filter_field_fn(|history_item: &LidarrHistoryItem| &history_item.source_title.text);
|
||||
|
||||
let artist_releases_table_handling_config =
|
||||
TableHandlingConfig::new(ActiveLidarrBlock::ManualArtistSearch.into())
|
||||
.sorting_block(ActiveLidarrBlock::ManualArtistSearchSortPrompt.into())
|
||||
.sort_options(releases_sorting_options());
|
||||
|
||||
if !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.lidarr_data.albums,
|
||||
albums_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| {
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_mut()
|
||||
.expect("Artist history is undefined")
|
||||
},
|
||||
|app| &mut app.data.lidarr_data.artist_history,
|
||||
artist_history_table_handling_config,
|
||||
) && !handle_table(
|
||||
self,
|
||||
|app| &mut app.data.lidarr_data.discography_releases,
|
||||
artist_releases_table_handling_config,
|
||||
) {
|
||||
match self.active_lidarr_block {
|
||||
_ if DeleteAlbumHandler::accepts(self.active_lidarr_block) => {
|
||||
@@ -106,10 +112,16 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
}
|
||||
|
||||
fn is_ready(&self) -> bool {
|
||||
if self.active_lidarr_block == ActiveLidarrBlock::ArtistHistory {
|
||||
!self.app.is_loading && self.app.data.lidarr_data.artist_history.is_some()
|
||||
} else {
|
||||
!self.app.is_loading
|
||||
if self.app.is_loading {
|
||||
return false;
|
||||
}
|
||||
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::ArtistHistory => !self.app.data.lidarr_data.artist_history.is_empty(),
|
||||
ActiveLidarrBlock::ManualArtistSearch => {
|
||||
!self.app.data.lidarr_data.discography_releases.is_empty()
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +145,9 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
|
||||
fn handle_left_right_action(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::ArtistDetails | ActiveLidarrBlock::ArtistHistory => match self.key {
|
||||
ActiveLidarrBlock::ArtistDetails
|
||||
| ActiveLidarrBlock::ArtistHistory
|
||||
| ActiveLidarrBlock::ManualArtistSearch => match self.key {
|
||||
_ if matches_key!(left, self.key) => {
|
||||
self.app.data.lidarr_data.artist_info_tabs.previous();
|
||||
self.app.pop_and_push_navigation_stack(
|
||||
@@ -159,7 +173,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
_ => (),
|
||||
},
|
||||
ActiveLidarrBlock::UpdateAndScanArtistPrompt
|
||||
| ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
| ActiveLidarrBlock::AutomaticallySearchArtistPrompt
|
||||
| ActiveLidarrBlock::ManualArtistSearchConfirmPrompt => {
|
||||
handle_prompt_toggle(self.app, self.key);
|
||||
}
|
||||
_ => (),
|
||||
@@ -168,20 +183,34 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
|
||||
fn handle_submit(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::ArtistHistory
|
||||
if !self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.expect("Artist history should be Some")
|
||||
.is_empty() =>
|
||||
{
|
||||
ActiveLidarrBlock::ArtistHistory if !self.app.data.lidarr_data.artist_history.is_empty() => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::ArtistHistoryDetails.into());
|
||||
}
|
||||
ActiveLidarrBlock::ManualArtistSearch => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveLidarrBlock::ManualArtistSearchConfirmPrompt.into());
|
||||
}
|
||||
ActiveLidarrBlock::ManualArtistSearchConfirmPrompt => {
|
||||
if self.app.data.lidarr_data.prompt_confirm {
|
||||
let LidarrRelease {
|
||||
guid, indexer_id, ..
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.discography_releases
|
||||
.current_selection()
|
||||
.clone();
|
||||
let params = LidarrReleaseDownloadBody { guid, indexer_id };
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::DownloadRelease(params));
|
||||
}
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
if self.app.data.lidarr_data.prompt_confirm {
|
||||
self.app.data.lidarr_data.prompt_confirm_action = Some(
|
||||
@@ -206,7 +235,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
fn handle_esc(&mut self) {
|
||||
match self.active_lidarr_block {
|
||||
ActiveLidarrBlock::UpdateAndScanArtistPrompt
|
||||
| ActiveLidarrBlock::AutomaticallySearchArtistPrompt => {
|
||||
| ActiveLidarrBlock::AutomaticallySearchArtistPrompt
|
||||
| ActiveLidarrBlock::ManualArtistSearchConfirmPrompt => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.prompt_confirm = false;
|
||||
}
|
||||
@@ -219,25 +249,16 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.expect("Artist history is not populated")
|
||||
.filtered_items
|
||||
.is_some()
|
||||
{
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_mut()
|
||||
.expect("Artist history is not populated")
|
||||
.reset_filter();
|
||||
self.app.data.lidarr_data.artist_history.reset_filter();
|
||||
} else {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.reset_artist_info_tabs();
|
||||
}
|
||||
}
|
||||
ActiveLidarrBlock::ArtistDetails => {
|
||||
ActiveLidarrBlock::ArtistDetails | ActiveLidarrBlock::ManualArtistSearch => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.lidarr_data.reset_artist_info_tabs();
|
||||
}
|
||||
@@ -287,7 +308,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
ActiveLidarrBlock::ArtistHistory => match self.key {
|
||||
ActiveLidarrBlock::ArtistHistory | ActiveLidarrBlock::ManualArtistSearch => match self.key {
|
||||
_ if matches_key!(refresh, key) => self
|
||||
.app
|
||||
.pop_and_push_navigation_stack(self.active_lidarr_block.into()),
|
||||
@@ -334,6 +355,25 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
ActiveLidarrBlock::ManualArtistSearchConfirmPrompt => {
|
||||
if matches_key!(confirm, key) {
|
||||
self.app.data.lidarr_data.prompt_confirm = true;
|
||||
let LidarrRelease {
|
||||
guid, indexer_id, ..
|
||||
} = self
|
||||
.app
|
||||
.data
|
||||
.lidarr_data
|
||||
.discography_releases
|
||||
.current_selection()
|
||||
.clone();
|
||||
let params = LidarrReleaseDownloadBody { guid, indexer_id };
|
||||
self.app.data.lidarr_data.prompt_confirm_action =
|
||||
Some(LidarrEvent::DownloadRelease(params));
|
||||
|
||||
self.app.pop_navigation_stack();
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
@@ -346,3 +386,61 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveLidarrBlock> for ArtistDetailsHandler
|
||||
self.app.get_current_route()
|
||||
}
|
||||
}
|
||||
|
||||
fn releases_sorting_options() -> Vec<SortOption<LidarrRelease>> {
|
||||
vec![
|
||||
SortOption {
|
||||
name: "Source",
|
||||
cmp_fn: Some(|a, b| a.protocol.cmp(&b.protocol)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Age",
|
||||
cmp_fn: Some(|a, b| a.age.cmp(&b.age)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Rejected",
|
||||
cmp_fn: Some(|a, b| a.rejected.cmp(&b.rejected)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Title",
|
||||
cmp_fn: Some(|a, b| {
|
||||
a.title
|
||||
.text
|
||||
.to_lowercase()
|
||||
.cmp(&b.title.text.to_lowercase())
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Indexer",
|
||||
cmp_fn: Some(|a, b| a.indexer.to_lowercase().cmp(&b.indexer.to_lowercase())),
|
||||
},
|
||||
SortOption {
|
||||
name: "Size",
|
||||
cmp_fn: Some(|a, b| a.size.cmp(&b.size)),
|
||||
},
|
||||
SortOption {
|
||||
name: "Peers",
|
||||
cmp_fn: Some(|a, b| {
|
||||
let default_number = Number::from(i64::MAX);
|
||||
let seeder_a = a
|
||||
.seeders
|
||||
.as_ref()
|
||||
.unwrap_or(&default_number)
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
let seeder_b = b
|
||||
.seeders
|
||||
.as_ref()
|
||||
.unwrap_or(&default_number)
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
|
||||
seeder_a.cmp(&seeder_b)
|
||||
}),
|
||||
},
|
||||
SortOption {
|
||||
name: "Quality",
|
||||
cmp_fn: Some(|a, b| a.quality.cmp(&b.quality)),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ mod tests {
|
||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||
use crate::handlers::KeyEventHandler;
|
||||
use crate::handlers::lidarr_handlers::library::artist_details_handler::ArtistDetailsHandler;
|
||||
use crate::models::lidarr_models::LidarrHistoryItem;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
|
||||
mod test_handle_delete {
|
||||
use super::*;
|
||||
@@ -86,7 +86,6 @@ mod tests {
|
||||
use crate::handlers::lidarr_handlers::library::artist_details_handler::ArtistDetailsHandler;
|
||||
use crate::models::lidarr_models::LidarrHistoryItem;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::ActiveLidarrBlock;
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::network::lidarr_network::LidarrEvent;
|
||||
use crate::network::lidarr_network::lidarr_network_test_utils::test_utils::artist;
|
||||
use crate::{assert_navigation_popped, assert_navigation_pushed};
|
||||
@@ -145,9 +144,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_artist_history_submit() {
|
||||
let mut app = App::test_default();
|
||||
let mut artist_history = StatefulTable::default();
|
||||
artist_history.set_items(vec![LidarrHistoryItem::default()]);
|
||||
app.data.lidarr_data.artist_history = Some(artist_history);
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.set_items(vec![LidarrHistoryItem::default()]);
|
||||
|
||||
ArtistDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None)
|
||||
.handle();
|
||||
@@ -159,7 +160,6 @@ mod tests {
|
||||
fn test_artist_history_submit_no_op_when_artist_history_is_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistory.into());
|
||||
app.data.lidarr_data.artist_history = Some(StatefulTable::default());
|
||||
|
||||
ArtistDetailsHandler::new(SUBMIT_KEY, &mut app, ActiveLidarrBlock::ArtistHistory, None)
|
||||
.handle();
|
||||
@@ -218,13 +218,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_artist_history_esc_resets_filter_if_one_is_set_instead_of_closing_the_window() {
|
||||
let mut app = App::test_default();
|
||||
let artist_history = StatefulTable {
|
||||
app.data.lidarr_data.artist_history = StatefulTable {
|
||||
filter: Some("Test".into()),
|
||||
filtered_items: Some(vec![LidarrHistoryItem::default()]),
|
||||
filtered_state: Some(TableState::default()),
|
||||
..StatefulTable::default()
|
||||
};
|
||||
app.data.lidarr_data.artist_history = Some(artist_history);
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
app.push_navigation_stack(ActiveLidarrBlock::ArtistHistory.into());
|
||||
|
||||
@@ -234,25 +233,9 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
ActiveLidarrBlock::ArtistHistory.into()
|
||||
);
|
||||
assert_none!(app.data.lidarr_data.artist_history.as_ref().unwrap().filter);
|
||||
assert_none!(
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.filtered_items
|
||||
);
|
||||
assert_none!(
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.filtered_state
|
||||
);
|
||||
assert_none!(app.data.lidarr_data.artist_history.filter);
|
||||
assert_none!(app.data.lidarr_data.artist_history.filtered_items);
|
||||
assert_none!(app.data.lidarr_data.artist_history.filtered_state);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -691,10 +674,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_artist_details_handler_ready_when_not_loading_and_artist_history_is_some() {
|
||||
fn test_artist_details_handler_ready_when_not_loading_and_artist_history_is_non_empty() {
|
||||
let mut app = App::test_default();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::Artists.into());
|
||||
app.data.lidarr_data.artist_history = Some(StatefulTable::default());
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.artist_history
|
||||
.set_items(vec![LidarrHistoryItem::default()]);
|
||||
|
||||
let handler = ArtistDetailsHandler::new(
|
||||
DEFAULT_KEYBINDINGS.esc.key,
|
||||
|
||||
Reference in New Issue
Block a user