test: Updated Rust edition to 2024 and refactored network module tests to be more idiomatic
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
use crate::app::App;
|
||||
use crate::models::Route;
|
||||
use crate::models::servarr_data::sonarr::sonarr_data::{ActiveSonarrBlock, EPISODE_DETAILS_BLOCKS};
|
||||
use crate::models::sonarr_models::{
|
||||
DownloadRecord, DownloadStatus, Episode, SonarrHistoryEventType, SonarrHistoryItem, SonarrRelease,
|
||||
};
|
||||
use crate::models::Route;
|
||||
use crate::ui::sonarr_ui::sonarr_ui_utils::{
|
||||
create_download_failed_history_event_details,
|
||||
create_download_folder_imported_history_event_details,
|
||||
@@ -21,14 +21,14 @@ use crate::ui::widgets::loading_block::LoadingBlock;
|
||||
use crate::ui::widgets::managarr_table::ManagarrTable;
|
||||
use crate::ui::widgets::message::Message;
|
||||
use crate::ui::widgets::popup::{Popup, Size};
|
||||
use crate::ui::{draw_popup, draw_tabs, DrawUi};
|
||||
use crate::ui::{DrawUi, draw_popup, draw_tabs};
|
||||
use crate::utils::convert_to_gb;
|
||||
use chrono::Utc;
|
||||
use ratatui::Frame;
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||
use ratatui::Frame;
|
||||
use serde_json::Number;
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -47,76 +47,80 @@ impl DrawUi for EpisodeDetailsUi {
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
if let Some(season_details_modal) = app.data.sonarr_data.season_details_modal.as_ref() {
|
||||
if season_details_modal.episode_details_modal.is_some() {
|
||||
if let Route::Sonarr(active_sonarr_block, _) = app.get_current_route() {
|
||||
let draw_episode_details_popup =
|
||||
|f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect| {
|
||||
let content_area = draw_tabs(
|
||||
f,
|
||||
popup_area,
|
||||
"Episode Details",
|
||||
&app
|
||||
.data
|
||||
.sonarr_data
|
||||
.season_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.episode_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.episode_details_tabs,
|
||||
);
|
||||
draw_episode_details_tabs(f, app, content_area);
|
||||
if let Some(season_details_modal) = app.data.sonarr_data.season_details_modal.as_ref()
|
||||
&& season_details_modal.episode_details_modal.is_some()
|
||||
&& let Route::Sonarr(active_sonarr_block, _) = app.get_current_route()
|
||||
{
|
||||
let draw_episode_details_popup = |f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect| {
|
||||
let content_area = draw_tabs(
|
||||
f,
|
||||
popup_area,
|
||||
"Episode Details",
|
||||
&app
|
||||
.data
|
||||
.sonarr_data
|
||||
.season_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.episode_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.episode_details_tabs,
|
||||
);
|
||||
draw_episode_details_tabs(f, app, content_area);
|
||||
|
||||
match active_sonarr_block {
|
||||
ActiveSonarrBlock::AutomaticallySearchEpisodePrompt => {
|
||||
let prompt = format!(
|
||||
"Do you want to trigger an automatic search of your indexers for the episode: {}",
|
||||
app.data.sonarr_data.season_details_modal.as_ref().unwrap().episodes.current_selection().title
|
||||
);
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Automatic Episode Search")
|
||||
.prompt(&prompt)
|
||||
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||
match active_sonarr_block {
|
||||
ActiveSonarrBlock::AutomaticallySearchEpisodePrompt => {
|
||||
let prompt = format!(
|
||||
"Do you want to trigger an automatic search of your indexers for the episode: {}",
|
||||
app
|
||||
.data
|
||||
.sonarr_data
|
||||
.season_details_modal
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.episodes
|
||||
.current_selection()
|
||||
.title
|
||||
);
|
||||
let confirmation_prompt = ConfirmationPrompt::new()
|
||||
.title("Automatic Episode Search")
|
||||
.prompt(&prompt)
|
||||
.yes_no_value(app.data.sonarr_data.prompt_confirm);
|
||||
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::MediumPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt => {
|
||||
draw_manual_episode_search_confirm_prompt(f, app);
|
||||
}
|
||||
ActiveSonarrBlock::EpisodeHistoryDetails => {
|
||||
draw_history_item_details_popup(f, app, popup_area);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
};
|
||||
|
||||
draw_popup(f, app, draw_episode_details_popup, Size::Large);
|
||||
f.render_widget(
|
||||
Popup::new(confirmation_prompt).size(Size::MediumPrompt),
|
||||
f.area(),
|
||||
);
|
||||
}
|
||||
ActiveSonarrBlock::ManualEpisodeSearchConfirmPrompt => {
|
||||
draw_manual_episode_search_confirm_prompt(f, app);
|
||||
}
|
||||
ActiveSonarrBlock::EpisodeHistoryDetails => {
|
||||
draw_history_item_details_popup(f, app, popup_area);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
draw_popup(f, app, draw_episode_details_popup, Size::Large);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_episode_details_tabs(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Some(season_details_modal) = app.data.sonarr_data.season_details_modal.as_ref() {
|
||||
if let Some(episode_details_modal) = season_details_modal.episode_details_modal.as_ref() {
|
||||
if let Route::Sonarr(active_sonarr_block, _) = episode_details_modal
|
||||
.episode_details_tabs
|
||||
.get_active_route()
|
||||
{
|
||||
match active_sonarr_block {
|
||||
ActiveSonarrBlock::EpisodeDetails => draw_episode_details(f, app, area),
|
||||
ActiveSonarrBlock::EpisodeHistory => draw_episode_history_table(f, app, area),
|
||||
ActiveSonarrBlock::EpisodeFile => draw_file_info(f, app, area),
|
||||
ActiveSonarrBlock::ManualEpisodeSearch => draw_episode_releases(f, app, area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
if let Some(season_details_modal) = app.data.sonarr_data.season_details_modal.as_ref()
|
||||
&& let Some(episode_details_modal) = season_details_modal.episode_details_modal.as_ref()
|
||||
&& let Route::Sonarr(active_sonarr_block, _) = episode_details_modal
|
||||
.episode_details_tabs
|
||||
.get_active_route()
|
||||
{
|
||||
match active_sonarr_block {
|
||||
ActiveSonarrBlock::EpisodeDetails => draw_episode_details(f, app, area),
|
||||
ActiveSonarrBlock::EpisodeHistory => draw_episode_history_table(f, app, area),
|
||||
ActiveSonarrBlock::EpisodeFile => draw_file_info(f, app, area),
|
||||
ActiveSonarrBlock::ManualEpisodeSearch => draw_episode_releases(f, app, area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,16 +201,22 @@ fn draw_file_info(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let file_info = episode_details_modal.file_details.to_owned();
|
||||
let audio_details = episode_details_modal.audio_details.to_owned();
|
||||
let video_details = episode_details_modal.video_details.to_owned();
|
||||
let [file_details_title_area, file_details_area, audio_details_title_area, audio_details_area, video_details_title_area, video_details_area] =
|
||||
Layout::vertical([
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(5),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(6),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(7),
|
||||
])
|
||||
.areas(area);
|
||||
let [
|
||||
file_details_title_area,
|
||||
file_details_area,
|
||||
audio_details_title_area,
|
||||
audio_details_area,
|
||||
video_details_title_area,
|
||||
video_details_area,
|
||||
] = Layout::vertical([
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(5),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(6),
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(7),
|
||||
])
|
||||
.areas(area);
|
||||
|
||||
let file_details_title_paragraph =
|
||||
Paragraph::new("File Details".bold()).block(layout_block_top_border());
|
||||
@@ -593,10 +603,10 @@ fn style_from_status(download: Option<&DownloadRecord>, episode: &Episode) -> St
|
||||
return Style::new().unmonitored_missing();
|
||||
}
|
||||
|
||||
if let Some(air_date) = episode.air_date_utc.as_ref() {
|
||||
if air_date > &Utc::now() {
|
||||
return Style::new().unreleased();
|
||||
}
|
||||
if let Some(air_date) = episode.air_date_utc.as_ref()
|
||||
&& air_date > &Utc::now()
|
||||
{
|
||||
return Style::new().unreleased();
|
||||
}
|
||||
|
||||
return Style::new().missing();
|
||||
|
||||
Reference in New Issue
Block a user