Add a filtering tool to only show only certain release group types #252

Merged
wojtek merged 14 commits from 161---add-a-filtering-tool-to-only-show-only-certain-release-group-types into main 2025-01-04 22:42:27 +01:00
4 changed files with 22 additions and 25 deletions
Showing only changes of commit 19f201e1ac - Show all commits

View File

@ -89,7 +89,7 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
fn filter_collection(&self) -> Collection { fn filter_collection(&self) -> Collection {
let iter = self.collection.iter(); let iter = self.collection.iter();
iter.map(|a| self.filter_artist(a)).flatten().collect() iter.flat_map(|a| self.filter_artist(a)).collect()
} }
fn filter_artist(&self, artist: &Artist) -> Option<Artist> { fn filter_artist(&self, artist: &Artist) -> Option<Artist> {
@ -149,10 +149,7 @@ impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
collection::{ collection::{album::AlbumPrimaryType, artist::ArtistMeta},
album::{AlbumMeta, AlbumPrimaryType},
artist::ArtistMeta,
},
core::testmod::FULL_COLLECTION, core::testmod::FULL_COLLECTION,
filter::AlbumField, filter::AlbumField,
}; };
@ -331,14 +328,16 @@ mod tests {
#[test] #[test]
fn filtered() { fn filtered() {
let mut mh = MusicHoard::default(); let mut mh = MusicHoard {
mh.collection = vec![Artist { collection: vec![Artist {
meta: ArtistMeta::new(ArtistId::new("Artist")), meta: ArtistMeta::new(ArtistId::new("Artist")),
albums: vec![ albums: vec![
Album::new(AlbumId::new("Album 1")), Album::new(AlbumId::new("Album 1")),
Album::new(AlbumId::new("Album 2")), Album::new(AlbumId::new("Album 2")),
], ],
}]; }],
..Default::default()
};
mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Ep); mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Ep);
mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Album); mh.collection[0].albums[0].meta.info.primary_type = Some(AlbumPrimaryType::Album);

View File

@ -1,6 +1,8 @@
use crate::core::{ use crate::core::{
interface::{database::IDatabase, library::ILibrary}, interface::{database::IDatabase, library::ILibrary},
musichoard::{database::IMusicHoardDatabase, Error, MusicHoard, NoDatabase, NoLibrary, CollectionFilter}, musichoard::{
database::IMusicHoardDatabase, CollectionFilter, Error, MusicHoard, NoDatabase, NoLibrary,
},
}; };
/// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of /// Builder for [`MusicHoard`]. Its purpose is to make it easier to set various combinations of

View File

@ -21,7 +21,7 @@ impl CollectionFilter {
include && !except include && !except
} }
fn filter_and(empty: bool, group: &Vec<Vec<AlbumField>>, album: &Album) -> bool { fn filter_and(empty: bool, group: &[Vec<AlbumField>], album: &Album) -> bool {
let mut filter = !group.is_empty() || empty; let mut filter = !group.is_empty() || empty;
for field in group.iter() { for field in group.iter() {
filter = filter && Self::filter_or(field, album); filter = filter && Self::filter_or(field, album);
@ -29,7 +29,7 @@ impl CollectionFilter {
filter filter
} }
fn filter_or(group: &Vec<AlbumField>, album: &Album) -> bool { fn filter_or(group: &[AlbumField], album: &Album) -> bool {
let mut filter = false; let mut filter = false;
for field in group.iter() { for field in group.iter() {
filter = filter || Self::filter_field(field, album); filter = filter || Self::filter_field(field, album);
@ -42,7 +42,7 @@ impl CollectionFilter {
AlbumField::PrimaryType(filter) => *filter == album.meta.info.primary_type, AlbumField::PrimaryType(filter) => *filter == album.meta.info.primary_type,
AlbumField::SecondaryType(filter) => { AlbumField::SecondaryType(filter) => {
let types = &album.meta.info.secondary_types; let types = &album.meta.info.secondary_types;
types.iter().find(|st| *st == filter).is_some() types.iter().any(|st| st == filter)
} }
AlbumField::Ownership(filter) => *filter == album.get_ownership(), AlbumField::Ownership(filter) => *filter == album.get_ownership(),
} }

View File

@ -28,19 +28,15 @@ impl IAppInteractReload for AppMachine<ReloadState> {
type APP = App; type APP = App;
fn reload_library(mut self) -> Self::APP { fn reload_library(mut self) -> Self::APP {
let previous = KeySelection::get( let previous =
self.inner.music_hoard.get_filtered(), KeySelection::get(self.inner.music_hoard.get_filtered(), &self.inner.selection);
&self.inner.selection,
);
let result = self.inner.music_hoard.rescan_library(); let result = self.inner.music_hoard.rescan_library();
self.refresh(previous, result) self.refresh(previous, result)
} }
fn reload_database(mut self) -> Self::APP { fn reload_database(mut self) -> Self::APP {
let previous = KeySelection::get( let previous =
self.inner.music_hoard.get_filtered(), KeySelection::get(self.inner.music_hoard.get_filtered(), &self.inner.selection);
&self.inner.selection,
);
let result = self.inner.music_hoard.reload_database(); let result = self.inner.music_hoard.reload_database();
self.refresh(previous, result) self.refresh(previous, result)
} }