Added 'Test All Indexers' table and functionality to the Indexers tab, and upgraded to Ratatui 0.24.0 and cleaned up code for newer Ratatui version
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
use ratatui::layout::{Constraint, Rect};
|
||||
use ratatui::Frame;
|
||||
use std::iter;
|
||||
use tui::backend::Backend;
|
||||
use tui::layout::{Constraint, Rect};
|
||||
use tui::Frame;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{
|
||||
@@ -32,7 +31,7 @@ impl DrawUi for IndexerSettingsUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
draw_popup_over(
|
||||
f,
|
||||
app,
|
||||
@@ -45,11 +44,7 @@ impl DrawUi for IndexerSettingsUi {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_edit_indexer_settings_prompt<B: Backend>(
|
||||
f: &mut Frame<'_, B>,
|
||||
app: &mut App<'_>,
|
||||
prompt_area: Rect,
|
||||
) {
|
||||
fn draw_edit_indexer_settings_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
let block = title_block_centered("Configure All Indexer Settings");
|
||||
let yes_no_value = app.data.radarr_data.prompt_confirm;
|
||||
let selected_block = app.data.radarr_data.selected_block.get_active_block();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use tui::backend::Backend;
|
||||
use tui::layout::{Constraint, Rect};
|
||||
use tui::text::Text;
|
||||
use tui::widgets::{Cell, Row};
|
||||
use tui::Frame;
|
||||
use ratatui::layout::{Constraint, Rect};
|
||||
use ratatui::text::Text;
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use ratatui::Frame;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::radarr_models::Indexer;
|
||||
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, INDEXERS_BLOCKS};
|
||||
use crate::models::Route;
|
||||
use crate::ui::radarr_ui::indexers::indexer_settings_ui::IndexerSettingsUi;
|
||||
use crate::ui::radarr_ui::indexers::test_all_indexers_ui::TestAllIndexersUi;
|
||||
use crate::ui::utils::{layout_block_top_border, style_failure, style_primary, style_success};
|
||||
use crate::ui::{draw_prompt_box, draw_prompt_popup_over, draw_table, DrawUi, TableProps};
|
||||
|
||||
@@ -17,6 +17,7 @@ mod indexer_settings_ui;
|
||||
#[cfg(test)]
|
||||
#[path = "indexers_ui_tests.rs"]
|
||||
mod indexers_ui_tests;
|
||||
mod test_all_indexers_ui;
|
||||
|
||||
pub(super) struct IndexersUi;
|
||||
|
||||
@@ -29,7 +30,7 @@ impl DrawUi for IndexersUi {
|
||||
false
|
||||
}
|
||||
|
||||
fn draw<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_rect: Rect) {
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
let route = *app.get_current_route();
|
||||
let mut indexers_matchers = |active_radarr_block| match active_radarr_block {
|
||||
ActiveRadarrBlock::Indexers => draw_indexers(f, app, content_rect),
|
||||
@@ -45,6 +46,7 @@ impl DrawUi for IndexersUi {
|
||||
|
||||
match route {
|
||||
_ if IndexerSettingsUi::accepts(route) => IndexerSettingsUi::draw(f, app, content_rect),
|
||||
_ if TestAllIndexersUi::accepts(route) => TestAllIndexersUi::draw(f, app, content_rect),
|
||||
Route::Radarr(active_radarr_block, _) if INDEXERS_BLOCKS.contains(&active_radarr_block) => {
|
||||
indexers_matchers(active_radarr_block)
|
||||
}
|
||||
@@ -53,7 +55,7 @@ impl DrawUi for IndexersUi {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_indexers<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
fn draw_indexers(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
draw_table(
|
||||
f,
|
||||
area,
|
||||
@@ -125,11 +127,7 @@ fn draw_indexers<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect
|
||||
)
|
||||
}
|
||||
|
||||
fn draw_delete_indexer_prompt<B: Backend>(
|
||||
f: &mut Frame<'_, B>,
|
||||
app: &mut App<'_>,
|
||||
prompt_area: Rect,
|
||||
) {
|
||||
fn draw_delete_indexer_prompt(f: &mut Frame<'_>, app: &mut App<'_>, prompt_area: Rect) {
|
||||
draw_prompt_box(
|
||||
f,
|
||||
prompt_area,
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use crate::app::context_clues::{build_context_clue_string, BARE_POPUP_CONTEXT_CLUES};
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::radarr::modals::IndexerTestResultModalItem;
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::models::Route;
|
||||
use crate::ui::radarr_ui::indexers::draw_indexers;
|
||||
use crate::ui::utils::{
|
||||
borderless_block, get_width_from_percentage, style_failure, style_success, title_block,
|
||||
};
|
||||
use crate::ui::{
|
||||
draw_help_and_get_content_rect, draw_large_popup_over, draw_table, DrawUi, TableProps,
|
||||
};
|
||||
use ratatui::layout::{Constraint, Rect};
|
||||
use ratatui::widgets::{Cell, Row};
|
||||
use ratatui::Frame;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "test_all_indexers_ui_tests.rs"]
|
||||
mod test_all_indexers_ui_tests;
|
||||
|
||||
pub(super) struct TestAllIndexersUi;
|
||||
|
||||
impl DrawUi for TestAllIndexersUi {
|
||||
fn accepts(route: Route) -> bool {
|
||||
if let Route::Radarr(active_radarr_block, _) = route {
|
||||
return active_radarr_block == ActiveRadarrBlock::TestAllIndexers;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, content_rect: Rect) {
|
||||
draw_large_popup_over(
|
||||
f,
|
||||
app,
|
||||
content_rect,
|
||||
draw_indexers,
|
||||
draw_test_all_indexers_test_results,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_test_all_indexers_test_results(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
let current_selection =
|
||||
if let Some(test_all_results) = app.data.radarr_data.indexer_test_all_results.as_ref() {
|
||||
test_all_results.current_selection().clone()
|
||||
} else {
|
||||
IndexerTestResultModalItem::default()
|
||||
};
|
||||
f.render_widget(title_block("Test All Indexers"), area);
|
||||
let help = Some(format!(
|
||||
"<↑↓> scroll | {}",
|
||||
build_context_clue_string(&BARE_POPUP_CONTEXT_CLUES)
|
||||
));
|
||||
let content_area = draw_help_and_get_content_rect(f, area, help);
|
||||
|
||||
draw_table(
|
||||
f,
|
||||
content_area,
|
||||
borderless_block(),
|
||||
TableProps {
|
||||
content: app.data.radarr_data.indexer_test_all_results.as_mut(),
|
||||
wrapped_content: None,
|
||||
table_headers: vec!["Indexer", "Pass/Fail", "Failure Messages"],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(20),
|
||||
Constraint::Percentage(10),
|
||||
Constraint::Percentage(70),
|
||||
],
|
||||
help: None,
|
||||
},
|
||||
|result| {
|
||||
result.validation_failures.scroll_left_or_reset(
|
||||
get_width_from_percentage(area, 86),
|
||||
*result == current_selection,
|
||||
app.tick_count % app.ticks_until_scroll == 0,
|
||||
);
|
||||
let pass_fail = if result.is_valid { "✔" } else { "❌" };
|
||||
let row_style = if result.is_valid {
|
||||
style_success()
|
||||
} else {
|
||||
style_failure()
|
||||
};
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(result.name.to_owned()),
|
||||
Cell::from(pass_fail.to_owned()),
|
||||
Cell::from(result.validation_failures.to_string()),
|
||||
])
|
||||
.style(row_style)
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
|
||||
use crate::ui::radarr_ui::indexers::test_all_indexers_ui::TestAllIndexersUi;
|
||||
use crate::ui::DrawUi;
|
||||
|
||||
#[test]
|
||||
fn test_test_all_indexers_ui_accepts() {
|
||||
ActiveRadarrBlock::iter().for_each(|active_radarr_block| {
|
||||
if active_radarr_block == ActiveRadarrBlock::TestAllIndexers {
|
||||
assert!(TestAllIndexersUi::accepts(active_radarr_block.into()));
|
||||
} else {
|
||||
assert!(!TestAllIndexersUi::accepts(active_radarr_block.into()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user