diff --git a/src/tui/ui/browse_state.rs b/src/tui/ui/browse_state.rs index 4a0129f..7047802 100644 --- a/src/tui/ui/browse_state.rs +++ b/src/tui/ui/browse_state.rs @@ -163,19 +163,23 @@ impl<'a, 'b> AlbumState<'a, 'b> { "Title: {}\n\ Date: {}\n\ Type: {}\n\ + Status: {}\n\ Ownership: {}", album.map(|a| a.meta.id.title.as_str()).unwrap_or(""), album .map(|a| UiDisplay::display_date(&a.meta.date, &a.meta.seq)) .unwrap_or_default(), album - .map(|a| UiDisplay::display_type( + .map(|a| UiDisplay::display_album_type( &a.meta.info.primary_type, &a.meta.info.secondary_types )) .unwrap_or_default(), album - .map(|a| UiDisplay::display_album_status(&a.get_ownership())) + .map(|a| UiDisplay::display_album_status(&a.meta.info.status)) + .unwrap_or(""), + album + .map(|a| UiDisplay::display_album_ownership(&a.get_ownership())) .unwrap_or("") )); diff --git a/src/tui/ui/display.rs b/src/tui/ui/display.rs index 1dcc4bb..32535cd 100644 --- a/src/tui/ui/display.rs +++ b/src/tui/ui/display.rs @@ -1,7 +1,7 @@ use musichoard::collection::{ album::{ AlbumDate, AlbumId, AlbumLibId, AlbumMeta, AlbumOwnership, AlbumPrimaryType, - AlbumSecondaryType, AlbumSeq, + AlbumSecondaryType, AlbumSeq, AlbumStatus, }, artist::ArtistMeta, musicbrainz::{IMusicBrainzRef, MbRefOption}, @@ -50,19 +50,33 @@ impl UiDisplay { } } - pub fn display_type( + pub fn display_album_status(value: &Option) -> &'static str { + match value { + Some(status) => match status { + AlbumStatus::Official => "Official", + AlbumStatus::Promotion => "Promotion", + AlbumStatus::Bootleg => "Bootleg", + AlbumStatus::PseudoRelease => "Pseudo-Release", + AlbumStatus::Withdrawn => "Withdrawn", + AlbumStatus::Cancelled => "Cancelled", + }, + None => "", + } + } + + pub fn display_album_type( primary: &Option, secondary: &Vec, ) -> String { match primary { Some(ref primary) => { if secondary.is_empty() { - Self::display_primary_type(primary).to_string() + Self::display_album_primary_type(primary).to_string() } else { format!( "{} ({})", - Self::display_primary_type(primary), - Self::display_secondary_types(secondary) + Self::display_album_primary_type(primary), + Self::display_album_secondary_types(secondary) ) } } @@ -70,7 +84,7 @@ impl UiDisplay { } } - pub fn display_primary_type(value: &AlbumPrimaryType) -> &'static str { + pub fn display_album_primary_type(value: &AlbumPrimaryType) -> &'static str { match value { AlbumPrimaryType::Album => "Album", AlbumPrimaryType::Single => "Single", @@ -80,7 +94,7 @@ impl UiDisplay { } } - pub fn display_secondary_types(values: &Vec) -> String { + pub fn display_album_secondary_types(values: &Vec) -> String { let mut types: Vec<&'static str> = vec![]; for value in values { match value { @@ -101,7 +115,7 @@ impl UiDisplay { types.join(", ") } - pub fn display_album_status(status: &AlbumOwnership) -> &'static str { + pub fn display_album_ownership(status: &AlbumOwnership) -> &'static str { match status { AlbumOwnership::None => "None", AlbumOwnership::Owned(format) => match format { @@ -173,7 +187,7 @@ impl UiDisplay { "{:010} | {} [{}]", UiDisplay::display_album_date(&album.date), album.id.title, - UiDisplay::display_type(&album.info.primary_type, &album.info.secondary_types), + UiDisplay::display_album_type(&album.info.primary_type, &album.info.secondary_types), ) } @@ -224,30 +238,62 @@ mod tests { } #[test] - fn display_primary_type() { + fn display_album_status() { assert_eq!( - UiDisplay::display_primary_type(&AlbumPrimaryType::Album), + UiDisplay::display_album_status(&Some(AlbumStatus::Official)), + "Official" + ); + assert_eq!( + UiDisplay::display_album_status(&Some(AlbumStatus::Promotion)), + "Promotion" + ); + assert_eq!( + UiDisplay::display_album_status(&Some(AlbumStatus::Bootleg)), + "Bootleg" + ); + assert_eq!( + UiDisplay::display_album_status(&Some(AlbumStatus::PseudoRelease)), + "Pseudo-Release" + ); + assert_eq!( + UiDisplay::display_album_status(&Some(AlbumStatus::Withdrawn)), + "Withdrawn" + ); + assert_eq!( + UiDisplay::display_album_status(&Some(AlbumStatus::Cancelled)), + "Cancelled" + ); + assert_eq!(UiDisplay::display_album_status(&None), ""); + } + + #[test] + fn display_album_primary_type() { + assert_eq!( + UiDisplay::display_album_primary_type(&AlbumPrimaryType::Album), "Album" ); assert_eq!( - UiDisplay::display_primary_type(&AlbumPrimaryType::Single), + UiDisplay::display_album_primary_type(&AlbumPrimaryType::Single), "Single" ); - assert_eq!(UiDisplay::display_primary_type(&AlbumPrimaryType::Ep), "EP"); assert_eq!( - UiDisplay::display_primary_type(&AlbumPrimaryType::Broadcast), + UiDisplay::display_album_primary_type(&AlbumPrimaryType::Ep), + "EP" + ); + assert_eq!( + UiDisplay::display_album_primary_type(&AlbumPrimaryType::Broadcast), "Broadcast" ); assert_eq!( - UiDisplay::display_primary_type(&AlbumPrimaryType::Other), + UiDisplay::display_album_primary_type(&AlbumPrimaryType::Other), "Other" ); } #[test] - fn display_secondary_types() { + fn display_album_secondary_types() { assert_eq!( - UiDisplay::display_secondary_types(&vec![ + UiDisplay::display_album_secondary_types(&vec![ AlbumSecondaryType::Compilation, AlbumSecondaryType::Soundtrack, AlbumSecondaryType::Spokenword, @@ -267,14 +313,14 @@ mod tests { } #[test] - fn display_type() { - assert_eq!(UiDisplay::display_type(&None, &vec![]), ""); + fn display_album_type() { + assert_eq!(UiDisplay::display_album_type(&None, &vec![]), ""); assert_eq!( - UiDisplay::display_type(&Some(AlbumPrimaryType::Album), &vec![]), + UiDisplay::display_album_type(&Some(AlbumPrimaryType::Album), &vec![]), "Album" ); assert_eq!( - UiDisplay::display_type( + UiDisplay::display_album_type( &Some(AlbumPrimaryType::Album), &vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation] ), @@ -283,17 +329,17 @@ mod tests { } #[test] - fn display_album_status() { + fn display_album_ownership() { assert_eq!( - UiDisplay::display_album_status(&AlbumOwnership::None), + UiDisplay::display_album_ownership(&AlbumOwnership::None), "None" ); assert_eq!( - UiDisplay::display_album_status(&AlbumOwnership::Owned(TrackFormat::Mp3)), + UiDisplay::display_album_ownership(&AlbumOwnership::Owned(TrackFormat::Mp3)), "MP3" ); assert_eq!( - UiDisplay::display_album_status(&AlbumOwnership::Owned(TrackFormat::Flac)), + UiDisplay::display_album_ownership(&AlbumOwnership::Owned(TrackFormat::Flac)), "FLAC" ); }