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 {
title: "Downloads".to_owned(),
route: ActiveRadarrBlock::Downloads.into(),
help: String::default(),
help: "<del> delete ".to_owned(),
},
TabRoute {
title: "Collections".to_owned(),
@@ -170,12 +170,12 @@ pub enum ActiveRadarrBlock {
AddMovieSelectQualityProfile,
AddMovieSelectMonitor,
AddMovieConfirmPrompt,
Calendar,
Collections,
CollectionDetails,
Cast,
Crew,
DeleteMoviePrompt,
DeleteDownloadPrompt,
FileInfo,
FilterCollections,
FilterMovies,
@@ -185,7 +185,6 @@ pub enum ActiveRadarrBlock {
Downloads,
SearchMovie,
SearchCollection,
SortOptions,
ViewMovieOverview,
}
+18 -5
View File
@@ -183,10 +183,14 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
}
fn handle_delete(&mut self) {
if *self.active_radarr_block == ActiveRadarrBlock::Movies {
self
match self.active_radarr_block {
ActiveRadarrBlock::Movies => self
.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();
}
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.should_ignore_quit_key = false;
}
ActiveRadarrBlock::DeleteMoviePrompt => {
ActiveRadarrBlock::DeleteMoviePrompt | ActiveRadarrBlock::DeleteDownloadPrompt => {
self.app.pop_navigation_stack();
self.app.data.radarr_data.prompt_confirm = false;
}
+1 -1
View File
@@ -148,7 +148,7 @@ pub struct DownloadRecord {
pub title: String,
pub status: String,
#[derivative(Default(value = "Number::from(0)"))]
pub movie_id: Number,
pub id: Number,
#[derivative(Default(value = "Number::from(0)"))]
pub size: Number,
#[derivative(Default(value = "Number::from(0)"))]
+32 -3
View File
@@ -8,8 +8,7 @@ use urlencoding::encode;
use crate::app::RadarrConfig;
use crate::models::radarr_models::{
AddMovieBody, AddMovieSearchResult, AddOptions, Collection, Credit, CreditType, DiskSpace,
DownloadsResponse, MinimumAvailability, Movie, MovieHistoryItem, QualityProfile, RootFolder,
SystemStatus,
DownloadsResponse, Movie, MovieHistoryItem, QualityProfile, RootFolder, SystemStatus,
};
use crate::models::ScrollableText;
use crate::network::utils::get_movie_status;
@@ -19,6 +18,7 @@ use crate::utils::{convert_runtime, convert_to_gb};
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum RadarrEvent {
AddMovie,
DeleteDownload,
DeleteMovie,
GetCollections,
GetDownloads,
@@ -38,7 +38,7 @@ impl RadarrEvent {
const fn resource(self) -> &'static str {
match self {
RadarrEvent::GetCollections => "/collection",
RadarrEvent::GetDownloads => "/queue",
RadarrEvent::GetDownloads | RadarrEvent::DeleteDownload => "/queue",
RadarrEvent::AddMovie
| RadarrEvent::GetMovies
| RadarrEvent::GetMovieDetails
@@ -70,6 +70,7 @@ impl<'a> Network<'a> {
RadarrEvent::GetStatus => self.get_status().await,
RadarrEvent::GetMovies => self.get_movies().await,
RadarrEvent::DeleteMovie => self.delete_movie().await,
RadarrEvent::DeleteDownload => self.delete_download().await,
RadarrEvent::GetMovieCredits => self.get_credits().await,
RadarrEvent::GetMovieDetails => self.get_movie_details().await,
RadarrEvent::GetMovieHistory => self.get_movie_history().await,
@@ -490,6 +491,34 @@ impl<'a> Network<'a> {
.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) {
info!("Adding new movie to Radarr");
let body = {
+1 -1
View File
@@ -16,7 +16,7 @@ pub fn get_movie_status(
if !has_file {
if let Some(download) = downloads_vec
.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" {
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,
),
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) {
let chunks = vertical_chunks_with_margin(vec![Constraint::Length(3)], area, 1);
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 let Some(download) = downloads_vec
.iter()
.find(|&download| download.movie_id == movie.id)
.find(|&download| download.id == movie.id)
{
if download.status == "downloading" {
return style_warning();