Skip to content

Commit

Permalink
Flip empty filter, remove has ISBN
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Sep 18, 2024
1 parent 4973526 commit 6c79745
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 59 deletions.
23 changes: 12 additions & 11 deletions src/Models/CodexProperties/CodexProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ public void UpdateSources()

public static CodexProperty? GetInstance(string propName) => propName switch
{
nameof(Codex.Title) => new StringProperty(nameof(Codex.Title)),
nameof(Codex.Authors) => new EnumerableProperty<string>(nameof(Codex.Authors)),
nameof(Codex.Publisher) => new StringProperty(nameof(Codex.Publisher)),
nameof(Codex.Version) => new StringProperty(nameof(Codex.Version)),
nameof(Codex.PageCount) => new NumberProperty<int>(nameof(Codex.PageCount), label: "Pagecount"),
nameof(Codex.Tags) => new TagsProperty(nameof(Codex.Tags)),
nameof(Codex.Description) => new StringProperty(nameof(Codex.Description)),
nameof(Codex.ReleaseDate) => new DateTimeProperty(nameof(Codex.ReleaseDate), label: "Release Date"),
nameof(Codex.CoverArt) => new CoverArtProperty(nameof(Codex.CoverArt), label: "Cover Art"),
nameof(Codex.Rating) => new NumberProperty<int>(nameof(Codex.Rating)),
nameof(Codex.Title) => new StringProperty(propName),
nameof(Codex.Authors) => new EnumerableProperty<string>(propName),
nameof(Codex.Publisher) => new StringProperty(propName),
nameof(Codex.Version) => new StringProperty(propName),
nameof(Codex.PageCount) => new NumberProperty<int>(propName, label: "Pagecount"),
nameof(Codex.Tags) => new TagsProperty(propName),
nameof(Codex.Description) => new StringProperty(propName),
nameof(Codex.ReleaseDate) => new DateTimeProperty(propName, label: "Release Date"),
nameof(Codex.CoverArt) => new CoverArtProperty(propName, label: "Cover Art"),
nameof(Codex.Rating) => new NumberProperty<int>(propName),
nameof(Codex.Sources.ISBN) => new StringProperty($"{nameof(Codex.Sources)}.{nameof(Codex.Sources.ISBN)}", label: "ISBN"),
_ => null //could occur when a new preference file with new props is loaded into an older version of compass
};

Expand Down Expand Up @@ -189,7 +190,7 @@ public CodexProperty(string propName, string? label = null) :

public virtual T? GetProp(IHasCodexMetadata codex)
{
object? value = codex.GetPropertyValue(Name);
object? value = codex.GetDeepPropertyValue(Name);
return value == null ? default : (T)value;
}

Expand Down
20 changes: 0 additions & 20 deletions src/Models/Filters/EmptyFilter.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Models/Filters/FilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public enum FilterType
Favorite,
FileExtension,
HasBrokenPath,
HasISBN,
Domain,
Empty
}
Expand Down
15 changes: 0 additions & 15 deletions src/Models/Filters/HasISBNFilter.cs

This file was deleted.

20 changes: 20 additions & 0 deletions src/Models/Filters/NotEmptyFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using COMPASS.Models.CodexProperties;
using System.Windows.Media;

namespace COMPASS.Models.Filters
{
internal class NotEmptyFilter : Filter
{
public NotEmptyFilter(CodexProperty filterValue) : base(FilterType.Empty, filterValue)
{
}

private CodexProperty prop => (CodexProperty)FilterValue!;

public override Color BackgroundColor => Colors.LightSlateGray;

public override string Content => $"Has value for '{prop.Label}'";

public override bool Apply(Codex codex) => !prop.IsEmpty(codex);
}
}
20 changes: 10 additions & 10 deletions src/ViewModels/FilterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public string SearchTerm
new OfflineSourceFilter(),
new OnlineSourceFilter(),
new PhysicalSourceFilter(),
new HasISBNFilter(),
new FavoriteFilter(),
};

Expand Down Expand Up @@ -165,30 +164,31 @@ public ObservableCollection<string> DomainList
set => SetProperty(ref _domainList, value);
}

public CodexProperty SelectedEmptyProperty
public CodexProperty SelectedNotEmptyProperty
{
set
{
if (value is not null)
{
Filter emptyFilter = new EmptyFilter(value);
AddFilter(emptyFilter, Include);
Filter notEmptyFilter = new NotEmptyFilter(value);
AddFilter(notEmptyFilter, Include);
}
}
}

public List<CodexProperty> PossibleEmptyProperties { get; } = new()
{
CodexProperty.GetInstance(nameof(Codex.Title))!,
CodexProperty.GetInstance(nameof(Codex.Authors))!,
CodexProperty.GetInstance(nameof(Codex.Publisher))!,
CodexProperty.GetInstance(nameof(Codex.CoverArt))!,
CodexProperty.GetInstance(nameof(Codex.Description))!,
CodexProperty.GetInstance(nameof(Codex.ReleaseDate))!,
CodexProperty.GetInstance(nameof(Codex.Sources.ISBN))!,
CodexProperty.GetInstance(nameof(Codex.PageCount))!,
CodexProperty.GetInstance(nameof(Codex.Version))!,
CodexProperty.GetInstance(nameof(Codex.Tags))!,
CodexProperty.GetInstance(nameof(Codex.CoverArt))!,
CodexProperty.GetInstance(nameof(Codex.Publisher))!,
CodexProperty.GetInstance(nameof(Codex.Rating))!,
CodexProperty.GetInstance(nameof(Codex.ReleaseDate))!,
CodexProperty.GetInstance(nameof(Codex.Tags))!,
CodexProperty.GetInstance(nameof(Codex.Title))!,
CodexProperty.GetInstance(nameof(Codex.Version))!,
};

//Selected Start and Stop Release Dates
Expand Down
4 changes: 2 additions & 2 deletions src/Views/LeftDockView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,12 @@
SelectedValue="{Binding SelectedDomain, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" />
</Grid>

<TextBlock Text="No value for:" Margin="0,5"/>
<TextBlock Text="Has a value for:" Margin="0,5"/>
<Grid>
<TextBlock Text="-- Select Property --" HorizontalAlignment="Center" Margin="0,0,20,0"/>
<ComboBox ItemsSource="{Binding PossibleEmptyProperties}" DisplayMemberPath="Label"
FontSize="15" Style="{StaticResource ContentLess}"
SelectedValue="{Binding SelectedEmptyProperty, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" />
SelectedValue="{Binding SelectedNotEmptyProperty, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" />
</Grid>
</StackPanel>
<Button Content="Clear All" Grid.Row="4" Margin="10" Command="{Binding ClearFiltersCommand}"
Expand Down

0 comments on commit 6c79745

Please sign in to comment.