feat(ui): Delete a series
This commit is contained in:
@@ -11,7 +11,9 @@ mod tests {
|
|||||||
use crate::event::Key;
|
use crate::event::Key;
|
||||||
use crate::handlers::sonarr_handlers::library::{series_sorting_options, LibraryHandler};
|
use crate::handlers::sonarr_handlers::library::{series_sorting_options, LibraryHandler};
|
||||||
use crate::handlers::KeyEventHandler;
|
use crate::handlers::KeyEventHandler;
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SERIES_BLOCKS};
|
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||||
|
ActiveSonarrBlock, DELETE_SERIES_BLOCKS, LIBRARY_BLOCKS,
|
||||||
|
};
|
||||||
use crate::models::sonarr_models::{Series, SeriesStatus, SeriesType};
|
use crate::models::sonarr_models::{Series, SeriesStatus, SeriesType};
|
||||||
use crate::models::stateful_table::SortOption;
|
use crate::models::stateful_table::SortOption;
|
||||||
use crate::models::HorizontallyScrollableText;
|
use crate::models::HorizontallyScrollableText;
|
||||||
@@ -1702,7 +1704,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_library_handler_accepts() {
|
fn test_library_handler_accepts() {
|
||||||
let mut library_handler_blocks = Vec::new();
|
let mut library_handler_blocks = Vec::new();
|
||||||
library_handler_blocks.extend(SERIES_BLOCKS);
|
library_handler_blocks.extend(LIBRARY_BLOCKS);
|
||||||
|
library_handler_blocks.extend(DELETE_SERIES_BLOCKS);
|
||||||
|
|
||||||
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
|
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
|
||||||
if library_handler_blocks.contains(&active_sonarr_block) {
|
if library_handler_blocks.contains(&active_sonarr_block) {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
models::{
|
models::{
|
||||||
servarr_data::sonarr::sonarr_data::{
|
servarr_data::sonarr::sonarr_data::{
|
||||||
ActiveSonarrBlock, DELETE_SERIES_SELECTION_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS,
|
ActiveSonarrBlock, DELETE_SERIES_SELECTION_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS,
|
||||||
SERIES_BLOCKS,
|
LIBRARY_BLOCKS,
|
||||||
},
|
},
|
||||||
sonarr_models::Series,
|
sonarr_models::Series,
|
||||||
stateful_table::SortOption,
|
stateful_table::SortOption,
|
||||||
@@ -45,7 +45,7 @@ impl<'a, 'b> KeyEventHandler<'a, 'b, ActiveSonarrBlock> for LibraryHandler<'a, '
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
fn accepts(active_block: ActiveSonarrBlock) -> bool {
|
||||||
SERIES_BLOCKS.contains(&active_block)
|
DeleteSeriesHandler::accepts(active_block) || LIBRARY_BLOCKS.contains(&active_block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with(
|
fn with(
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ pub enum ActiveSonarrBlock {
|
|||||||
UpdateDownloadsPrompt,
|
UpdateDownloadsPrompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static SERIES_BLOCKS: [ActiveSonarrBlock; 7] = [
|
pub static LIBRARY_BLOCKS: [ActiveSonarrBlock; 7] = [
|
||||||
ActiveSonarrBlock::Series,
|
ActiveSonarrBlock::Series,
|
||||||
ActiveSonarrBlock::SeriesSortPrompt,
|
ActiveSonarrBlock::SeriesSortPrompt,
|
||||||
ActiveSonarrBlock::SearchSeries,
|
ActiveSonarrBlock::SearchSeries,
|
||||||
|
|||||||
@@ -203,19 +203,19 @@ mod tests {
|
|||||||
mod active_sonarr_block_tests {
|
mod active_sonarr_block_tests {
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::{
|
use crate::models::servarr_data::sonarr::sonarr_data::{
|
||||||
ActiveSonarrBlock, DELETE_SERIES_BLOCKS, DELETE_SERIES_SELECTION_BLOCKS, DOWNLOADS_BLOCKS,
|
ActiveSonarrBlock, DELETE_SERIES_BLOCKS, DELETE_SERIES_SELECTION_BLOCKS, DOWNLOADS_BLOCKS,
|
||||||
EDIT_SERIES_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS, SERIES_BLOCKS,
|
EDIT_SERIES_BLOCKS, EDIT_SERIES_SELECTION_BLOCKS, LIBRARY_BLOCKS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_series_blocks_contents() {
|
fn test_library_blocks_contents() {
|
||||||
assert_eq!(SERIES_BLOCKS.len(), 7);
|
assert_eq!(LIBRARY_BLOCKS.len(), 7);
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::Series));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::Series));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::SeriesSortPrompt));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::SeriesSortPrompt));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::SearchSeries));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::SearchSeries));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::SearchSeriesError));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::SearchSeriesError));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::FilterSeries));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::FilterSeries));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::FilterSeriesError));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::FilterSeriesError));
|
||||||
assert!(SERIES_BLOCKS.contains(&ActiveSonarrBlock::UpdateAllSeriesPrompt));
|
assert!(LIBRARY_BLOCKS.contains(&ActiveSonarrBlock::UpdateAllSeriesPrompt));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
use ratatui::layout::Rect;
|
||||||
|
use ratatui::Frame;
|
||||||
|
|
||||||
|
use crate::app::App;
|
||||||
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DELETE_SERIES_BLOCKS};
|
||||||
|
use crate::models::Route;
|
||||||
|
use crate::ui::sonarr_ui::library::draw_library;
|
||||||
|
use crate::ui::widgets::checkbox::Checkbox;
|
||||||
|
use crate::ui::widgets::confirmation_prompt::ConfirmationPrompt;
|
||||||
|
use crate::ui::widgets::popup::{Popup, Size};
|
||||||
|
use crate::ui::DrawUi;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "delete_series_ui_tests.rs"]
|
||||||
|
mod delete_series_ui_tests;
|
||||||
|
|
||||||
|
pub(super) struct DeleteSeriesUi;
|
||||||
|
|
||||||
|
impl DrawUi for DeleteSeriesUi {
|
||||||
|
fn accepts(route: Route) -> bool {
|
||||||
|
if let Route::Sonarr(active_sonarr_block, _) = route {
|
||||||
|
return DELETE_SERIES_BLOCKS.contains(&active_sonarr_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||||
|
if matches!(
|
||||||
|
app.get_current_route(),
|
||||||
|
Route::Sonarr(ActiveSonarrBlock::DeleteSeriesPrompt, _)
|
||||||
|
) {
|
||||||
|
let selected_block = app.data.sonarr_data.selected_block.get_active_block();
|
||||||
|
let prompt = format!(
|
||||||
|
"Do you really want to delete: \n{}?",
|
||||||
|
app.data.sonarr_data.series.current_selection().title.text
|
||||||
|
);
|
||||||
|
let checkboxes = vec![
|
||||||
|
Checkbox::new("Delete Series File")
|
||||||
|
.checked(app.data.sonarr_data.delete_series_files)
|
||||||
|
.highlighted(selected_block == ActiveSonarrBlock::DeleteSeriesToggleDeleteFile),
|
||||||
|
Checkbox::new("Add List Exclusion")
|
||||||
|
.checked(app.data.sonarr_data.add_list_exclusion)
|
||||||
|
.highlighted(selected_block == ActiveSonarrBlock::DeleteSeriesToggleAddListExclusion),
|
||||||
|
];
|
||||||
|
let confirmation_prompt = ConfirmationPrompt::new()
|
||||||
|
.title("Delete Series")
|
||||||
|
.prompt(&prompt)
|
||||||
|
.checkboxes(checkboxes)
|
||||||
|
.yes_no_highlighted(selected_block == ActiveSonarrBlock::DeleteSeriesConfirmPrompt)
|
||||||
|
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||||
|
|
||||||
|
draw_library(f, app, area);
|
||||||
|
f.render_widget(Popup::new(confirmation_prompt).size(Size::Prompt), f.area());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DELETE_SERIES_BLOCKS};
|
||||||
|
use crate::ui::sonarr_ui::library::delete_series_ui::DeleteSeriesUi;
|
||||||
|
use crate::ui::DrawUi;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_series_ui_accepts() {
|
||||||
|
ActiveSonarrBlock::iter().for_each(|active_sonarr_block| {
|
||||||
|
if DELETE_SERIES_BLOCKS.contains(&active_sonarr_block) {
|
||||||
|
assert!(DeleteSeriesUi::accepts(active_sonarr_block.into()));
|
||||||
|
} else {
|
||||||
|
assert!(!DeleteSeriesUi::accepts(active_sonarr_block.into()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::models::servarr_data::sonarr::sonarr_data::ActiveSonarrBlock;
|
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, DELETE_SERIES_BLOCKS};
|
||||||
use crate::models::{
|
use crate::models::{
|
||||||
servarr_data::sonarr::sonarr_data::SERIES_BLOCKS, sonarr_models::SeriesStatus,
|
servarr_data::sonarr::sonarr_data::LIBRARY_BLOCKS, sonarr_models::SeriesStatus,
|
||||||
};
|
};
|
||||||
use crate::ui::sonarr_ui::library::LibraryUi;
|
use crate::ui::sonarr_ui::library::LibraryUi;
|
||||||
use crate::ui::styles::ManagarrStyle;
|
use crate::ui::styles::ManagarrStyle;
|
||||||
@@ -20,7 +20,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_library_ui_accepts() {
|
fn test_library_ui_accepts() {
|
||||||
let mut library_ui_blocks = Vec::new();
|
let mut library_ui_blocks = Vec::new();
|
||||||
library_ui_blocks.extend(SERIES_BLOCKS);
|
library_ui_blocks.extend(LIBRARY_BLOCKS);
|
||||||
|
library_ui_blocks.extend(DELETE_SERIES_BLOCKS);
|
||||||
|
|
||||||
ActiveSonarrBlock::iter().for_each(|active_radarr_block| {
|
ActiveSonarrBlock::iter().for_each(|active_radarr_block| {
|
||||||
if library_ui_blocks.contains(&active_radarr_block) {
|
if library_ui_blocks.contains(&active_radarr_block) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use delete_series_ui::DeleteSeriesUi;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Rect},
|
layout::{Constraint, Rect},
|
||||||
widgets::{Cell, Row},
|
widgets::{Cell, Row},
|
||||||
@@ -12,7 +13,7 @@ use crate::ui::widgets::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::App,
|
||||||
models::{
|
models::{
|
||||||
servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, SERIES_BLOCKS},
|
servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, LIBRARY_BLOCKS},
|
||||||
sonarr_models::{Series, SeriesStatus},
|
sonarr_models::{Series, SeriesStatus},
|
||||||
EnumDisplayStyle, Route,
|
EnumDisplayStyle, Route,
|
||||||
},
|
},
|
||||||
@@ -25,6 +26,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod delete_series_ui;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[path = "library_ui_tests.rs"]
|
#[path = "library_ui_tests.rs"]
|
||||||
mod library_ui_tests;
|
mod library_ui_tests;
|
||||||
@@ -34,7 +37,7 @@ pub(super) struct LibraryUi;
|
|||||||
impl DrawUi for LibraryUi {
|
impl DrawUi for LibraryUi {
|
||||||
fn accepts(route: Route) -> bool {
|
fn accepts(route: Route) -> bool {
|
||||||
if let Route::Sonarr(active_sonarr_block, _) = route {
|
if let Route::Sonarr(active_sonarr_block, _) = route {
|
||||||
return SERIES_BLOCKS.contains(&active_sonarr_block);
|
return DeleteSeriesUi::accepts(route) || LIBRARY_BLOCKS.contains(&active_sonarr_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
@@ -44,26 +47,26 @@ impl DrawUi for LibraryUi {
|
|||||||
let route = app.get_current_route();
|
let route = app.get_current_route();
|
||||||
let mut series_ui_matchers = |active_sonarr_block: ActiveSonarrBlock| match active_sonarr_block
|
let mut series_ui_matchers = |active_sonarr_block: ActiveSonarrBlock| match active_sonarr_block
|
||||||
{
|
{
|
||||||
ActiveSonarrBlock::Series | ActiveSonarrBlock::SeriesSortPrompt => draw_series(f, app, area),
|
ActiveSonarrBlock::Series | ActiveSonarrBlock::SeriesSortPrompt => draw_library(f, app, area),
|
||||||
ActiveSonarrBlock::SearchSeries => draw_popup_over(
|
ActiveSonarrBlock::SearchSeries => draw_popup_over(
|
||||||
f,
|
f,
|
||||||
app,
|
app,
|
||||||
area,
|
area,
|
||||||
draw_series,
|
draw_library,
|
||||||
draw_series_search_box,
|
draw_library_search_box,
|
||||||
Size::InputBox,
|
Size::InputBox,
|
||||||
),
|
),
|
||||||
ActiveSonarrBlock::SearchSeriesError => {
|
ActiveSonarrBlock::SearchSeriesError => {
|
||||||
let popup = Popup::new(Message::new("Series not found!")).size(Size::Message);
|
let popup = Popup::new(Message::new("Series not found!")).size(Size::Message);
|
||||||
|
|
||||||
draw_series(f, app, area);
|
draw_library(f, app, area);
|
||||||
f.render_widget(popup, f.area());
|
f.render_widget(popup, f.area());
|
||||||
}
|
}
|
||||||
ActiveSonarrBlock::FilterSeries => draw_popup_over(
|
ActiveSonarrBlock::FilterSeries => draw_popup_over(
|
||||||
f,
|
f,
|
||||||
app,
|
app,
|
||||||
area,
|
area,
|
||||||
draw_series,
|
draw_library,
|
||||||
draw_filter_series_box,
|
draw_filter_series_box,
|
||||||
Size::InputBox,
|
Size::InputBox,
|
||||||
),
|
),
|
||||||
@@ -71,7 +74,7 @@ impl DrawUi for LibraryUi {
|
|||||||
let popup = Popup::new(Message::new("No series found matching the given filter!"))
|
let popup = Popup::new(Message::new("No series found matching the given filter!"))
|
||||||
.size(Size::Message);
|
.size(Size::Message);
|
||||||
|
|
||||||
draw_series(f, app, area);
|
draw_library(f, app, area);
|
||||||
f.render_widget(popup, f.area());
|
f.render_widget(popup, f.area());
|
||||||
}
|
}
|
||||||
ActiveSonarrBlock::UpdateAllSeriesPrompt => {
|
ActiveSonarrBlock::UpdateAllSeriesPrompt => {
|
||||||
@@ -80,14 +83,15 @@ impl DrawUi for LibraryUi {
|
|||||||
.prompt("Do you want to update info and scan your disks for all of your series?")
|
.prompt("Do you want to update info and scan your disks for all of your series?")
|
||||||
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||||
|
|
||||||
draw_series(f, app, area);
|
draw_library(f, app, area);
|
||||||
f.render_widget(Popup::new(confirmation_prompt).size(Size::Prompt), f.area());
|
f.render_widget(Popup::new(confirmation_prompt).size(Size::Prompt), f.area());
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
match route {
|
match route {
|
||||||
Route::Sonarr(active_sonarr_block, _) if SERIES_BLOCKS.contains(&active_sonarr_block) => {
|
_ if DeleteSeriesUi::accepts(route) => DeleteSeriesUi::draw(f, app, area),
|
||||||
|
Route::Sonarr(active_sonarr_block, _) if LIBRARY_BLOCKS.contains(&active_sonarr_block) => {
|
||||||
series_ui_matchers(active_sonarr_block)
|
series_ui_matchers(active_sonarr_block)
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@@ -95,7 +99,7 @@ impl DrawUi for LibraryUi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw_series(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
pub(super) fn draw_library(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||||
if let Route::Sonarr(active_sonarr_block, _) = app.get_current_route() {
|
if let Route::Sonarr(active_sonarr_block, _) = app.get_current_route() {
|
||||||
let current_selection = if !app.data.sonarr_data.series.items.is_empty() {
|
let current_selection = if !app.data.sonarr_data.series.items.is_empty() {
|
||||||
app.data.sonarr_data.series.current_selection().clone()
|
app.data.sonarr_data.series.current_selection().clone()
|
||||||
@@ -220,7 +224,7 @@ fn decorate_series_row_with_style<'a>(series: &Series, row: Row<'a>) -> Row<'a>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_series_search_box(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
fn draw_library_search_box(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||||
draw_input_box_popup(
|
draw_input_box_popup(
|
||||||
f,
|
f,
|
||||||
area,
|
area,
|
||||||
|
|||||||
Reference in New Issue
Block a user