Mostly added Add movie functionality. Removed calendar functions for now. Want to add the ability to modify settings and quality profiles first

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent ae6e19a414
commit 08cde20359
14 changed files with 475 additions and 98 deletions
+2 -5
View File
@@ -16,7 +16,7 @@ use crate::ui::utils::{
borderless_block, centered_rect, horizontal_chunks, horizontal_chunks_with_margin, layout_block,
layout_block_top_border, logo_block, style_default_bold, style_failure, style_help,
style_highlight, style_primary, style_secondary, style_system_function, title_block,
vertical_chunks_with_margin,
title_block_centered, vertical_chunks_with_margin,
};
mod radarr_ui;
@@ -259,10 +259,7 @@ pub fn draw_prompt_box<B: Backend>(
prompt: &str,
yes_no_value: &bool,
) {
f.render_widget(
title_block(title).title_alignment(Alignment::Center),
prompt_area,
);
f.render_widget(title_block_centered(title), prompt_area);
let chunks = vertical_chunks_with_margin(
vec![
+177
View File
@@ -0,0 +1,177 @@
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Rect};
use tui::text::Text;
use tui::widgets::{Cell, Paragraph, Row};
use tui::Frame;
use crate::app::radarr::ActiveRadarrBlock;
use crate::models::Route;
use crate::ui::utils::{
borderless_block, layout_block, show_cursor, style_default, style_help, style_primary,
title_block_centered, vertical_chunks_with_margin,
};
use crate::ui::{draw_medium_popup_over, draw_prompt_box, draw_table, TableProps};
use crate::utils::convert_runtime;
use crate::App;
pub(super) fn draw_add_movie_search_popup<B: Backend>(
f: &mut Frame<'_, B>,
app: &mut App,
area: Rect,
) {
if let Route::Radarr(active_radarr_block) = app.get_current_route().clone() {
match active_radarr_block {
ActiveRadarrBlock::AddMovieSearchInput | ActiveRadarrBlock::AddMovieSearchResults => {
draw_add_movie_search(f, app, area);
}
ActiveRadarrBlock::AddMoviePrompt => {
draw_medium_popup_over(
f,
app,
area,
draw_add_movie_search,
draw_add_movie_confirmation_prompt,
);
}
_ => (),
}
}
}
fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let chunks = vertical_chunks_with_margin(
vec![
Constraint::Length(3),
Constraint::Min(0),
Constraint::Length(3),
],
area,
1,
);
let block_content = app.data.radarr_data.search.as_str();
let search_paragraph = Paragraph::new(Text::from(block_content))
.style(style_default())
.block(title_block_centered(" Add Movie "));
if let Route::Radarr(active_radarr_block) = app.get_current_route().clone() {
match active_radarr_block {
ActiveRadarrBlock::AddMovieSearchInput => {
show_cursor(f, chunks[0], block_content);
f.render_widget(layout_block(), chunks[1]);
let mut help_text = Text::from("<esc> close");
help_text.patch_style(style_help());
let help_paragraph = Paragraph::new(help_text)
.block(borderless_block())
.alignment(Alignment::Center);
f.render_widget(help_paragraph, chunks[2]);
}
ActiveRadarrBlock::AddMovieSearchResults | ActiveRadarrBlock::AddMoviePrompt => {
let mut help_text = Text::from("<esc> edit search");
help_text.patch_style(style_help());
let help_paragraph = Paragraph::new(help_text)
.block(borderless_block())
.alignment(Alignment::Center);
f.render_widget(help_paragraph, chunks[2]);
draw_table(
f,
chunks[1],
layout_block(),
TableProps {
content: &mut app.data.radarr_data.add_searched_movies,
table_headers: vec![
"Title",
"Year",
"Runtime",
"IMDB Rating",
"Rotten Tomatoes Rating",
"Genres",
],
constraints: vec![
Constraint::Percentage(20),
Constraint::Percentage(8),
Constraint::Percentage(10),
Constraint::Percentage(10),
Constraint::Percentage(18),
Constraint::Percentage(30),
],
},
|movie| {
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
let imdb_rating = movie
.ratings
.imdb
.clone()
.unwrap_or_default()
.value
.as_f64()
.unwrap();
let rotten_tomatoes_rating = movie
.ratings
.rotten_tomatoes
.clone()
.unwrap_or_default()
.value
.as_u64()
.unwrap();
let imdb_rating = if imdb_rating == 0.0 {
String::default()
} else {
format!("{:.1}", imdb_rating)
};
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
String::default()
} else {
format!("{}%", rotten_tomatoes_rating)
};
Row::new(vec![
Cell::from(movie.title.to_owned()),
Cell::from(movie.year.as_u64().unwrap().to_string()),
Cell::from(format!("{}h {}m", hours, minutes)),
Cell::from(imdb_rating),
Cell::from(rotten_tomatoes_rating),
Cell::from(movie.genres.join(", ")),
])
.style(style_primary())
},
app.is_loading,
);
}
_ => (),
}
}
f.render_widget(search_paragraph, chunks[0]);
}
fn draw_add_movie_confirmation_prompt<B: Backend>(
f: &mut Frame<'_, B>,
app: &mut App,
prompt_area: Rect,
) {
draw_prompt_box(
f,
prompt_area,
" Confirm Add Movie? ",
format!(
"{}:\n\n{}",
app
.data
.radarr_data
.add_searched_movies
.current_selection()
.title,
app
.data
.radarr_data
.add_searched_movies
.current_selection()
.overview
)
.as_str(),
&app.data.radarr_data.prompt_confirm,
);
}
+13 -2
View File
@@ -14,12 +14,13 @@ use crate::app::App;
use crate::logos::RADARR_LOGO;
use crate::models::radarr_models::{DiskSpace, DownloadRecord, Movie};
use crate::models::Route;
use crate::ui::radarr_ui::add_movie_ui::draw_add_movie_search_popup;
use crate::ui::radarr_ui::collection_details_ui::draw_collection_details_popup;
use crate::ui::radarr_ui::movie_details_ui::draw_movie_info;
use crate::ui::utils::{
borderless_block, horizontal_chunks, layout_block, layout_block_top_border,
line_gauge_with_label, line_gauge_with_title, show_cursor, style_bold, style_default,
style_failure, style_primary, style_success, style_warning, title_block,
style_failure, style_primary, style_success, style_warning, title_block, title_block_centered,
vertical_chunks_with_margin,
};
use crate::ui::{
@@ -28,6 +29,7 @@ use crate::ui::{
};
use crate::utils::{convert_runtime, convert_to_gb};
mod add_movie_ui;
mod collection_details_ui;
mod movie_details_ui;
@@ -60,6 +62,15 @@ pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, ar
| ActiveRadarrBlock::Crew => {
draw_large_popup_over(f, app, content_rect, draw_library, draw_movie_info)
}
ActiveRadarrBlock::AddMovieSearchInput
| ActiveRadarrBlock::AddMovieSearchResults
| ActiveRadarrBlock::AddMoviePrompt => draw_large_popup_over(
f,
app,
content_rect,
draw_library,
draw_add_movie_search_popup,
),
ActiveRadarrBlock::CollectionDetails | ActiveRadarrBlock::ViewMovieOverview => {
draw_large_popup_over(
f,
@@ -200,7 +211,7 @@ fn draw_search_box<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect)
let input = Paragraph::new(block_content)
.style(style_default())
.block(title_block(block_title));
.block(title_block_centered(block_title));
show_cursor(f, chunks[0], block_content);
f.render_widget(input, chunks[0]);
+5 -1
View File
@@ -1,5 +1,5 @@
use tui::backend::Backend;
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use tui::style::{Color, Modifier, Style};
use tui::text::{Span, Spans};
use tui::widgets::{Block, Borders, LineGauge};
@@ -152,6 +152,10 @@ pub fn title_block(title: &str) -> Block<'_> {
layout_block_with_title(title_style(title))
}
pub fn title_block_centered(title: &str) -> Block<'_> {
title_block(title).title_alignment(Alignment::Center)
}
pub fn logo_block<'a>() -> Block<'a> {
layout_block().title(Span::styled(
" Managarr - A Servarr management TUI ",