Skip to content

Commit

Permalink
Add Empty filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Sep 12, 2024
1 parent 1e9bfa4 commit 3c1ecb1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Models/CodexProperties/CodexProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void UpdateSources()
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)),
_ => null //could occur when a new preference file with new props is loaded into an older version of compass
};

Expand Down
20 changes: 20 additions & 0 deletions src/Models/Filters/EmptyFilter.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 EmptyFilter : Filter
{
public EmptyFilter(CodexProperty filterValue) : base(FilterType.Empty, filterValue)
{
}

private CodexProperty prop => (CodexProperty)FilterValue!;

public override Color BackgroundColor => Colors.LightSlateGray;

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

public override bool Apply(Codex codex) => prop.IsEmpty(codex);
}
}
3 changes: 2 additions & 1 deletion src/Models/Filters/FilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum FilterType
FileExtension,
HasBrokenPath,
HasISBN,
Domain
Domain,
Empty
}
}
27 changes: 27 additions & 0 deletions src/ViewModels/FilterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.Input;
using COMPASS.Models;
using COMPASS.Models.CodexProperties;
using COMPASS.Models.Filters;
using COMPASS.Services;
using COMPASS.Tools;
Expand Down Expand Up @@ -164,6 +165,32 @@ public ObservableCollection<string> DomainList
set => SetProperty(ref _domainList, value);
}

public CodexProperty SelectedEmptyProperty
{
set
{
if (value is not null)
{
Filter emptyFilter = new EmptyFilter(value);
AddFilter(emptyFilter, 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.Description))!,
CodexProperty.GetInstance(nameof(Codex.ReleaseDate))!,
CodexProperty.GetInstance(nameof(Codex.PageCount))!,
CodexProperty.GetInstance(nameof(Codex.Version))!,
CodexProperty.GetInstance(nameof(Codex.Tags))!,
CodexProperty.GetInstance(nameof(Codex.CoverArt))!,
CodexProperty.GetInstance(nameof(Codex.Rating))!,
};

//Selected Start and Stop Release Dates
private DateTime? _startReleaseDate;
private DateTime? _stopReleaseDate;
Expand Down
20 changes: 15 additions & 5 deletions src/Views/LeftDockView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,31 @@
<TextBlock Text="Minimum Rating:" Margin="0,10,0,0"/>
<materialDesign:RatingBar Value="{Binding MinRating, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
IsPreviewValueEnabled="True" Margin="5 3"/>

<TextBlock Text="File Type:" Margin="0,5"/>
<Grid>
<TextBlock Text="-- Select File Type --" HorizontalAlignment="Center" Margin="0,0,20,0"/>
<ComboBox ItemsSource="{Binding FileTypeList}" FontSize="15"
SelectedValue="{Binding SelectedFileType, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" Style="{StaticResource ContentLess}"/>
<ComboBox ItemsSource="{Binding FileTypeList}" FontSize="15" Style="{StaticResource ContentLess}"
SelectedValue="{Binding SelectedFileType, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" />
</Grid>

<TextBlock Text="Source Website:" Margin="0,5"/>
<Grid>
<TextBlock Text="-- Select Website --" HorizontalAlignment="Center" Margin="0,0,20,0"/>
<ComboBox ItemsSource="{Binding DomainList}" FontSize="15"
SelectedValue="{Binding SelectedDomain, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" Style="{StaticResource ContentLess}"/>
<ComboBox ItemsSource="{Binding DomainList}" FontSize="15" Style="{StaticResource ContentLess}"
SelectedValue="{Binding SelectedDomain, Mode=OneWayToSource, UpdateSourceTrigger=LostFocus}" />
</Grid>

<TextBlock Text="No 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}" />
</Grid>
</StackPanel>
<Button Content="Clear All" Grid.Row="4" Margin="10" Command="{Binding ClearFiltersCommand}"
Style="{StaticResource IconTextButton}" tools:AP.IconKind="FilterRemove" Background="Red"/>
Style="{StaticResource IconTextButton}" tools:AP.IconKind="FilterRemove" Background="Red"/>
</Grid>
</ScrollViewer>
</ContentControl>
Expand Down

0 comments on commit 3c1ecb1

Please sign in to comment.