Refactored table filtering and searching so that they are now relative to the table being filtered/searched on. Also created two new widgets for error messages and popups to make life easier moving forward. Going to refactor table sorting into StatefulTable's as well so all tables can be searched, filtered, and sorted moving forwards.
This commit is contained in:
@@ -19,7 +19,6 @@ mod tests {
|
||||
mod test_handle_scroll_up_and_down {
|
||||
use rstest::rstest;
|
||||
|
||||
use crate::models::StatefulTable;
|
||||
use crate::{simple_stateful_iterable_vec, test_iterable_scroll};
|
||||
|
||||
use super::*;
|
||||
@@ -34,55 +33,11 @@ mod tests {
|
||||
title,
|
||||
to_string
|
||||
);
|
||||
|
||||
#[rstest]
|
||||
fn test_filtered_collections_scroll(
|
||||
#[values(DEFAULT_KEYBINDINGS.up.key, DEFAULT_KEYBINDINGS.down.key)] key: Key,
|
||||
) {
|
||||
let mut app = App::default();
|
||||
let mut filtered_collections = StatefulTable::default();
|
||||
filtered_collections.set_items(simple_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.filtered_collections = Some(filtered_collections);
|
||||
|
||||
CollectionsHandler::with(&key, &mut app, &ActiveRadarrBlock::Collections, &None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 2"
|
||||
);
|
||||
|
||||
CollectionsHandler::with(&key, &mut app, &ActiveRadarrBlock::Collections, &None).handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod test_handle_home_end {
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::models::StatefulTable;
|
||||
use crate::{extended_stateful_iterable_vec, test_iterable_home_and_end};
|
||||
|
||||
use super::*;
|
||||
@@ -98,63 +53,10 @@ mod tests {
|
||||
to_string
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_filtered_collections_home_end() {
|
||||
let mut app = App::default();
|
||||
let mut filtered_collections = StatefulTable::default();
|
||||
filtered_collections.set_items(extended_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.filtered_collections = Some(filtered_collections);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.end.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 3"
|
||||
);
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
&mut app,
|
||||
&ActiveRadarrBlock::Collections,
|
||||
&None,
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.current_selection()
|
||||
.title
|
||||
.to_string(),
|
||||
"Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collection_search_box_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.search = Some("Test".into());
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
@@ -168,6 +70,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -188,6 +91,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -200,7 +104,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_collection_filter_box_home_end_keys() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.filter = Some("Test".into());
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.home.key,
|
||||
@@ -214,6 +118,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -234,6 +139,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -326,7 +232,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_collection_search_box_left_right_keys() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.search = Some("Test".into());
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.left.key,
|
||||
@@ -340,6 +246,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -360,6 +267,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -372,7 +280,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_collection_filter_box_left_right_keys() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.filter = Some("Test".into());
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.left.key,
|
||||
@@ -386,6 +294,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -406,6 +315,7 @@ mod tests {
|
||||
*app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
@@ -417,7 +327,6 @@ mod tests {
|
||||
}
|
||||
|
||||
mod test_handle_submit {
|
||||
use crate::models::StatefulTable;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
@@ -457,7 +366,7 @@ mod tests {
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.search = Some("Test 2".into());
|
||||
app.data.radarr_data.collections.search = Some("Test 2".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -496,7 +405,7 @@ mod tests {
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.search = Some("Test 5".into());
|
||||
app.data.radarr_data.collections.search = Some("Test 5".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -527,13 +436,15 @@ mod tests {
|
||||
let mut app = App::default();
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::SearchCollection.into());
|
||||
let mut filtered_collections = StatefulTable::default();
|
||||
filtered_collections.set_items(extended_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.filtered_collections = Some(filtered_collections);
|
||||
app.data.radarr_data.search = Some("Test 2".into());
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.set_items(extended_stateful_iterable_vec!(
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.collections.search = Some("Test 2".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -547,9 +458,7 @@ mod tests {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.text,
|
||||
@@ -574,7 +483,7 @@ mod tests {
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.filter = Some("Test".into());
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -584,15 +493,16 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert!(app.data.radarr_data.filtered_collections.is_some());
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.collections.filtered_items.is_some());
|
||||
assert_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.collections
|
||||
.filtered_items
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.items
|
||||
.len(),
|
||||
3
|
||||
);
|
||||
@@ -600,9 +510,7 @@ mod tests {
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.filtered_collections
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.collections
|
||||
.current_selection()
|
||||
.title
|
||||
.text,
|
||||
@@ -627,7 +535,7 @@ mod tests {
|
||||
Collection,
|
||||
HorizontallyScrollableText
|
||||
));
|
||||
app.data.radarr_data.filter = Some("Test 5".into());
|
||||
app.data.radarr_data.collections.filter = Some("Test 5".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&SUBMIT_KEY,
|
||||
@@ -637,7 +545,8 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert!(app.data.radarr_data.filtered_collections.is_none());
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.collections.filtered_items.is_none());
|
||||
assert_eq!(
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::FilterCollectionsError.into()
|
||||
@@ -695,9 +604,10 @@ mod tests {
|
||||
|
||||
mod test_handle_esc {
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::widgets::TableState;
|
||||
|
||||
use crate::models::servarr_data::radarr::radarr_data::radarr_test_utils::utils::create_test_radarr_data;
|
||||
use crate::{assert_filter_reset, assert_search_reset};
|
||||
use crate::models::StatefulTable;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -716,6 +626,7 @@ mod tests {
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(&ESC_KEY, &mut app, &active_radarr_block, &None).handle();
|
||||
|
||||
@@ -724,7 +635,7 @@ mod tests {
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert_search_reset!(app.data.radarr_data);
|
||||
assert_eq!(app.data.radarr_data.collections.search, None);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -740,6 +651,12 @@ mod tests {
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(active_radarr_block.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.collections = StatefulTable {
|
||||
filter: Some("Test".into()),
|
||||
filtered_items: Some(Vec::new()),
|
||||
filtered_state: Some(TableState::default()),
|
||||
..StatefulTable::default()
|
||||
};
|
||||
|
||||
CollectionsHandler::with(&ESC_KEY, &mut app, &active_radarr_block, &None).handle();
|
||||
|
||||
@@ -748,7 +665,9 @@ mod tests {
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(!app.should_ignore_quit_key);
|
||||
assert_filter_reset!(app.data.radarr_data);
|
||||
assert_eq!(app.data.radarr_data.collections.filter, None);
|
||||
assert_eq!(app.data.radarr_data.collections.filtered_items, None);
|
||||
assert_eq!(app.data.radarr_data.collections.filtered_state, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -780,6 +699,13 @@ mod tests {
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.collections = StatefulTable {
|
||||
search: Some("Test".into()),
|
||||
filter: Some("Test".into()),
|
||||
filtered_items: Some(Vec::new()),
|
||||
filtered_state: Some(TableState::default()),
|
||||
..StatefulTable::default()
|
||||
};
|
||||
|
||||
CollectionsHandler::with(&ESC_KEY, &mut app, &ActiveRadarrBlock::Collections, &None).handle();
|
||||
|
||||
@@ -788,8 +714,10 @@ mod tests {
|
||||
&ActiveRadarrBlock::Collections.into()
|
||||
);
|
||||
assert!(app.error.text.is_empty());
|
||||
assert_search_reset!(app.data.radarr_data);
|
||||
assert_filter_reset!(app.data.radarr_data);
|
||||
assert_eq!(app.data.radarr_data.collections.search, None);
|
||||
assert_eq!(app.data.radarr_data.collections.filter, None);
|
||||
assert_eq!(app.data.radarr_data.collections.filtered_items, None);
|
||||
assert_eq!(app.data.radarr_data.collections.filtered_state, None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -805,6 +733,7 @@ mod tests {
|
||||
RadarrData, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
|
||||
use crate::models::StatefulTable;
|
||||
use crate::{assert_refresh_key, test_edit_collection_key};
|
||||
|
||||
use super::*;
|
||||
@@ -825,9 +754,11 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::SearchCollection.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.is_searching);
|
||||
assert!(app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.search.is_some());
|
||||
assert_eq!(
|
||||
app.data.radarr_data.collections.search,
|
||||
Some(HorizontallyScrollableText::default())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -846,9 +777,8 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::FilterCollections.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.is_filtering);
|
||||
assert!(app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.filter.is_some());
|
||||
assert!(app.data.radarr_data.collections.filter.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -857,6 +787,8 @@ mod tests {
|
||||
app.should_ignore_quit_key = true;
|
||||
app.push_navigation_stack(ActiveRadarrBlock::Collections.into());
|
||||
app.data.radarr_data = create_test_radarr_data();
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.filter.key,
|
||||
@@ -870,10 +802,13 @@ mod tests {
|
||||
app.get_current_route(),
|
||||
&ActiveRadarrBlock::FilterCollections.into()
|
||||
);
|
||||
assert!(app.data.radarr_data.is_filtering);
|
||||
assert!(app.should_ignore_quit_key);
|
||||
assert!(app.data.radarr_data.filter.is_some());
|
||||
assert!(app.data.radarr_data.filtered_collections.is_none());
|
||||
assert_eq!(
|
||||
app.data.radarr_data.collections.filter,
|
||||
Some(HorizontallyScrollableText::default())
|
||||
);
|
||||
assert!(app.data.radarr_data.collections.filtered_items.is_none());
|
||||
assert!(app.data.radarr_data.collections.filtered_state.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -911,7 +846,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_search_collections_box_backspace_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.search = Some("Test".into());
|
||||
app.data.radarr_data.collections.search = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.backspace.key,
|
||||
@@ -921,13 +856,24 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.search.as_ref().unwrap().text, "Tes");
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text,
|
||||
"Tes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_collections_box_backspace_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.filter = Some("Test".into());
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app.data.radarr_data.collections.filter = Some("Test".into());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&DEFAULT_KEYBINDINGS.backspace.key,
|
||||
@@ -937,13 +883,23 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.filter.as_ref().unwrap().text, "Tes");
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text,
|
||||
"Tes"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search_collections_box_char_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.search = Some(HorizontallyScrollableText::default());
|
||||
app.data.radarr_data.collections.search = Some(HorizontallyScrollableText::default());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&Key::Char('h'),
|
||||
@@ -953,13 +909,24 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.search.as_ref().unwrap().text, "h");
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text,
|
||||
"h"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_collections_box_char_key() {
|
||||
let mut app = App::default();
|
||||
app.data.radarr_data.filter = Some(HorizontallyScrollableText::default());
|
||||
app.data.radarr_data.collections = StatefulTable::default();
|
||||
app.data.radarr_data.collections.filter = Some(HorizontallyScrollableText::default());
|
||||
|
||||
CollectionsHandler::with(
|
||||
&Key::Char('h'),
|
||||
@@ -969,7 +936,17 @@ mod tests {
|
||||
)
|
||||
.handle();
|
||||
|
||||
assert_str_eq!(app.data.radarr_data.filter.as_ref().unwrap().text, "h");
|
||||
assert_str_eq!(
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.text,
|
||||
"h"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,9 @@ use crate::handlers::{handle_clear_errors, handle_prompt_toggle, KeyEventHandler
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
ActiveRadarrBlock, COLLECTIONS_BLOCKS, EDIT_COLLECTION_SELECTION_BLOCKS,
|
||||
};
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Scrollable, StatefulTable};
|
||||
use crate::models::{BlockSelectionState, HorizontallyScrollableText, Scrollable};
|
||||
use crate::network::radarr_network::RadarrEvent;
|
||||
use crate::utils::strip_non_search_characters;
|
||||
use crate::{filter_table, handle_text_box_keys, handle_text_box_left_right_keys, search_table};
|
||||
use crate::{handle_text_box_keys, handle_text_box_left_right_keys};
|
||||
|
||||
mod collection_details_handler;
|
||||
mod edit_collection_handler;
|
||||
@@ -68,38 +67,24 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
|
||||
fn handle_scroll_up(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::Collections {
|
||||
if let Some(filtered_collections) = self.app.data.radarr_data.filtered_collections.as_mut() {
|
||||
filtered_collections.scroll_up();
|
||||
} else {
|
||||
self.app.data.radarr_data.collections.scroll_up()
|
||||
}
|
||||
self.app.data.radarr_data.collections.scroll_up()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_scroll_down(&mut self) {
|
||||
if self.active_radarr_block == &ActiveRadarrBlock::Collections {
|
||||
if let Some(filtered_collections) = self.app.data.radarr_data.filtered_collections.as_mut() {
|
||||
filtered_collections.scroll_down();
|
||||
} else {
|
||||
self.app.data.radarr_data.collections.scroll_down()
|
||||
}
|
||||
self.app.data.radarr_data.collections.scroll_down()
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_home(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::Collections => {
|
||||
if let Some(filtered_collections) = self.app.data.radarr_data.filtered_collections.as_mut()
|
||||
{
|
||||
filtered_collections.scroll_to_top();
|
||||
} else {
|
||||
self.app.data.radarr_data.collections.scroll_to_top()
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::Collections => self.app.data.radarr_data.collections.scroll_to_top(),
|
||||
ActiveRadarrBlock::SearchCollection => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -108,6 +93,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -118,18 +104,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
|
||||
fn handle_end(&mut self) {
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::Collections => {
|
||||
if let Some(filtered_collections) = self.app.data.radarr_data.filtered_collections.as_mut()
|
||||
{
|
||||
filtered_collections.scroll_to_bottom();
|
||||
} else {
|
||||
self.app.data.radarr_data.collections.scroll_to_bottom()
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::Collections => self.app.data.radarr_data.collections.scroll_to_bottom(),
|
||||
ActiveRadarrBlock::SearchCollection => self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -138,6 +118,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -156,14 +137,28 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
handle_text_box_left_right_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self.app.data.radarr_data.search.as_mut().unwrap()
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::FilterCollections => {
|
||||
handle_text_box_left_right_keys!(
|
||||
self,
|
||||
self.key,
|
||||
self.app.data.radarr_data.filter.as_mut().unwrap()
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
_ => (),
|
||||
@@ -176,28 +171,42 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::CollectionDetails.into()),
|
||||
ActiveRadarrBlock::SearchCollection => {
|
||||
if self.app.data.radarr_data.filtered_collections.is_some() {
|
||||
search_table!(
|
||||
self.app,
|
||||
filtered_collections,
|
||||
ActiveRadarrBlock::SearchCollectionError,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
search_table!(
|
||||
self.app,
|
||||
collections,
|
||||
ActiveRadarrBlock::SearchCollectionError
|
||||
);
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
|
||||
if self.app.data.radarr_data.collections.search.is_some() {
|
||||
let has_match = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.apply_search(|collection| &collection.title.text);
|
||||
|
||||
if !has_match {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::SearchCollectionError.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::FilterCollections => {
|
||||
filter_table!(
|
||||
self.app,
|
||||
collections,
|
||||
filtered_collections,
|
||||
ActiveRadarrBlock::FilterCollectionsError
|
||||
);
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
|
||||
if self.app.data.radarr_data.collections.filter.is_some() {
|
||||
let has_matches = self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.apply_filter(|collection| &collection.title.text);
|
||||
|
||||
if !has_matches {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::FilterCollectionsError.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveRadarrBlock::UpdateAllCollectionsPrompt => {
|
||||
if self.app.data.radarr_data.prompt_confirm {
|
||||
@@ -214,12 +223,12 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
match self.active_radarr_block {
|
||||
ActiveRadarrBlock::FilterCollections | ActiveRadarrBlock::FilterCollectionsError => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.radarr_data.reset_filter();
|
||||
self.app.data.radarr_data.collections.reset_filter();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
ActiveRadarrBlock::SearchCollection | ActiveRadarrBlock::SearchCollectionError => {
|
||||
self.app.pop_navigation_stack();
|
||||
self.app.data.radarr_data.reset_search();
|
||||
self.app.data.radarr_data.collections.reset_search();
|
||||
self.app.should_ignore_quit_key = false;
|
||||
}
|
||||
ActiveRadarrBlock::UpdateAllCollectionsPrompt => {
|
||||
@@ -227,8 +236,8 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
self.app.data.radarr_data.prompt_confirm = false;
|
||||
}
|
||||
_ => {
|
||||
self.app.data.radarr_data.reset_search();
|
||||
self.app.data.radarr_data.reset_filter();
|
||||
self.app.data.radarr_data.collections.reset_search();
|
||||
self.app.data.radarr_data.collections.reset_filter();
|
||||
handle_clear_errors(self.app);
|
||||
}
|
||||
}
|
||||
@@ -242,17 +251,17 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::SearchCollection.into());
|
||||
self.app.data.radarr_data.search = Some(HorizontallyScrollableText::default());
|
||||
self.app.data.radarr_data.is_searching = true;
|
||||
self.app.data.radarr_data.collections.search =
|
||||
Some(HorizontallyScrollableText::default());
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
_ if *key == DEFAULT_KEYBINDINGS.filter.key => {
|
||||
self
|
||||
.app
|
||||
.push_navigation_stack(ActiveRadarrBlock::FilterCollections.into());
|
||||
self.app.data.radarr_data.reset_filter();
|
||||
self.app.data.radarr_data.filter = Some(HorizontallyScrollableText::default());
|
||||
self.app.data.radarr_data.is_filtering = true;
|
||||
self.app.data.radarr_data.collections.reset_filter();
|
||||
self.app.data.radarr_data.collections.filter =
|
||||
Some(HorizontallyScrollableText::default());
|
||||
self.app.should_ignore_quit_key = true;
|
||||
}
|
||||
_ if *key == DEFAULT_KEYBINDINGS.edit.key => {
|
||||
@@ -282,14 +291,28 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveRadarrBlock> for CollectionsHandler<'
|
||||
handle_text_box_keys!(
|
||||
self,
|
||||
key,
|
||||
self.app.data.radarr_data.search.as_mut().unwrap()
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.search
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
ActiveRadarrBlock::FilterCollections => {
|
||||
handle_text_box_keys!(
|
||||
self,
|
||||
key,
|
||||
self.app.data.radarr_data.filter.as_mut().unwrap()
|
||||
self
|
||||
.app
|
||||
.data
|
||||
.radarr_data
|
||||
.collections
|
||||
.filter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
_ => (),
|
||||
|
||||
Reference in New Issue
Block a user