Added delete download functionality

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent 8f6505bb1e
commit 69981857d8
6 changed files with 78 additions and 14 deletions
+2 -3
View File
@@ -121,7 +121,7 @@ impl Default for RadarrData {
TabRoute { TabRoute {
title: "Downloads".to_owned(), title: "Downloads".to_owned(),
route: ActiveRadarrBlock::Downloads.into(), route: ActiveRadarrBlock::Downloads.into(),
help: String::default(), help: "<del> delete ".to_owned(),
}, },
TabRoute { TabRoute {
title: "Collections".to_owned(), title: "Collections".to_owned(),
@@ -170,12 +170,12 @@ pub enum ActiveRadarrBlock {
AddMovieSelectQualityProfile, AddMovieSelectQualityProfile,
AddMovieSelectMonitor, AddMovieSelectMonitor,
AddMovieConfirmPrompt, AddMovieConfirmPrompt,
Calendar,
Collections, Collections,
CollectionDetails, CollectionDetails,
Cast, Cast,
Crew, Crew,
DeleteMoviePrompt, DeleteMoviePrompt,
DeleteDownloadPrompt,
FileInfo, FileInfo,
FilterCollections, FilterCollections,
FilterMovies, FilterMovies,
@@ -185,7 +185,6 @@ pub enum ActiveRadarrBlock {
Downloads, Downloads,
SearchMovie, SearchMovie,
SearchCollection, SearchCollection,
SortOptions,
ViewMovieOverview, ViewMovieOverview,
} }
+18 -5
View File
@@ -183,10 +183,14 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
} }
fn handle_delete(&mut self) { fn handle_delete(&mut self) {
if *self.active_radarr_block == ActiveRadarrBlock::Movies { match self.active_radarr_block {
self ActiveRadarrBlock::Movies => self
.app .app
.push_navigation_stack(ActiveRadarrBlock::DeleteMoviePrompt.into()); .push_navigation_stack(ActiveRadarrBlock::DeleteMoviePrompt.into()),
ActiveRadarrBlock::Downloads => self
.app
.push_navigation_stack(ActiveRadarrBlock::DeleteDownloadPrompt.into()),
_ => (),
} }
} }
@@ -221,7 +225,9 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
_ => (), _ => (),
} }
} }
ActiveRadarrBlock::DeleteMoviePrompt => handle_prompt_toggle(self.app, self.key), ActiveRadarrBlock::DeleteMoviePrompt | ActiveRadarrBlock::DeleteDownloadPrompt => {
handle_prompt_toggle(self.app, self.key)
}
_ => (), _ => (),
} }
} }
@@ -295,6 +301,13 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
self.app.pop_navigation_stack(); self.app.pop_navigation_stack();
} }
ActiveRadarrBlock::DeleteDownloadPrompt => {
if self.app.data.radarr_data.prompt_confirm {
self.app.data.radarr_data.prompt_confirm_action = Some(RadarrEvent::DeleteDownload);
}
self.app.pop_navigation_stack();
}
_ => (), _ => (),
} }
} }
@@ -309,7 +322,7 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
self.app.data.radarr_data.reset_search(); self.app.data.radarr_data.reset_search();
self.app.should_ignore_quit_key = false; self.app.should_ignore_quit_key = false;
} }
ActiveRadarrBlock::DeleteMoviePrompt => { ActiveRadarrBlock::DeleteMoviePrompt | ActiveRadarrBlock::DeleteDownloadPrompt => {
self.app.pop_navigation_stack(); self.app.pop_navigation_stack();
self.app.data.radarr_data.prompt_confirm = false; self.app.data.radarr_data.prompt_confirm = false;
} }
+1 -1
View File
@@ -148,7 +148,7 @@ pub struct DownloadRecord {
pub title: String, pub title: String,
pub status: String, pub status: String,
#[derivative(Default(value = "Number::from(0)"))] #[derivative(Default(value = "Number::from(0)"))]
pub movie_id: Number, pub id: Number,
#[derivative(Default(value = "Number::from(0)"))] #[derivative(Default(value = "Number::from(0)"))]
pub size: Number, pub size: Number,
#[derivative(Default(value = "Number::from(0)"))] #[derivative(Default(value = "Number::from(0)"))]
+32 -3
View File
@@ -8,8 +8,7 @@ use urlencoding::encode;
use crate::app::RadarrConfig; use crate::app::RadarrConfig;
use crate::models::radarr_models::{ use crate::models::radarr_models::{
AddMovieBody, AddMovieSearchResult, AddOptions, Collection, Credit, CreditType, DiskSpace, AddMovieBody, AddMovieSearchResult, AddOptions, Collection, Credit, CreditType, DiskSpace,
DownloadsResponse, MinimumAvailability, Movie, MovieHistoryItem, QualityProfile, RootFolder, DownloadsResponse, Movie, MovieHistoryItem, QualityProfile, RootFolder, SystemStatus,
SystemStatus,
}; };
use crate::models::ScrollableText; use crate::models::ScrollableText;
use crate::network::utils::get_movie_status; use crate::network::utils::get_movie_status;
@@ -19,6 +18,7 @@ use crate::utils::{convert_runtime, convert_to_gb};
#[derive(Debug, Eq, PartialEq, Clone)] #[derive(Debug, Eq, PartialEq, Clone)]
pub enum RadarrEvent { pub enum RadarrEvent {
AddMovie, AddMovie,
DeleteDownload,
DeleteMovie, DeleteMovie,
GetCollections, GetCollections,
GetDownloads, GetDownloads,
@@ -38,7 +38,7 @@ impl RadarrEvent {
const fn resource(self) -> &'static str { const fn resource(self) -> &'static str {
match self { match self {
RadarrEvent::GetCollections => "/collection", RadarrEvent::GetCollections => "/collection",
RadarrEvent::GetDownloads => "/queue", RadarrEvent::GetDownloads | RadarrEvent::DeleteDownload => "/queue",
RadarrEvent::AddMovie RadarrEvent::AddMovie
| RadarrEvent::GetMovies | RadarrEvent::GetMovies
| RadarrEvent::GetMovieDetails | RadarrEvent::GetMovieDetails
@@ -70,6 +70,7 @@ impl<'a> Network<'a> {
RadarrEvent::GetStatus => self.get_status().await, RadarrEvent::GetStatus => self.get_status().await,
RadarrEvent::GetMovies => self.get_movies().await, RadarrEvent::GetMovies => self.get_movies().await,
RadarrEvent::DeleteMovie => self.delete_movie().await, RadarrEvent::DeleteMovie => self.delete_movie().await,
RadarrEvent::DeleteDownload => self.delete_download().await,
RadarrEvent::GetMovieCredits => self.get_credits().await, RadarrEvent::GetMovieCredits => self.get_credits().await,
RadarrEvent::GetMovieDetails => self.get_movie_details().await, RadarrEvent::GetMovieDetails => self.get_movie_details().await,
RadarrEvent::GetMovieHistory => self.get_movie_history().await, RadarrEvent::GetMovieHistory => self.get_movie_history().await,
@@ -490,6 +491,34 @@ impl<'a> Network<'a> {
.await; .await;
} }
async fn delete_download(&self) {
let movie_id = self
.app
.lock()
.await
.data
.radarr_data
.downloads
.current_selection()
.id
.as_u64()
.unwrap();
info!("Deleting Radarr download for movie with id: {}", movie_id);
let request_props = self
.radarr_request_props_from(
format!("{}/{}", RadarrEvent::DeleteDownload.resource(), movie_id).as_str(),
RequestMethod::Delete,
None::<()>,
)
.await;
self
.handle_request::<(), ()>(request_props, |_, _| ())
.await;
}
async fn add_movie(&self) { async fn add_movie(&self) {
info!("Adding new movie to Radarr"); info!("Adding new movie to Radarr");
let body = { let body = {
+1 -1
View File
@@ -16,7 +16,7 @@ pub fn get_movie_status(
if !has_file { if !has_file {
if let Some(download) = downloads_vec if let Some(download) = downloads_vec
.iter() .iter()
.find(|&download| download.movie_id.as_u64().unwrap() == movie_id.as_u64().unwrap()) .find(|&download| download.id.as_u64().unwrap() == movie_id.as_u64().unwrap())
{ {
if download.status == "downloading" { if download.status == "downloading" {
return "Downloading".to_owned(); return "Downloading".to_owned();
+24 -1
View File
@@ -92,6 +92,15 @@ pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, ar
30, 30,
30, 30,
), ),
ActiveRadarrBlock::DeleteDownloadPrompt => draw_popup_over(
f,
app,
content_rect,
draw_downloads,
draw_delete_download_prompt,
30,
30,
),
_ => (), _ => (),
} }
} }
@@ -179,6 +188,20 @@ fn draw_delete_movie_prompt<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, pro
); );
} }
fn draw_delete_download_prompt<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, prompt_area: Rect) {
draw_prompt_box(
f,
prompt_area,
" Confirm Cancel Download? ",
format!(
"Do you really want to delete this download: {}?",
app.data.radarr_data.downloads.current_selection().title
)
.as_str(),
&app.data.radarr_data.prompt_confirm,
);
}
fn draw_search_box<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) { fn draw_search_box<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks = vertical_chunks_with_margin(vec![Constraint::Length(3)], area, 1); let chunks = vertical_chunks_with_margin(vec![Constraint::Length(3)], area, 1);
if !app.data.radarr_data.is_searching { if !app.data.radarr_data.is_searching {
@@ -446,7 +469,7 @@ fn determine_row_style(downloads_vec: &[DownloadRecord], movie: &Movie) -> Style
if !movie.has_file { if !movie.has_file {
if let Some(download) = downloads_vec if let Some(download) = downloads_vec
.iter() .iter()
.find(|&download| download.movie_id == movie.id) .find(|&download| download.id == movie.id)
{ {
if download.status == "downloading" { if download.status == "downloading" {
return style_warning(); return style_warning();