Implemented Library and Download tabs!

This commit is contained in:
2023-08-08 10:50:04 -06:00
parent d856e84b93
commit c16f234088
10 changed files with 257 additions and 61 deletions
+3 -13
View File
@@ -10,8 +10,8 @@ use crate::logos::{
BAZARR_LOGO, LIDARR_LOGO, PROWLARR_LOGO, RADARR_LOGO, READARR_LOGO, SONARR_LOGO,
};
use crate::ui::utils::{
centered_rect, horizontal_chunks, horizontal_chunks_with_margin, style_secondary,
style_system_function, vertical_chunks, vertical_chunks_with_margin,
centered_rect, horizontal_chunks, horizontal_chunks_with_margin, style_system_function,
style_warning, vertical_chunks, vertical_chunks_with_margin,
};
mod radarr_ui;
@@ -28,17 +28,7 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
draw_context_row(f, app, main_chunks[0]);
match app.get_current_route().clone() {
Route::Radarr(active_radarr_block) => match active_radarr_block {
ActiveRadarrBlock::Movies => radarr_ui::draw_radarr_ui(f, app, main_chunks[1]),
ActiveRadarrBlock::MovieDetails => draw_small_popup_over(
f,
app,
main_chunks[1],
radarr_ui::draw_radarr_ui,
radarr_ui::draw_movie_details,
),
_ => (),
},
Route::Radarr(_) => radarr_ui::draw_radarr_ui(f, app, main_chunks[1]),
}
}
+127 -41
View File
@@ -4,32 +4,72 @@ use std::ops::Sub;
use chrono::{Duration, Utc};
use tui::backend::Backend;
use tui::layout::{Alignment, Constraint, Rect};
use tui::style::{Color, Modifier, Style};
use tui::style::Style;
use tui::text::{Span, Spans, Text};
use tui::widgets::{Block, Borders, Cell, Paragraph, Row, Table, Wrap};
use tui::widgets::{Block, Borders, Cell, Paragraph, Row, Table, Tabs, Wrap};
use tui::Frame;
use crate::app::radarr::RadarrData;
use crate::app::App;
use crate::app::radarr::{ActiveRadarrBlock, RadarrData};
use crate::app::{App, Route};
use crate::logos::RADARR_LOGO;
use crate::network::radarr_network::{DownloadRecord, Movie};
use crate::ui::utils::{
horizontal_chunks_with_margin, line_gague, style_default, style_highlight, style_primary,
style_secondary, style_tertiary, title_block, vertical_chunks_with_margin,
horizontal_chunks_with_margin, line_gague, style_default, style_failure, style_highlight,
style_secondary, style_success, style_warning, title_block, vertical_chunks_with_margin,
};
use crate::ui::{loading, HIGHLIGHT_SYMBOL};
use crate::ui::{draw_small_popup_over, loading, HIGHLIGHT_SYMBOL};
use crate::utils::{convert_runtime, convert_to_gb};
pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let block = Block::default()
.borders(Borders::ALL)
.title(Spans::from(vec![Span::styled(
"Movies",
Style::default()
.fg(Color::Yellow)
.add_modifier(Modifier::BOLD),
)]));
let chunks =
vertical_chunks_with_margin(vec![Constraint::Length(2), Constraint::Min(0)], area, 1);
let block = title_block(" Movies");
let titles = app
.data
.radarr_data
.main_tabs
.tabs
.iter()
.map(|tab_route| Spans::from(Span::styled(&tab_route.title, style_default())))
.collect();
let tabs = Tabs::new(titles)
.block(block)
.highlight_style(style_secondary())
.select(app.data.radarr_data.main_tabs.index);
f.render_widget(tabs, area);
if let Route::Radarr(active_radarr_block) = app.get_current_route() {
match active_radarr_block {
ActiveRadarrBlock::Movies => draw_radarr_library(f, app, chunks[1]),
ActiveRadarrBlock::Downloads => draw_downloads(f, app, chunks[1]),
ActiveRadarrBlock::MovieDetails => {
draw_small_popup_over(f, app, chunks[1], draw_radarr_library, draw_movie_details)
}
_ => (),
}
}
}
pub(super) fn draw_radarr_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
let chunks = horizontal_chunks_with_margin(
vec![
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
],
area,
1,
);
draw_stats_context(f, app, chunks[0]);
f.render_widget(Block::default().borders(Borders::ALL), chunks[1]);
draw_downloads_context(f, app, chunks[2]);
}
fn draw_radarr_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let block = Block::default().borders(Borders::TOP);
let movies_vec = &app.data.radarr_data.movies.items;
if !movies_vec.is_empty() {
@@ -80,23 +120,7 @@ pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, ar
}
}
pub(super) fn draw_radarr_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
let chunks = horizontal_chunks_with_margin(
vec![
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
],
area,
1,
);
draw_stats(f, app, chunks[0]);
f.render_widget(Block::default().borders(Borders::ALL), chunks[1]);
draw_downloads(f, app, chunks[2]);
}
pub(super) fn draw_downloads<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
fn draw_downloads_context<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
let block = title_block("Downloads");
let downloads_vec = &app.data.radarr_data.downloads.items;
@@ -126,7 +150,69 @@ pub(super) fn draw_downloads<B: Backend>(f: &mut Frame<'_, B>, app: &App, area:
}
}
pub(super) fn draw_movie_details<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
fn draw_downloads<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
let block = Block::default().borders(Borders::TOP);
let downloads_vec = &app.data.radarr_data.downloads.items;
if !downloads_vec.is_empty() {
let rows = downloads_vec.iter().map(|download_record| {
let DownloadRecord {
title,
size,
sizeleft,
download_client,
indexer,
output_path,
..
} = download_record;
let percent = 1f64 - (sizeleft.as_f64().unwrap() / size.as_f64().unwrap());
let file_size: f64 = convert_to_gb(size.as_u64().unwrap());
Row::new(vec![
Cell::from(title.to_owned()),
Cell::from(format!("{:.0}%", percent * 100.0)),
Cell::from(format!("{:.2} GB", file_size)),
Cell::from(output_path.to_owned()),
Cell::from(indexer.to_owned()),
Cell::from(download_client.to_owned()),
])
.style(style_success())
});
let header_row = Row::new(vec![
"Title",
"Percent Complete",
"Size",
"Output Path",
"Indexer",
"Download Client",
])
.style(style_default())
.bottom_margin(0);
let constraints = vec![
Constraint::Percentage(30),
Constraint::Percentage(11),
Constraint::Percentage(11),
Constraint::Percentage(18),
Constraint::Percentage(17),
Constraint::Percentage(13),
];
let table = Table::new(rows)
.header(header_row)
.block(block)
.highlight_style(style_highlight())
.highlight_symbol(HIGHLIGHT_SYMBOL)
.widths(&constraints);
f.render_stateful_widget(table, area, &mut app.data.radarr_data.downloads.state);
} else {
loading(f, block, area, app.is_loading);
}
}
fn draw_movie_details<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
let block = title_block("Movie Details");
let movie_details = app.data.radarr_data.movie_details.get_text();
@@ -155,7 +241,7 @@ pub(super) fn draw_movie_details<B: Backend>(f: &mut Frame<'_, B>, app: &App, ar
}
}
pub(super) fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
fn draw_stats_context<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
let block = title_block("Stats");
if !app.data.radarr_data.version.is_empty() {
@@ -233,21 +319,21 @@ fn determine_row_style(app: &App, movie: &Movie) -> Style {
.find(|&download| download.movie_id == movie.id)
{
if download.status == "downloading" {
return style_secondary();
return style_warning();
}
}
return style_tertiary();
return style_failure();
}
style_primary()
style_success()
}
fn determine_style_from_download_status(download_status: &str) -> Style {
match download_status {
"Downloaded" => style_primary(),
"Downloading" => style_secondary(),
"Missing" => style_tertiary(),
_ => style_primary(),
"Downloaded" => style_success(),
"Downloading" => style_warning(),
"Missing" => style_failure(),
_ => style_success(),
}
}
+15 -3
View File
@@ -54,6 +54,10 @@ pub fn layout_block(title_span: Span<'_>) -> Block<'_> {
Block::default().borders(Borders::ALL).title(title_span)
}
pub fn layout_block_top_border(title_span: Span<'_>) -> Block<'_> {
Block::default().borders(Borders::TOP).title(title_span)
}
pub fn style_bold() -> Style {
Style::default().add_modifier(Modifier::BOLD)
}
@@ -66,19 +70,27 @@ pub fn style_default() -> Style {
Style::default().fg(Color::White)
}
pub fn style_primary() -> Style {
Style::default().fg(Color::Cyan)
}
pub fn style_secondary() -> Style {
Style::default().fg(Color::Yellow)
}
pub fn style_system_function() -> Style {
Style::default().fg(Color::Yellow)
}
pub fn style_primary() -> Style {
pub fn style_success() -> Style {
Style::default().fg(Color::Green)
}
pub fn style_secondary() -> Style {
pub fn style_warning() -> Style {
Style::default().fg(Color::Magenta)
}
pub fn style_tertiary() -> Style {
pub fn style_failure() -> Style {
Style::default().fg(Color::Red)
}