Added delete movie functionality
This commit is contained in:
@@ -81,7 +81,7 @@ tautulli:
|
|||||||
- [x] View details of a specific movie including description, history, downloaded file info, or the credits
|
- [x] View details of a specific movie including description, history, downloaded file info, or the credits
|
||||||
- [x] View details of any collection and the movies in them
|
- [x] View details of any collection and the movies in them
|
||||||
- [x] Search your library or collections
|
- [x] Search your library or collections
|
||||||
- [ ] Add movies to Radarr
|
- [ ] Add or delete movies
|
||||||
- [ ] Manage your quality profiles
|
- [ ] Manage your quality profiles
|
||||||
- [ ] Modify your Radarr settings
|
- [ ] Modify your Radarr settings
|
||||||
|
|
||||||
|
|||||||
+17
-12
@@ -9,18 +9,19 @@ macro_rules! generate_keybindings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generate_keybindings! {
|
generate_keybindings! {
|
||||||
up,
|
up,
|
||||||
down,
|
down,
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
backspace,
|
backspace,
|
||||||
search,
|
search,
|
||||||
filter,
|
filter,
|
||||||
home,
|
home,
|
||||||
end,
|
end,
|
||||||
submit,
|
delete,
|
||||||
quit,
|
submit,
|
||||||
esc
|
quit,
|
||||||
|
esc
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct KeyBinding {
|
pub struct KeyBinding {
|
||||||
@@ -65,6 +66,10 @@ pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
|
|||||||
key: Key::End,
|
key: Key::End,
|
||||||
desc: "End",
|
desc: "End",
|
||||||
},
|
},
|
||||||
|
delete: KeyBinding {
|
||||||
|
key: Key::Delete,
|
||||||
|
desc: "Delete selected item",
|
||||||
|
},
|
||||||
submit: KeyBinding {
|
submit: KeyBinding {
|
||||||
key: Key::Enter,
|
key: Key::Enter,
|
||||||
desc: "Select",
|
desc: "Select",
|
||||||
|
|||||||
+4
-1
@@ -29,6 +29,7 @@ pub struct App {
|
|||||||
pub network_tick_frequency: Duration,
|
pub network_tick_frequency: Duration,
|
||||||
pub is_routing: bool,
|
pub is_routing: bool,
|
||||||
pub is_loading: bool,
|
pub is_loading: bool,
|
||||||
|
pub should_refresh: bool,
|
||||||
pub config: AppConfig,
|
pub config: AppConfig,
|
||||||
pub data: Data,
|
pub data: Data,
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn on_tick(&mut self, is_first_render: bool) {
|
pub async fn on_tick(&mut self, is_first_render: bool) {
|
||||||
if self.tick_count % self.tick_until_poll == 0 || self.is_routing {
|
if self.tick_count % self.tick_until_poll == 0 || self.is_routing || self.should_refresh {
|
||||||
match self.get_current_route() {
|
match self.get_current_route() {
|
||||||
Route::Radarr(active_radarr_block) => {
|
Route::Radarr(active_radarr_block) => {
|
||||||
self
|
self
|
||||||
@@ -80,6 +81,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.is_routing = false;
|
self.is_routing = false;
|
||||||
|
self.should_refresh = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.tick_count += 1;
|
self.tick_count += 1;
|
||||||
@@ -133,6 +135,7 @@ impl Default for App {
|
|||||||
last_tick: Instant::now(),
|
last_tick: Instant::now(),
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
is_routing: false,
|
is_routing: false,
|
||||||
|
should_refresh: false,
|
||||||
config: AppConfig::default(),
|
config: AppConfig::default(),
|
||||||
data: Data::default(),
|
data: Data::default(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ pub struct RadarrData {
|
|||||||
pub movie_info_tabs: TabState,
|
pub movie_info_tabs: TabState,
|
||||||
pub search: String,
|
pub search: String,
|
||||||
pub filter: String,
|
pub filter: String,
|
||||||
|
pub prompt_confirm: bool,
|
||||||
pub is_searching: bool,
|
pub is_searching: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +89,7 @@ impl Default for RadarrData {
|
|||||||
search: String::default(),
|
search: String::default(),
|
||||||
filter: String::default(),
|
filter: String::default(),
|
||||||
is_searching: false,
|
is_searching: false,
|
||||||
|
prompt_confirm: false,
|
||||||
main_tabs: TabState::new(vec![
|
main_tabs: TabState::new(vec![
|
||||||
TabRoute {
|
TabRoute {
|
||||||
title: "Library".to_owned(),
|
title: "Library".to_owned(),
|
||||||
@@ -146,6 +148,7 @@ pub enum ActiveRadarrBlock {
|
|||||||
CollectionDetails,
|
CollectionDetails,
|
||||||
Cast,
|
Cast,
|
||||||
Crew,
|
Crew,
|
||||||
|
DeleteMoviePrompt,
|
||||||
FileInfo,
|
FileInfo,
|
||||||
FilterCollections,
|
FilterCollections,
|
||||||
FilterMovies,
|
FilterMovies,
|
||||||
@@ -192,6 +195,13 @@ impl App {
|
|||||||
self
|
self
|
||||||
.dispatch_network_event(RadarrEvent::GetDownloads.into())
|
.dispatch_network_event(RadarrEvent::GetDownloads.into())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
if self.data.radarr_data.prompt_confirm {
|
||||||
|
self.data.radarr_data.prompt_confirm = false;
|
||||||
|
self
|
||||||
|
.dispatch_network_event(RadarrEvent::DeleteMovie.into())
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ActiveRadarrBlock::MovieDetails | ActiveRadarrBlock::FileInfo => {
|
ActiveRadarrBlock::MovieDetails | ActiveRadarrBlock::FileInfo => {
|
||||||
self.is_loading = true;
|
self.is_loading = true;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pub enum Key {
|
|||||||
Backspace,
|
Backspace,
|
||||||
Home,
|
Home,
|
||||||
End,
|
End,
|
||||||
|
Delete,
|
||||||
Char(char),
|
Char(char),
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
@@ -57,6 +58,10 @@ impl From<KeyEvent> for Key {
|
|||||||
code: KeyCode::End,
|
code: KeyCode::End,
|
||||||
..
|
..
|
||||||
} => Key::End,
|
} => Key::End,
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Delete,
|
||||||
|
..
|
||||||
|
} => Key::Delete,
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Enter,
|
code: KeyCode::Enter,
|
||||||
..
|
..
|
||||||
|
|||||||
+4
-2
@@ -15,8 +15,9 @@ pub trait KeyEventHandler<'a, T: Into<Route>> {
|
|||||||
_ if *key == DEFAULT_KEYBINDINGS.down.key => self.handle_scroll_down(),
|
_ if *key == DEFAULT_KEYBINDINGS.down.key => self.handle_scroll_down(),
|
||||||
_ if *key == DEFAULT_KEYBINDINGS.home.key => self.handle_home(),
|
_ if *key == DEFAULT_KEYBINDINGS.home.key => self.handle_home(),
|
||||||
_ if *key == DEFAULT_KEYBINDINGS.end.key => self.handle_end(),
|
_ if *key == DEFAULT_KEYBINDINGS.end.key => self.handle_end(),
|
||||||
|
_ if *key == DEFAULT_KEYBINDINGS.delete.key => self.handle_delete(),
|
||||||
_ if *key == DEFAULT_KEYBINDINGS.left.key || *key == DEFAULT_KEYBINDINGS.right.key => {
|
_ if *key == DEFAULT_KEYBINDINGS.left.key || *key == DEFAULT_KEYBINDINGS.right.key => {
|
||||||
self.handle_tab_action()
|
self.handle_left_right_action()
|
||||||
}
|
}
|
||||||
_ if *key == DEFAULT_KEYBINDINGS.submit.key => self.handle_submit(),
|
_ if *key == DEFAULT_KEYBINDINGS.submit.key => self.handle_submit(),
|
||||||
_ if *key == DEFAULT_KEYBINDINGS.esc.key => self.handle_esc(),
|
_ if *key == DEFAULT_KEYBINDINGS.esc.key => self.handle_esc(),
|
||||||
@@ -34,7 +35,8 @@ pub trait KeyEventHandler<'a, T: Into<Route>> {
|
|||||||
fn handle_scroll_down(&mut self);
|
fn handle_scroll_down(&mut self);
|
||||||
fn handle_home(&mut self);
|
fn handle_home(&mut self);
|
||||||
fn handle_end(&mut self);
|
fn handle_end(&mut self);
|
||||||
fn handle_tab_action(&mut self);
|
fn handle_delete(&mut self);
|
||||||
|
fn handle_left_right_action(&mut self);
|
||||||
fn handle_submit(&mut self);
|
fn handle_submit(&mut self);
|
||||||
fn handle_esc(&mut self);
|
fn handle_esc(&mut self);
|
||||||
fn handle_char_key_event(&mut self);
|
fn handle_char_key_event(&mut self);
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for CollectionDetailsHandler<'a>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_tab_action(&mut self) {}
|
fn handle_delete(&mut self) {}
|
||||||
|
|
||||||
|
fn handle_left_right_action(&mut self) {}
|
||||||
|
|
||||||
fn handle_submit(&mut self) {
|
fn handle_submit(&mut self) {
|
||||||
if ActiveRadarrBlock::CollectionDetails == *self.active_radarr_block {
|
if ActiveRadarrBlock::CollectionDetails == *self.active_radarr_block {
|
||||||
|
|||||||
@@ -171,7 +171,15 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_tab_action(&mut self) {
|
fn handle_delete(&mut self) {
|
||||||
|
if *self.active_radarr_block == ActiveRadarrBlock::Movies {
|
||||||
|
self
|
||||||
|
.app
|
||||||
|
.push_navigation_stack(ActiveRadarrBlock::DeleteMoviePrompt.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_left_right_action(&mut self) {
|
||||||
match self.active_radarr_block {
|
match self.active_radarr_block {
|
||||||
ActiveRadarrBlock::Movies | ActiveRadarrBlock::Downloads | ActiveRadarrBlock::Collections => {
|
ActiveRadarrBlock::Movies | ActiveRadarrBlock::Downloads | ActiveRadarrBlock::Collections => {
|
||||||
match self.key {
|
match self.key {
|
||||||
@@ -202,6 +210,14 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ActiveRadarrBlock::DeleteMoviePrompt => match self.key {
|
||||||
|
_ if *self.key == DEFAULT_KEYBINDINGS.left.key
|
||||||
|
|| *self.key == DEFAULT_KEYBINDINGS.right.key =>
|
||||||
|
{
|
||||||
|
self.app.data.radarr_data.prompt_confirm = !self.app.data.radarr_data.prompt_confirm;
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -268,6 +284,10 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
|||||||
.set_items(filtered_collections);
|
.set_items(filtered_collections);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ActiveRadarrBlock::DeleteMoviePrompt => {
|
||||||
|
self.app.should_refresh = self.app.data.radarr_data.prompt_confirm;
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,6 +301,10 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for RadarrHandler<'a> {
|
|||||||
self.app.pop_navigation_stack();
|
self.app.pop_navigation_stack();
|
||||||
self.app.data.radarr_data.reset_search();
|
self.app.data.radarr_data.reset_search();
|
||||||
}
|
}
|
||||||
|
ActiveRadarrBlock::DeleteMoviePrompt => {
|
||||||
|
self.app.pop_navigation_stack();
|
||||||
|
self.app.data.radarr_data.prompt_confirm = false;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.app.data.radarr_data.reset_search();
|
self.app.data.radarr_data.reset_search();
|
||||||
handle_clear_errors(self.app);
|
handle_clear_errors(self.app);
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ impl<'a> KeyEventHandler<'a, ActiveRadarrBlock> for MovieDetailsHandler<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_tab_action(&mut self) {
|
fn handle_delete(&mut self) {}
|
||||||
|
|
||||||
|
fn handle_left_right_action(&mut self) {
|
||||||
match self.active_radarr_block {
|
match self.active_radarr_block {
|
||||||
ActiveRadarrBlock::MovieDetails
|
ActiveRadarrBlock::MovieDetails
|
||||||
| ActiveRadarrBlock::MovieHistory
|
| ActiveRadarrBlock::MovieHistory
|
||||||
|
|||||||
+204
-77
@@ -1,7 +1,7 @@
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use indoc::formatdoc;
|
use indoc::formatdoc;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use reqwest::RequestBuilder;
|
use reqwest::{RequestBuilder, StatusCode};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tokio::sync::MutexGuard;
|
use tokio::sync::MutexGuard;
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ use crate::utils::{convert_runtime, convert_to_gb};
|
|||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum RadarrEvent {
|
pub enum RadarrEvent {
|
||||||
|
DeleteMovie,
|
||||||
GetCollections,
|
GetCollections,
|
||||||
GetDownloads,
|
GetDownloads,
|
||||||
GetMovies,
|
GetMovies,
|
||||||
@@ -29,12 +30,24 @@ pub enum RadarrEvent {
|
|||||||
HealthCheck,
|
HealthCheck,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
enum RequestMethod {
|
||||||
|
GET,
|
||||||
|
DELETE,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RequestProps<T> {
|
||||||
|
pub resource: String,
|
||||||
|
pub method: RequestMethod,
|
||||||
|
pub body: Option<T>,
|
||||||
|
}
|
||||||
|
|
||||||
impl RadarrEvent {
|
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 => "/queue",
|
||||||
RadarrEvent::GetMovies | RadarrEvent::GetMovieDetails => "/movie",
|
RadarrEvent::GetMovies | RadarrEvent::GetMovieDetails | RadarrEvent::DeleteMovie => "/movie",
|
||||||
RadarrEvent::GetMovieCredits => "/credit",
|
RadarrEvent::GetMovieCredits => "/credit",
|
||||||
RadarrEvent::GetMovieHistory => "/history/movie",
|
RadarrEvent::GetMovieHistory => "/history/movie",
|
||||||
RadarrEvent::GetOverview => "/diskspace",
|
RadarrEvent::GetOverview => "/diskspace",
|
||||||
@@ -56,86 +69,133 @@ impl<'a> Network<'a> {
|
|||||||
match radarr_event {
|
match radarr_event {
|
||||||
RadarrEvent::GetCollections => {
|
RadarrEvent::GetCollections => {
|
||||||
self
|
self
|
||||||
.get_collections(RadarrEvent::GetCollections.resource())
|
.get_collections(RadarrEvent::GetCollections.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::HealthCheck => {
|
RadarrEvent::HealthCheck => {
|
||||||
self
|
self
|
||||||
.get_healthcheck(RadarrEvent::HealthCheck.resource())
|
.get_healthcheck(RadarrEvent::HealthCheck.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetOverview => {
|
RadarrEvent::GetOverview => {
|
||||||
self
|
self
|
||||||
.get_diskspace(RadarrEvent::GetOverview.resource())
|
.get_diskspace(RadarrEvent::GetOverview.resource().to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::GetStatus => {
|
||||||
|
self
|
||||||
|
.get_status(RadarrEvent::GetStatus.resource().to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::GetMovies => {
|
||||||
|
self
|
||||||
|
.get_movies(RadarrEvent::GetMovies.resource().to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::DeleteMovie => {
|
||||||
|
self
|
||||||
|
.delete_movie(RadarrEvent::DeleteMovie.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetStatus => self.get_status(RadarrEvent::GetStatus.resource()).await,
|
|
||||||
RadarrEvent::GetMovies => self.get_movies(RadarrEvent::GetMovies.resource()).await,
|
|
||||||
RadarrEvent::GetMovieCredits => {
|
RadarrEvent::GetMovieCredits => {
|
||||||
self
|
self
|
||||||
.get_credits(RadarrEvent::GetMovieCredits.resource())
|
.get_credits(RadarrEvent::GetMovieCredits.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetMovieDetails => {
|
RadarrEvent::GetMovieDetails => {
|
||||||
self
|
self
|
||||||
.get_movie_details(RadarrEvent::GetMovieDetails.resource())
|
.get_movie_details(RadarrEvent::GetMovieDetails.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetMovieHistory => {
|
RadarrEvent::GetMovieHistory => {
|
||||||
self
|
self
|
||||||
.get_movie_history(RadarrEvent::GetMovieHistory.resource())
|
.get_movie_history(RadarrEvent::GetMovieHistory.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetDownloads => {
|
RadarrEvent::GetDownloads => {
|
||||||
self
|
self
|
||||||
.get_downloads(RadarrEvent::GetDownloads.resource())
|
.get_downloads(RadarrEvent::GetDownloads.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
RadarrEvent::GetQualityProfiles => {
|
RadarrEvent::GetQualityProfiles => {
|
||||||
self
|
self
|
||||||
.get_quality_profiles(RadarrEvent::GetQualityProfiles.resource())
|
.get_quality_profiles(RadarrEvent::GetQualityProfiles.resource().to_owned())
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_healthcheck(&self, resource: &str) {
|
async fn get_healthcheck(&self, resource: String) {
|
||||||
if let Err(e) = self.call_radarr_api(resource).await.send().await {
|
if let Err(e) = self
|
||||||
|
.call_radarr_api::<()>(RequestProps {
|
||||||
|
resource,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<()>,
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
error!("Healthcheck failed. {:?}", e);
|
error!("Healthcheck failed. {:?}", e);
|
||||||
self.app.lock().await.handle_error(anyhow!(e));
|
self.app.lock().await.handle_error(anyhow!(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_diskspace(&self, resource: &str) {
|
async fn get_diskspace(&self, resource: String) {
|
||||||
|
type RequestType = Vec<DiskSpace>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<DiskSpace>>(resource, |disk_space_vec, mut app| {
|
.handle_request::<RequestType>(
|
||||||
app.data.radarr_data.disk_space_vec = disk_space_vec;
|
RequestProps {
|
||||||
})
|
resource,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<RequestType>,
|
||||||
|
},
|
||||||
|
|disk_space_vec, mut app| {
|
||||||
|
app.data.radarr_data.disk_space_vec = disk_space_vec;
|
||||||
|
},
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_status(&self, resource: &str) {
|
async fn get_status(&self, resource: String) {
|
||||||
self
|
self
|
||||||
.handle_get_request::<SystemStatus>(resource, |system_status, mut app| {
|
.handle_request::<SystemStatus>(
|
||||||
app.data.radarr_data.version = system_status.version;
|
RequestProps {
|
||||||
app.data.radarr_data.start_time = system_status.start_time;
|
resource,
|
||||||
})
|
method: RequestMethod::GET,
|
||||||
|
body: None::<SystemStatus>,
|
||||||
|
},
|
||||||
|
|system_status, mut app| {
|
||||||
|
app.data.radarr_data.version = system_status.version;
|
||||||
|
app.data.radarr_data.start_time = system_status.start_time;
|
||||||
|
},
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_movies(&self, resource: &str) {
|
async fn get_movies(&self, resource: String) {
|
||||||
|
type RequestType = Vec<Movie>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<Movie>>(resource, |movie_vec, mut app| {
|
.handle_request::<RequestType>(
|
||||||
app.data.radarr_data.movies.set_items(movie_vec)
|
RequestProps {
|
||||||
})
|
resource,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<RequestType>,
|
||||||
|
},
|
||||||
|
|movie_vec, mut app| app.data.radarr_data.movies.set_items(movie_vec),
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_movie_details(&self, resource: &str) {
|
async fn get_movie_details(&self, resource: String) {
|
||||||
let movie_id = self.extract_movie_id().await;
|
let movie_id = self.extract_movie_id().await;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Movie>(
|
.handle_request::<Movie>(
|
||||||
format!("{}/{}", resource, movie_id).as_str(),
|
RequestProps {
|
||||||
|
resource: format!("{}/{}", resource, movie_id),
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<Movie>,
|
||||||
|
},
|
||||||
|movie_response, mut app| {
|
|movie_response, mut app| {
|
||||||
let Movie {
|
let Movie {
|
||||||
id,
|
id,
|
||||||
@@ -277,10 +337,15 @@ impl<'a> Network<'a> {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_movie_history(&self, resource: &str) {
|
async fn get_movie_history(&self, resource: String) {
|
||||||
|
type RequestType = Vec<MovieHistoryItem>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<MovieHistoryItem>>(
|
.handle_request::<RequestType>(
|
||||||
self.append_movie_id_param(resource).await.as_str(),
|
RequestProps {
|
||||||
|
resource: self.append_movie_id_param(&resource).await,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<RequestType>,
|
||||||
|
},
|
||||||
|movie_history_vec, mut app| {
|
|movie_history_vec, mut app| {
|
||||||
let mut reversed_movie_history_vec = movie_history_vec.to_vec();
|
let mut reversed_movie_history_vec = movie_history_vec.to_vec();
|
||||||
reversed_movie_history_vec.reverse();
|
reversed_movie_history_vec.reverse();
|
||||||
@@ -294,41 +359,69 @@ impl<'a> Network<'a> {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_collections(&self, resource: &str) {
|
async fn get_collections(&self, resource: String) {
|
||||||
|
type RequestType = Vec<Collection>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<Collection>>(resource, |collections_vec, mut app| {
|
.handle_request::<RequestType>(
|
||||||
app.data.radarr_data.collections.set_items(collections_vec);
|
RequestProps {
|
||||||
})
|
resource,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<RequestType>,
|
||||||
|
},
|
||||||
|
|collections_vec, mut app| {
|
||||||
|
app.data.radarr_data.collections.set_items(collections_vec);
|
||||||
|
},
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_downloads(&self, resource: &str) {
|
async fn get_downloads(&self, resource: String) {
|
||||||
self
|
self
|
||||||
.handle_get_request::<DownloadsResponse>(resource, |queue_response, mut app| {
|
.handle_request::<DownloadsResponse>(
|
||||||
app
|
RequestProps {
|
||||||
.data
|
resource,
|
||||||
.radarr_data
|
method: RequestMethod::GET,
|
||||||
.downloads
|
body: None::<DownloadsResponse>,
|
||||||
.set_items(queue_response.records);
|
},
|
||||||
})
|
|queue_response, mut app| {
|
||||||
|
app
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.downloads
|
||||||
|
.set_items(queue_response.records);
|
||||||
|
},
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_quality_profiles(&self, resource: &str) {
|
async fn get_quality_profiles(&self, resource: String) {
|
||||||
|
type RequestType = Vec<QualityProfile>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<QualityProfile>>(resource, |quality_profiles, mut app| {
|
.handle_request::<RequestType>(
|
||||||
app.data.radarr_data.quality_profile_map = quality_profiles
|
RequestProps {
|
||||||
.iter()
|
resource,
|
||||||
.map(|profile| (profile.id.as_u64().unwrap(), profile.name.clone()))
|
method: RequestMethod::GET,
|
||||||
.collect();
|
body: None::<RequestType>,
|
||||||
})
|
},
|
||||||
|
|quality_profiles, mut app| {
|
||||||
|
app.data.radarr_data.quality_profile_map = quality_profiles
|
||||||
|
.iter()
|
||||||
|
.map(|profile| (profile.id.as_u64().unwrap(), profile.name.clone()))
|
||||||
|
.collect();
|
||||||
|
},
|
||||||
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_credits(&self, resource: &str) {
|
async fn get_credits(&self, resource: String) {
|
||||||
|
type RequestType = Vec<Credit>;
|
||||||
self
|
self
|
||||||
.handle_get_request::<Vec<Credit>>(
|
.handle_request::<RequestType>(
|
||||||
self.append_movie_id_param(resource).await.as_str(),
|
RequestProps {
|
||||||
|
resource: self.append_movie_id_param(&resource).await,
|
||||||
|
method: RequestMethod::GET,
|
||||||
|
body: None::<RequestType>,
|
||||||
|
},
|
||||||
|credit_vec, mut app| {
|
|credit_vec, mut app| {
|
||||||
let cast_vec: Vec<Credit> = credit_vec
|
let cast_vec: Vec<Credit> = credit_vec
|
||||||
.iter()
|
.iter()
|
||||||
@@ -348,7 +441,26 @@ impl<'a> Network<'a> {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn call_radarr_api(&self, resource: &str) -> RequestBuilder {
|
async fn delete_movie(&self, resource: String) {
|
||||||
|
let movie_id = self.extract_movie_id().await;
|
||||||
|
self
|
||||||
|
.handle_request::<()>(
|
||||||
|
RequestProps {
|
||||||
|
resource: format!("{}/{}", resource, movie_id),
|
||||||
|
method: RequestMethod::DELETE,
|
||||||
|
body: None::<()>,
|
||||||
|
},
|
||||||
|
|_, _| (),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn call_radarr_api<T>(&self, request_props: RequestProps<T>) -> RequestBuilder {
|
||||||
|
let RequestProps {
|
||||||
|
resource,
|
||||||
|
method,
|
||||||
|
body,
|
||||||
|
} = request_props;
|
||||||
debug!("Creating RequestBuilder for resource: {:?}", resource);
|
debug!("Creating RequestBuilder for resource: {:?}", resource);
|
||||||
let app = self.app.lock().await;
|
let app = self.app.lock().await;
|
||||||
let RadarrConfig {
|
let RadarrConfig {
|
||||||
@@ -356,38 +468,53 @@ impl<'a> Network<'a> {
|
|||||||
port,
|
port,
|
||||||
api_token,
|
api_token,
|
||||||
} = &app.config.radarr;
|
} = &app.config.radarr;
|
||||||
|
let uri = format!(
|
||||||
|
"http://{}:{}/api/v3{}",
|
||||||
|
host,
|
||||||
|
port.unwrap_or(7878),
|
||||||
|
resource
|
||||||
|
);
|
||||||
|
|
||||||
app
|
match method {
|
||||||
.client
|
RequestMethod::GET => app.client.get(uri).header("X-Api-Key", api_token),
|
||||||
.get(format!(
|
RequestMethod::DELETE => app.client.delete(uri).header("X-Api-Key", api_token),
|
||||||
"http://{}:{}/api/v3{}",
|
}
|
||||||
host,
|
|
||||||
port.unwrap_or(7878),
|
|
||||||
resource
|
|
||||||
))
|
|
||||||
.header("X-Api-Key", api_token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_get_request<T>(
|
async fn handle_request<T>(
|
||||||
&self,
|
&self,
|
||||||
resource: &str,
|
request_props: RequestProps<T>,
|
||||||
mut app_update_fn: impl FnMut(T, MutexGuard<App>),
|
mut app_update_fn: impl FnMut(T, MutexGuard<App>),
|
||||||
) where
|
) where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
{
|
{
|
||||||
match self.call_radarr_api(resource).await.send().await {
|
let method = request_props.method.clone();
|
||||||
Ok(response) => match utils::parse_response::<T>(response).await {
|
match self.call_radarr_api(request_props).await.send().await {
|
||||||
Ok(value) => {
|
Ok(response) => match method {
|
||||||
let app = self.app.lock().await;
|
RequestMethod::GET => match utils::parse_response::<T>(response).await {
|
||||||
app_update_fn(value, app);
|
Ok(value) => {
|
||||||
}
|
let app = self.app.lock().await;
|
||||||
Err(e) => {
|
app_update_fn(value, app);
|
||||||
error!("Failed to parse response! {:?}", e);
|
}
|
||||||
self.app.lock().await.handle_error(anyhow!(e));
|
Err(e) => {
|
||||||
|
error!("Failed to parse response! {:?}", e);
|
||||||
|
self.app.lock().await.handle_error(anyhow!(e));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
RequestMethod::DELETE => {
|
||||||
|
if response.status() != StatusCode::OK {
|
||||||
|
error!(
|
||||||
|
"Received the following code for delete operation: {:?}",
|
||||||
|
response.status()
|
||||||
|
);
|
||||||
|
self.app.lock().await.handle_error(anyhow!(
|
||||||
|
"Received a non 200 OK response for delete operation"
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to fetch resource. {:?}", e);
|
error!("Failed to send request. {:?}", e);
|
||||||
self.app.lock().await.handle_error(anyhow!(e));
|
self.app.lock().await.handle_error(anyhow!(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-6
@@ -1,8 +1,6 @@
|
|||||||
use std::iter::Map;
|
|
||||||
use std::slice::Iter;
|
|
||||||
|
|
||||||
use tui::backend::Backend;
|
use tui::backend::Backend;
|
||||||
use tui::layout::{Alignment, Constraint, Rect};
|
use tui::layout::{Alignment, Constraint, Rect};
|
||||||
|
use tui::style::{Modifier, Style};
|
||||||
use tui::text::{Span, Spans, Text};
|
use tui::text::{Span, Spans, Text};
|
||||||
use tui::widgets::Clear;
|
use tui::widgets::Clear;
|
||||||
use tui::widgets::Paragraph;
|
use tui::widgets::Paragraph;
|
||||||
@@ -15,9 +13,10 @@ use tui::Frame;
|
|||||||
use crate::app::App;
|
use crate::app::App;
|
||||||
use crate::models::{Route, StatefulTable, TabState};
|
use crate::models::{Route, StatefulTable, TabState};
|
||||||
use crate::ui::utils::{
|
use crate::ui::utils::{
|
||||||
borderless_block, centered_rect, horizontal_chunks_with_margin, layout_block_top_border,
|
borderless_block, centered_rect, horizontal_chunks, horizontal_chunks_with_margin, layout_block,
|
||||||
logo_block, style_default_bold, style_failure, style_help, style_highlight, style_primary,
|
layout_block_top_border, logo_block, style_default_bold, style_failure, style_help,
|
||||||
style_secondary, style_system_function, title_block, vertical_chunks_with_margin,
|
style_highlight, style_primary, style_secondary, style_system_function, title_block,
|
||||||
|
vertical_chunks_with_margin,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod radarr_ui;
|
mod radarr_ui;
|
||||||
@@ -252,3 +251,56 @@ pub fn loading<B: Backend>(f: &mut Frame<'_, B>, block: Block<'_>, area: Rect, i
|
|||||||
f.render_widget(block, area)
|
f.render_widget(block, area)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn draw_prompt_box<B: Backend>(
|
||||||
|
f: &mut Frame<'_, B>,
|
||||||
|
prompt_area: Rect,
|
||||||
|
title: &str,
|
||||||
|
prompt: &str,
|
||||||
|
yes_no_value: &bool,
|
||||||
|
) {
|
||||||
|
f.render_widget(
|
||||||
|
title_block(title).title_alignment(Alignment::Center),
|
||||||
|
prompt_area,
|
||||||
|
);
|
||||||
|
|
||||||
|
let chunks = vertical_chunks_with_margin(
|
||||||
|
vec![
|
||||||
|
Constraint::Percentage(72),
|
||||||
|
Constraint::Min(0),
|
||||||
|
Constraint::Length(3),
|
||||||
|
],
|
||||||
|
prompt_area,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
let prompt_paragraph = Paragraph::new(Text::from(prompt))
|
||||||
|
.block(borderless_block())
|
||||||
|
.style(style_primary().add_modifier(Modifier::BOLD))
|
||||||
|
.wrap(Wrap { trim: false })
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
f.render_widget(prompt_paragraph, chunks[0]);
|
||||||
|
|
||||||
|
let horizontal_chunks = horizontal_chunks(
|
||||||
|
vec![Constraint::Percentage(50), Constraint::Percentage(50)],
|
||||||
|
chunks[2],
|
||||||
|
);
|
||||||
|
|
||||||
|
draw_button(f, horizontal_chunks[0], "Yes", *yes_no_value);
|
||||||
|
draw_button(f, horizontal_chunks[1], "No", !*yes_no_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw_button<B: Backend>(f: &mut Frame<'_, B>, area: Rect, label: &str, is_selected: bool) {
|
||||||
|
let style = if is_selected {
|
||||||
|
style_system_function().add_modifier(Modifier::BOLD)
|
||||||
|
} else {
|
||||||
|
style_default_bold()
|
||||||
|
};
|
||||||
|
|
||||||
|
let label_paragraph = Paragraph::new(Text::from(label))
|
||||||
|
.block(layout_block())
|
||||||
|
.alignment(Alignment::Center)
|
||||||
|
.style(style);
|
||||||
|
|
||||||
|
f.render_widget(label_paragraph, area);
|
||||||
|
}
|
||||||
|
|||||||
+25
-1
@@ -23,7 +23,8 @@ use crate::ui::utils::{
|
|||||||
vertical_chunks_with_margin,
|
vertical_chunks_with_margin,
|
||||||
};
|
};
|
||||||
use crate::ui::{
|
use crate::ui::{
|
||||||
draw_large_popup_over, draw_popup_over, draw_table, draw_tabs, loading, TableProps,
|
draw_large_popup_over, draw_popup_over, draw_prompt_box, draw_table, draw_tabs, loading,
|
||||||
|
TableProps,
|
||||||
};
|
};
|
||||||
use crate::utils::{convert_runtime, convert_to_gb};
|
use crate::utils::{convert_runtime, convert_to_gb};
|
||||||
|
|
||||||
@@ -68,6 +69,15 @@ pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, ar
|
|||||||
draw_collection_details_popup,
|
draw_collection_details_popup,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
ActiveRadarrBlock::DeleteMoviePrompt => draw_popup_over(
|
||||||
|
f,
|
||||||
|
app,
|
||||||
|
content_rect,
|
||||||
|
draw_library,
|
||||||
|
draw_delete_movie_prompt,
|
||||||
|
30,
|
||||||
|
30,
|
||||||
|
),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,6 +151,20 @@ fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_delete_movie_prompt<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, prompt_area: Rect) {
|
||||||
|
draw_prompt_box(
|
||||||
|
f,
|
||||||
|
prompt_area,
|
||||||
|
" Confirm Delete Movie? ",
|
||||||
|
format!(
|
||||||
|
"Do you really want to delete {}?",
|
||||||
|
app.data.radarr_data.movies.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 {
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ pub fn title_block(title: &str) -> Block<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn logo_block<'a>() -> Block<'a> {
|
pub fn logo_block<'a>() -> Block<'a> {
|
||||||
Block::default().borders(Borders::ALL).title(Span::styled(
|
layout_block().title(Span::styled(
|
||||||
" Managarr - A Servarr management TUI ",
|
" Managarr - A Servarr management TUI ",
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Color::Magenta)
|
.fg(Color::Magenta)
|
||||||
|
|||||||
Reference in New Issue
Block a user