Add a filtering tool to only show only certain release group types #252
@ -3,8 +3,8 @@ use crate::core::collection::album::{Album, AlbumOwnership, AlbumPrimaryType, Al
|
|||||||
/// Filter for a specifying subsets of the entire collection (e.g., for display).
|
/// Filter for a specifying subsets of the entire collection (e.g., for display).
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct CollectionFilter {
|
pub struct CollectionFilter {
|
||||||
pub include: Vec<Vec<AlbumField>>,
|
pub include: Vec<AlbumField>,
|
||||||
pub except: Vec<Vec<AlbumField>>,
|
pub except: Vec<AlbumField>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -16,19 +16,11 @@ pub enum AlbumField {
|
|||||||
|
|
||||||
impl CollectionFilter {
|
impl CollectionFilter {
|
||||||
pub fn filter_album(&self, album: &Album) -> bool {
|
pub fn filter_album(&self, album: &Album) -> bool {
|
||||||
let include = Self::filter_and(&self.include, album);
|
let include = Self::filter_or(&self.include, album);
|
||||||
let except = Self::filter_and(&self.except, album);
|
let except = Self::filter_or(&self.except, album);
|
||||||
include && !except
|
include && !except
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_and(group: &Vec<Vec<AlbumField>>, album: &Album) -> bool {
|
|
||||||
let mut filter = !group.is_empty();
|
|
||||||
for group in group.iter() {
|
|
||||||
filter = filter && Self::filter_or(group, album);
|
|
||||||
}
|
|
||||||
filter
|
|
||||||
}
|
|
||||||
|
|
||||||
fn filter_or(group: &Vec<AlbumField>, album: &Album) -> bool {
|
fn filter_or(group: &Vec<AlbumField>, album: &Album) -> bool {
|
||||||
let mut filter = false;
|
let mut filter = false;
|
||||||
for field in group.iter() {
|
for field in group.iter() {
|
||||||
@ -60,18 +52,18 @@ mod tests {
|
|||||||
|
|
||||||
fn test_filter() -> CollectionFilter {
|
fn test_filter() -> CollectionFilter {
|
||||||
CollectionFilter {
|
CollectionFilter {
|
||||||
include: vec![vec![
|
include: vec![
|
||||||
AlbumField::PrimaryType(None),
|
AlbumField::PrimaryType(None),
|
||||||
AlbumField::PrimaryType(Some(AlbumPrimaryType::Ep)),
|
AlbumField::PrimaryType(Some(AlbumPrimaryType::Ep)),
|
||||||
AlbumField::PrimaryType(Some(AlbumPrimaryType::Album)),
|
AlbumField::PrimaryType(Some(AlbumPrimaryType::Album)),
|
||||||
]],
|
],
|
||||||
except: vec![vec![
|
except: vec![
|
||||||
AlbumField::Ownership(AlbumOwnership::None),
|
AlbumField::Ownership(AlbumOwnership::None),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Compilation),
|
AlbumField::SecondaryType(AlbumSecondaryType::Compilation),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Soundtrack),
|
AlbumField::SecondaryType(AlbumSecondaryType::Soundtrack),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Live),
|
AlbumField::SecondaryType(AlbumSecondaryType::Live),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Demo),
|
AlbumField::SecondaryType(AlbumSecondaryType::Demo),
|
||||||
]],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,12 +73,12 @@ struct DbOpt {
|
|||||||
|
|
||||||
fn default_filter() -> CollectionFilter {
|
fn default_filter() -> CollectionFilter {
|
||||||
CollectionFilter {
|
CollectionFilter {
|
||||||
include: vec![vec![
|
include: vec![
|
||||||
AlbumField::PrimaryType(None),
|
AlbumField::PrimaryType(None),
|
||||||
AlbumField::PrimaryType(Some(AlbumPrimaryType::Ep)),
|
AlbumField::PrimaryType(Some(AlbumPrimaryType::Ep)),
|
||||||
AlbumField::PrimaryType(Some(AlbumPrimaryType::Album)),
|
AlbumField::PrimaryType(Some(AlbumPrimaryType::Album)),
|
||||||
]],
|
],
|
||||||
except: vec![vec![
|
except: vec![
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Compilation),
|
AlbumField::SecondaryType(AlbumSecondaryType::Compilation),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Soundtrack),
|
AlbumField::SecondaryType(AlbumSecondaryType::Soundtrack),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::Spokenword),
|
AlbumField::SecondaryType(AlbumSecondaryType::Spokenword),
|
||||||
@ -92,7 +92,7 @@ fn default_filter() -> CollectionFilter {
|
|||||||
AlbumField::SecondaryType(AlbumSecondaryType::Demo),
|
AlbumField::SecondaryType(AlbumSecondaryType::Demo),
|
||||||
AlbumField::SecondaryType(AlbumSecondaryType::FieldRecording),
|
AlbumField::SecondaryType(AlbumSecondaryType::FieldRecording),
|
||||||
AlbumField::Ownership(AlbumOwnership::None),
|
AlbumField::Ownership(AlbumOwnership::None),
|
||||||
]],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user