feat: CLI and TUI support for track history and track details in Lidarr
This commit is contained in:
@@ -2,6 +2,7 @@ use crate::app::App;
|
||||
use crate::models::Route;
|
||||
use crate::models::lidarr_models::{LidarrHistoryItem, LidarrRelease, Track};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ALBUM_DETAILS_BLOCKS, ActiveLidarrBlock};
|
||||
use crate::ui::lidarr_ui::library::track_details_ui::TrackDetailsUi;
|
||||
use crate::ui::lidarr_ui::lidarr_ui_utils::create_history_event_details;
|
||||
use crate::ui::styles::{ManagarrStyle, secondary_style};
|
||||
use crate::ui::utils::{
|
||||
@@ -31,10 +32,11 @@ impl DrawUi for AlbumDetailsUi {
|
||||
let Route::Lidarr(active_lidarr_block, _) = route else {
|
||||
return false;
|
||||
};
|
||||
ALBUM_DETAILS_BLOCKS.contains(&active_lidarr_block)
|
||||
TrackDetailsUi::accepts(route) || ALBUM_DETAILS_BLOCKS.contains(&active_lidarr_block)
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
let route = app.get_current_route();
|
||||
if app.data.lidarr_data.album_details_modal.is_some()
|
||||
&& let Route::Lidarr(active_lidarr_block, _) = app.get_current_route()
|
||||
{
|
||||
@@ -106,6 +108,10 @@ impl DrawUi for AlbumDetailsUi {
|
||||
};
|
||||
|
||||
draw_popup(f, app, draw_album_details_popup, Size::XLarge);
|
||||
|
||||
if TrackDetailsUi::accepts(route) {
|
||||
TrackDetailsUi::draw(f, app, _area);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ALBUM_DETAILS_BLOCKS, ActiveLidarrBlock};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ALBUM_DETAILS_BLOCKS, ActiveLidarrBlock, TRACK_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::models::stateful_table::StatefulTable;
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::lidarr_ui::library::album_details_ui::AlbumDetailsUi;
|
||||
@@ -11,8 +13,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_album_details_ui_accepts() {
|
||||
let mut album_details_blocks = ALBUM_DETAILS_BLOCKS.to_vec();
|
||||
album_details_blocks.extend(TRACK_DETAILS_BLOCKS);
|
||||
|
||||
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
|
||||
if ALBUM_DETAILS_BLOCKS.contains(&active_lidarr_block) {
|
||||
if album_details_blocks.contains(&active_lidarr_block) {
|
||||
assert!(AlbumDetailsUi::accepts(active_lidarr_block.into()));
|
||||
} else {
|
||||
assert!(!AlbumDetailsUi::accepts(active_lidarr_block.into()));
|
||||
@@ -127,5 +132,17 @@ mod tests {
|
||||
output
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_details_ui_renders_track_details_over_album_details() {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(ActiveLidarrBlock::TrackDetails.into());
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
AlbumDetailsUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ mod tests {
|
||||
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ALBUM_DETAILS_BLOCKS, ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock, DELETE_ALBUM_BLOCKS,
|
||||
TRACK_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::lidarr_ui::library::artist_details_ui::ArtistDetailsUi;
|
||||
@@ -13,6 +14,7 @@ mod tests {
|
||||
let mut blocks = ARTIST_DETAILS_BLOCKS.clone().to_vec();
|
||||
blocks.extend(DELETE_ALBUM_BLOCKS);
|
||||
blocks.extend(ALBUM_DETAILS_BLOCKS);
|
||||
blocks.extend(TRACK_DETAILS_BLOCKS);
|
||||
|
||||
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
|
||||
if blocks.contains(&active_lidarr_block) {
|
||||
|
||||
@@ -6,6 +6,7 @@ mod tests {
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{
|
||||
ADD_ARTIST_BLOCKS, ALBUM_DETAILS_BLOCKS, ARTIST_DETAILS_BLOCKS, ActiveLidarrBlock,
|
||||
DELETE_ALBUM_BLOCKS, DELETE_ARTIST_BLOCKS, EDIT_ARTIST_BLOCKS, LIBRARY_BLOCKS,
|
||||
TRACK_DETAILS_BLOCKS,
|
||||
};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::lidarr_ui::library::{LibraryUi, decorate_artist_row_with_style};
|
||||
@@ -23,12 +24,19 @@ mod tests {
|
||||
library_ui_blocks.extend(ADD_ARTIST_BLOCKS);
|
||||
library_ui_blocks.extend(ARTIST_DETAILS_BLOCKS);
|
||||
library_ui_blocks.extend(ALBUM_DETAILS_BLOCKS);
|
||||
library_ui_blocks.extend(TRACK_DETAILS_BLOCKS);
|
||||
|
||||
for active_lidarr_block in ActiveLidarrBlock::iter() {
|
||||
if library_ui_blocks.contains(&active_lidarr_block) {
|
||||
assert!(LibraryUi::accepts(active_lidarr_block.into()));
|
||||
assert!(
|
||||
LibraryUi::accepts(active_lidarr_block.into()),
|
||||
"{active_lidarr_block} is not accepted by the LibraryUi"
|
||||
);
|
||||
} else {
|
||||
assert!(!LibraryUi::accepts(active_lidarr_block.into()));
|
||||
assert!(
|
||||
!LibraryUi::accepts(active_lidarr_block.into()),
|
||||
"{active_lidarr_block} should not be accepted by LibraryUi"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,11 @@ use crate::{
|
||||
mod add_artist_ui;
|
||||
mod album_details_ui;
|
||||
mod artist_details_ui;
|
||||
mod delete_album_ui;
|
||||
mod delete_artist_ui;
|
||||
mod edit_artist_ui;
|
||||
mod track_details_ui;
|
||||
|
||||
mod delete_album_ui;
|
||||
#[cfg(test)]
|
||||
#[path = "library_ui_tests.rs"]
|
||||
mod library_ui_tests;
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/album_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Test Album Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Tracks │ History │ Manual Search │
|
||||
│──────╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮─────│
|
||||
│ # │ Track Details │ History │ │
|
||||
│=> 1 │──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ │
|
||||
│ │Some details: │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
|
||||
│ │
|
||||
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/library_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
Name ▼ Type Status Quality Profile Metadata Profile Albums Tracks Size Monitored Tags
|
||||
=> Alex Person Continuing Lossless Standard 1 15/15 0.00 GB 🏷 alex
|
||||
|
||||
|
||||
|
||||
╭─────────────────────────────────── Edit - Alex (American pianist) ────────────────────────────────────╮
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭───╮ │
|
||||
│ Monitored: │ ✔ │ │
|
||||
│ ╰───╯ │
|
||||
│ ╭─────────────────────────────────────────────────╮ │
|
||||
│ Monitor New Albums: │All Albums ▼ │ │
|
||||
│ ╰─────────────────────────────────────────────────╯ │
|
||||
│ ╭─────────────────────────────────────────────────╮ │
|
||||
│ Quality Profile: │Lossless ▼ │ │
|
||||
│ ╰─────────────────────────────────────────────────╯ │
|
||||
│ ╭─────────────────────────────────────────────────╮ │
|
||||
│ Metadata Profile: │Standard ▼ │ │
|
||||
│ ╰─────────────────────────────────────────────────╯ │
|
||||
│ ╭─────────────────────────────────────────────────╮ │
|
||||
│ Path: │/nfs/music │ │
|
||||
│ ╰─────────────────────────────────────────────────╯ │
|
||||
│ ╭─────────────────────────────────────────────────╮ │
|
||||
│ Tags: │alex │ │
|
||||
│ ╰─────────────────────────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│╭───────────────────────────────────────────────────╮╭──────────────────────────────────────────────────╮│
|
||||
││ Save ││ Cancel ││
|
||||
│╰───────────────────────────────────────────────────╯╰──────────────────────────────────────────────────╯│
|
||||
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ Loading ... │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ Loading ... │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭────────── Error ──────────╮ │
|
||||
│ │ The given filter produced │ │
|
||||
│ ╰─────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭─────────── Filter ───────────╮ │
|
||||
│ │track history filter │ │
|
||||
│ ╰────────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭────────── Error ──────────╮ │
|
||||
│ │ No items found matching │ │
|
||||
│ ╰─────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭─────────── Search ───────────╮ │
|
||||
│ │track history search │ │
|
||||
│ ╰────────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│Some details: │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭─────────────────────────────────── Details ───────────────────────────────────╮ │
|
||||
│ │Source Title: Test source title │ │
|
||||
│ │Event Type: grabbed │ │
|
||||
│ │Quality: Lossless │ │
|
||||
│ │Date: 2023-01-01 00:00:00 UTC │ │
|
||||
│ │Indexer: │ │
|
||||
│ │NZB Info URL: │ │
|
||||
│ │Release Group: │ │
|
||||
│ │Age: 0 days │ │
|
||||
│ │Published Date: 1970-01-01 00:00:00 UTC │ │
|
||||
│ │Download Client: │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ ╰─────────────────────────────────────────────────────────────────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ ╭──────────────────────╮ │
|
||||
│ │Something │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ │ │ │
|
||||
│ ╰──────────────────────╯ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: src/ui/lidarr_ui/library/track_details_ui_tests.rs
|
||||
expression: output
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
╭ Track Details ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Track Details │ History │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ Source Title ▼ Event Type Quality Date │
|
||||
│=> Test source title grabbed Lossless 2023-01-01 00:00:00 UTC │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
@@ -0,0 +1,259 @@
|
||||
use crate::app::App;
|
||||
use crate::models::Route;
|
||||
use crate::models::lidarr_models::{LidarrHistoryItem, Track};
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, TRACK_DETAILS_BLOCKS};
|
||||
use crate::ui::lidarr_ui::lidarr_ui_utils::create_history_event_details;
|
||||
use crate::ui::styles::ManagarrStyle;
|
||||
use crate::ui::styles::{downloaded_style, missing_style, secondary_style};
|
||||
use crate::ui::utils::{get_width_from_percentage, layout_block_top_border};
|
||||
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::{DrawUi, draw_popup, draw_tabs};
|
||||
use ratatui::Frame;
|
||||
use ratatui::layout::{Alignment, Constraint, Rect};
|
||||
use ratatui::style::{Style, Stylize};
|
||||
use ratatui::text::{Line, Span, Text};
|
||||
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "track_details_ui_tests.rs"]
|
||||
mod track_details_ui_tests;
|
||||
|
||||
pub(super) struct TrackDetailsUi;
|
||||
|
||||
impl DrawUi for TrackDetailsUi {
|
||||
fn accepts(route: Route) -> bool {
|
||||
let Route::Lidarr(active_lidarr_block, _) = route else {
|
||||
return false;
|
||||
};
|
||||
TRACK_DETAILS_BLOCKS.contains(&active_lidarr_block)
|
||||
}
|
||||
|
||||
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, _area: Rect) {
|
||||
if let Some(album_details_modal) = app.data.lidarr_data.album_details_modal.as_ref()
|
||||
&& album_details_modal.track_details_modal.is_some()
|
||||
&& let Route::Lidarr(active_lidarr_block, _) = app.get_current_route()
|
||||
{
|
||||
let draw_track_details_popup = |f: &mut Frame<'_>, app: &mut App<'_>, popup_area: Rect| {
|
||||
let content_area = draw_tabs(
|
||||
f,
|
||||
popup_area,
|
||||
"Track Details",
|
||||
&app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.expect("album_details_modal must exist in this context")
|
||||
.track_details_modal
|
||||
.as_ref()
|
||||
.expect("track_details_modal must exist in this context")
|
||||
.track_details_tabs,
|
||||
);
|
||||
draw_track_details_tabs(f, app, content_area);
|
||||
|
||||
if active_lidarr_block == ActiveLidarrBlock::TrackHistoryDetails {
|
||||
draw_history_item_details_popup(f, app);
|
||||
}
|
||||
};
|
||||
|
||||
draw_popup(f, app, draw_track_details_popup, Size::Large);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_track_details_tabs(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
if let Some(album_details_modal) = app.data.lidarr_data.album_details_modal.as_ref()
|
||||
&& let Some(track_details_modal) = album_details_modal.track_details_modal.as_ref()
|
||||
&& let Route::Lidarr(active_lidarr_block, _) =
|
||||
track_details_modal.track_details_tabs.get_active_route()
|
||||
{
|
||||
match active_lidarr_block {
|
||||
ActiveLidarrBlock::TrackDetails => draw_track_details(f, app, area),
|
||||
ActiveLidarrBlock::TrackHistory => draw_track_history_table(f, app, area),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_track_details(f: &mut Frame<'_>, app: &App<'_>, area: Rect) {
|
||||
let block = layout_block_top_border();
|
||||
|
||||
match app.data.lidarr_data.album_details_modal.as_ref() {
|
||||
Some(album_details_modal) if !app.is_loading => {
|
||||
if let Some(track_details_modal) = album_details_modal.track_details_modal.as_ref() {
|
||||
let track = album_details_modal.tracks.current_selection().clone();
|
||||
let track_details = &track_details_modal.track_details;
|
||||
let text = Text::from(
|
||||
track_details
|
||||
.items
|
||||
.iter()
|
||||
.filter(|it| !it.is_empty())
|
||||
.map(|line| {
|
||||
let split = line.split(':').collect::<Vec<&str>>();
|
||||
let title = format!("{}:", split[0]);
|
||||
let style = style_from_status(&track);
|
||||
|
||||
Line::from(vec![
|
||||
title.bold().style(style),
|
||||
Span::styled(split[1..].join(":"), style),
|
||||
])
|
||||
})
|
||||
.collect::<Vec<Line<'_>>>(),
|
||||
);
|
||||
|
||||
let paragraph = Paragraph::new(text)
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((track_details.offset, 0));
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
}
|
||||
}
|
||||
_ => f.render_widget(
|
||||
LoadingBlock::new(
|
||||
app.is_loading
|
||||
|| app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.expect("album_details_modal must exist in this context")
|
||||
.track_details_modal
|
||||
.is_none(),
|
||||
block,
|
||||
),
|
||||
area,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_track_history_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
|
||||
match app.data.lidarr_data.album_details_modal.as_ref() {
|
||||
Some(album_details_modal) if !app.is_loading => {
|
||||
let Route::Lidarr(active_lidarr_block, _) = app.get_current_route() else {
|
||||
panic!("Non-Lidarr route is being used");
|
||||
};
|
||||
if let Some(track_details_modal) = album_details_modal.track_details_modal.as_ref() {
|
||||
let current_selection = if track_details_modal.track_history.is_empty() {
|
||||
LidarrHistoryItem::default()
|
||||
} else {
|
||||
track_details_modal
|
||||
.track_history
|
||||
.current_selection()
|
||||
.clone()
|
||||
};
|
||||
|
||||
let history_row_mapping = |history_item: &LidarrHistoryItem| {
|
||||
let LidarrHistoryItem {
|
||||
source_title,
|
||||
quality,
|
||||
event_type,
|
||||
date,
|
||||
..
|
||||
} = history_item;
|
||||
|
||||
source_title.scroll_left_or_reset(
|
||||
get_width_from_percentage(area, 40),
|
||||
current_selection == *history_item,
|
||||
app.ui_scroll_tick_count == 0,
|
||||
);
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(source_title.to_string()),
|
||||
Cell::from(event_type.to_string()),
|
||||
Cell::from(quality.quality.name.to_owned()),
|
||||
Cell::from(date.to_string()),
|
||||
])
|
||||
.primary()
|
||||
};
|
||||
let mut track_history_table = &mut app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.expect("album_details_modal must exist in this context")
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.expect("track_details_modal must exist in this context")
|
||||
.track_history;
|
||||
let history_table = ManagarrTable::new(Some(&mut track_history_table), history_row_mapping)
|
||||
.block(layout_block_top_border())
|
||||
.loading(app.is_loading)
|
||||
.sorting(active_lidarr_block == ActiveLidarrBlock::TrackHistorySortPrompt)
|
||||
.searching(active_lidarr_block == ActiveLidarrBlock::SearchTrackHistory)
|
||||
.search_produced_empty_results(
|
||||
active_lidarr_block == ActiveLidarrBlock::SearchTrackHistoryError,
|
||||
)
|
||||
.filtering(active_lidarr_block == ActiveLidarrBlock::FilterTrackHistory)
|
||||
.filter_produced_empty_results(
|
||||
active_lidarr_block == ActiveLidarrBlock::FilterTrackHistoryError,
|
||||
)
|
||||
.headers(["Source Title", "Event Type", "Quality", "Date"])
|
||||
.constraints([
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(20),
|
||||
Constraint::Percentage(15),
|
||||
Constraint::Percentage(25),
|
||||
]);
|
||||
|
||||
f.render_widget(history_table, area);
|
||||
}
|
||||
}
|
||||
_ => f.render_widget(
|
||||
LoadingBlock::new(
|
||||
app.is_loading
|
||||
|| app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_ref()
|
||||
.expect("album_details_modal must exist in this context")
|
||||
.track_details_modal
|
||||
.is_none(),
|
||||
layout_block_top_border(),
|
||||
),
|
||||
area,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_history_item_details_popup(f: &mut Frame<'_>, app: &mut App<'_>) {
|
||||
let current_selection =
|
||||
if let Some(album_details_modal) = app.data.lidarr_data.album_details_modal.as_ref() {
|
||||
if let Some(track_details_modal) = album_details_modal.track_details_modal.as_ref() {
|
||||
if track_details_modal.track_history.is_empty() {
|
||||
LidarrHistoryItem::default()
|
||||
} else {
|
||||
track_details_modal
|
||||
.track_history
|
||||
.current_selection()
|
||||
.clone()
|
||||
}
|
||||
} else {
|
||||
LidarrHistoryItem::default()
|
||||
}
|
||||
} else {
|
||||
LidarrHistoryItem::default()
|
||||
};
|
||||
|
||||
let line_vec = create_history_event_details(current_selection);
|
||||
let text = Text::from(line_vec);
|
||||
|
||||
let message = Message::new(text)
|
||||
.title("Details")
|
||||
.style(secondary_style())
|
||||
.alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(Popup::new(message).size(Size::NarrowLongMessage), f.area());
|
||||
}
|
||||
|
||||
fn style_from_status(track: &Track) -> Style {
|
||||
if !track.has_file {
|
||||
return missing_style();
|
||||
}
|
||||
|
||||
downloaded_style()
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use crate::app::App;
|
||||
use crate::models::servarr_data::lidarr::lidarr_data::{ActiveLidarrBlock, TRACK_DETAILS_BLOCKS};
|
||||
use crate::ui::DrawUi;
|
||||
use crate::ui::lidarr_ui::library::track_details_ui::TrackDetailsUi;
|
||||
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
|
||||
|
||||
#[test]
|
||||
fn test_track_details_ui_accepts() {
|
||||
ActiveLidarrBlock::iter().for_each(|active_lidarr_block| {
|
||||
if TRACK_DETAILS_BLOCKS.contains(&active_lidarr_block) {
|
||||
assert!(TrackDetailsUi::accepts(active_lidarr_block.into()));
|
||||
} else {
|
||||
assert!(!TrackDetailsUi::accepts(active_lidarr_block.into()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
mod snapshot_tests {
|
||||
use crate::ui::ui_test_utils::test_utils::TerminalSize;
|
||||
use rstest::rstest;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveLidarrBlock::TrackDetails, 0)]
|
||||
#[case(ActiveLidarrBlock::TrackHistory, 1)]
|
||||
#[case(ActiveLidarrBlock::TrackHistoryDetails, 1)]
|
||||
#[case(ActiveLidarrBlock::SearchTrackHistory, 1)]
|
||||
#[case(ActiveLidarrBlock::SearchTrackHistoryError, 1)]
|
||||
#[case(ActiveLidarrBlock::FilterTrackHistory, 1)]
|
||||
#[case(ActiveLidarrBlock::FilterTrackHistoryError, 1)]
|
||||
#[case(ActiveLidarrBlock::TrackHistorySortPrompt, 1)]
|
||||
#[case(ActiveLidarrBlock::TrackHistoryDetails, 1)]
|
||||
fn test_track_details_ui_renders(
|
||||
#[case] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[case] index: usize,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.set_index(index);
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
TrackDetailsUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(
|
||||
format!("track_details_{active_lidarr_block}_{index}"),
|
||||
output
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveLidarrBlock::TrackDetails, 0)]
|
||||
#[case(ActiveLidarrBlock::TrackHistory, 1)]
|
||||
fn test_track_details_ui_renders_loading(
|
||||
#[case] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[case] index: usize,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.is_loading = true;
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_tabs
|
||||
.set_index(index);
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
TrackDetailsUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(
|
||||
format!("loading_track_details_{active_lidarr_block}_{index}"),
|
||||
output
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(ActiveLidarrBlock::TrackDetails, 0)]
|
||||
#[case(ActiveLidarrBlock::TrackHistory, 1)]
|
||||
fn test_track_details_ui_renders_empty(
|
||||
#[case] active_lidarr_block: ActiveLidarrBlock,
|
||||
#[case] index: usize,
|
||||
) {
|
||||
let mut app = App::test_default_fully_populated();
|
||||
app.push_navigation_stack(active_lidarr_block.into());
|
||||
{
|
||||
let track_details_modal = app
|
||||
.data
|
||||
.lidarr_data
|
||||
.album_details_modal
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.track_details_modal
|
||||
.as_mut()
|
||||
.unwrap();
|
||||
track_details_modal.track_details_tabs.set_index(index);
|
||||
track_details_modal.track_details = Default::default();
|
||||
track_details_modal.track_history = Default::default();
|
||||
}
|
||||
|
||||
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
|
||||
TrackDetailsUi::draw(f, app, f.area());
|
||||
});
|
||||
|
||||
insta::assert_snapshot!(
|
||||
format!("empty_track_details_{active_lidarr_block}_{index}"),
|
||||
output
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user