refactor: Improved and simplified the implementation of history details for both Sonarr and Lidarr
This commit is contained in:
1 parent
ad9e2b3671
commit
e1a25bfaf2
18 files changed
+377
-486
No files matched your search
@@ -1,18 +1,17 @@
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
|
||||
use crate::models::sonarr_models::{SonarrHistoryData, SonarrHistoryItem};
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::models::sonarr_models::{SonarrHistoryData, SonarrHistoryEventType, SonarrHistoryItem};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sonarr_ui_utils_tests.rs"]
|
||||
mod sonarr_ui_utils_tests;
|
||||
|
||||
pub(super) fn create_grabbed_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
pub(super) fn create_history_event_details(history_item: SonarrHistoryItem) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem {
|
||||
source_title, data, ..
|
||||
source_title,
|
||||
data,
|
||||
event_type,
|
||||
..
|
||||
} = history_item;
|
||||
let SonarrHistoryData {
|
||||
indexer,
|
||||
@@ -22,120 +21,10 @@ pub(super) fn create_grabbed_history_event_details(
|
||||
download_client_name,
|
||||
age,
|
||||
published_date,
|
||||
..
|
||||
} = data;
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Indexer: ".bold().secondary(),
|
||||
indexer.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Release Group: ".bold().secondary(),
|
||||
release_group.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Series Match Type: ".bold().secondary(),
|
||||
series_match_type.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"NZB Info URL: ".bold().secondary(),
|
||||
nzb_info_url.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Download Client Name: ".bold().secondary(),
|
||||
download_client_name.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Age: ".bold().secondary(),
|
||||
format!("{} days", age.unwrap_or("0".to_owned())).secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Published Date: ".bold().secondary(),
|
||||
published_date.unwrap_or_default().to_string().secondary(),
|
||||
]),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn create_download_folder_imported_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem {
|
||||
source_title, data, ..
|
||||
} = history_item;
|
||||
let SonarrHistoryData {
|
||||
dropped_path,
|
||||
imported_path,
|
||||
..
|
||||
} = data;
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Dropped Path: ".bold().secondary(),
|
||||
dropped_path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Imported Path: ".bold().secondary(),
|
||||
imported_path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn create_download_failed_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem {
|
||||
source_title, data, ..
|
||||
} = history_item;
|
||||
let SonarrHistoryData { message, .. } = data;
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Message: ".bold().secondary(),
|
||||
message.unwrap_or_default().secondary(),
|
||||
]),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn create_episode_file_deleted_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem {
|
||||
source_title, data, ..
|
||||
} = history_item;
|
||||
let SonarrHistoryData { reason, .. } = data;
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Reason: ".bold().secondary(),
|
||||
reason.unwrap_or_default().secondary(),
|
||||
]),
|
||||
]
|
||||
}
|
||||
|
||||
pub(super) fn create_episode_file_renamed_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem {
|
||||
source_title, data, ..
|
||||
} = history_item;
|
||||
let SonarrHistoryData {
|
||||
message,
|
||||
reason,
|
||||
source_path,
|
||||
source_relative_path,
|
||||
path,
|
||||
@@ -143,41 +32,87 @@ pub(super) fn create_episode_file_renamed_history_event_details(
|
||||
..
|
||||
} = data;
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Source Path: ".bold().secondary(),
|
||||
source_path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Source Relative Path: ".bold().secondary(),
|
||||
source_relative_path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Destination Path: ".bold().secondary(),
|
||||
path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
Line::from(vec![
|
||||
"Destination Relative Path: ".bold().secondary(),
|
||||
relative_path.unwrap_or_default().secondary(),
|
||||
]),
|
||||
]
|
||||
}
|
||||
let mut lines = vec![
|
||||
Line::from(format!("Source Title: {}", source_title.text.trim_start())),
|
||||
Line::from(format!("Event Type: {}", event_type)),
|
||||
];
|
||||
|
||||
pub(super) fn create_no_data_history_event_details(
|
||||
history_item: SonarrHistoryItem,
|
||||
) -> Vec<Line<'static>> {
|
||||
let SonarrHistoryItem { source_title, .. } = history_item;
|
||||
match event_type {
|
||||
SonarrHistoryEventType::Grabbed => {
|
||||
lines.push(Line::from(format!(
|
||||
"Indexer: {}",
|
||||
indexer.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Release Group: {}",
|
||||
release_group.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Series Match Type: {}",
|
||||
series_match_type.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"NZB Info URL: {}",
|
||||
nzb_info_url.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Download Client Name: {}",
|
||||
download_client_name.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Age: {}",
|
||||
format!("{} days", age.unwrap_or("0".to_owned())).trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Published Date: {}",
|
||||
published_date.unwrap_or_default().to_string().trim_start(),
|
||||
)));
|
||||
}
|
||||
SonarrHistoryEventType::DownloadFolderImported => {
|
||||
lines.push(Line::from(format!(
|
||||
"Dropped Path: {}",
|
||||
dropped_path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Imported Path: {}",
|
||||
imported_path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
}
|
||||
SonarrHistoryEventType::DownloadFailed => {
|
||||
lines.push(Line::from(format!(
|
||||
"Message: {}",
|
||||
message.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
}
|
||||
SonarrHistoryEventType::EpisodeFileDeleted => {
|
||||
lines.push(Line::from(format!(
|
||||
"Reason: {}",
|
||||
reason.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
}
|
||||
SonarrHistoryEventType::EpisodeFileRenamed => {
|
||||
lines.push(Line::from(format!(
|
||||
"Source Path: {}",
|
||||
source_path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Source Relative Path: {}",
|
||||
source_relative_path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Destination Path: {}",
|
||||
path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
lines.push(Line::from(format!(
|
||||
"Destination Relative Path: {}",
|
||||
relative_path.unwrap_or_default().trim_start(),
|
||||
)));
|
||||
}
|
||||
_ => {
|
||||
lines.push(Line::from(String::new()));
|
||||
lines.push(Line::from("No additional data available"));
|
||||
}
|
||||
}
|
||||
|
||||
vec![
|
||||
Line::from(vec![
|
||||
"Source Title: ".bold().secondary(),
|
||||
source_title.text.secondary(),
|
||||
]),
|
||||
Line::from(vec![String::new().secondary()]),
|
||||
Line::from(vec!["No additional data available".bold().secondary()]),
|
||||
]
|
||||
lines
|
||||
}
|
||||
Reference in new issue
Block a user