Skip to content

Commit

Permalink
Merge pull request #12 from victor-david/filter-directory
Browse files Browse the repository at this point in the history
Merge filter-directory to main
  • Loading branch information
victor-david authored Feb 5, 2023
2 parents 1a4403f + 1907e45 commit cefca0c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/Panama/Core/Filter/TitleFilterEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private Predicate<DataRow> GetEvaluator(TitleRowFilterType filterType)
{
TitleRowFilterType.Id => EvaluateId,
TitleRowFilterType.Text => EvaluateText,
TitleRowFilterType.Directory => EvaluateDirectory,
TitleRowFilterType.Ready => EvaluateReady,
TitleRowFilterType.Flagged => EvaluateFlagged,
TitleRowFilterType.CurrentlySubmitted => EvaluateCurrentlySubmitted,
Expand All @@ -54,6 +55,7 @@ private bool GetIsEvaluatorActive()
{
return filterType switch
{
TitleRowFilterType.Directory => !string.IsNullOrWhiteSpace(Filter.Directory),
TitleRowFilterType.WordCount => Filter.WordCount != 0,
TitleRowFilterType.Tag => Filter.Tags.Count > 0,
_ => base.IsActive
Expand All @@ -73,6 +75,13 @@ private bool EvaluateText(DataRow item)
item[Columns.Title].ToString().Contains(Filter.Text, StringComparison.InvariantCultureIgnoreCase);
}

private bool EvaluateDirectory(DataRow item)
{
return
string.IsNullOrWhiteSpace(Filter.Directory) ||
item[Columns.Calculated.LastestVersionPath].ToString().Contains(Filter.Directory, StringComparison.InvariantCultureIgnoreCase);
}

private bool EvaluateReady(DataRow item)
{
return State == ThreeWayState.Neutral || EvaluateBoolColumn(item[Columns.Ready]);
Expand Down
19 changes: 19 additions & 0 deletions src/Panama/Core/Filter/TitleRowFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TitleRowFilter : RowFilter
private ThreeWayState everSubmittedState;
private ThreeWayState publishedState;
private ThreeWayState selfPublishedState;
private string directory;
private int wordCount;
private bool isTagFilterAny;
private bool isTagFilterAll;
Expand All @@ -35,6 +36,21 @@ public class TitleRowFilter : RowFilter
/// <inheritdoc/>
public override bool IsAnyFilterActive => base.IsAnyFilterActive || IsAnyEvaluatorActive();

/// <summary>
/// Gets or sets a partial or whole directory name
/// </summary>
public string Directory
{
get => directory;
set
{
if (SetProperty(ref directory, value))
{
ApplyFilter();
}
}
}

/// <summary>
/// Gets or sets the filter state for whether a title is flagged as ready
/// </summary>
Expand Down Expand Up @@ -184,6 +200,7 @@ public TitleRowFilter()
{
{ TitleRowFilterType.Id, new TitleFilterEvaluator(this, TitleRowFilterType.Id) },
{ TitleRowFilterType.Text, new TitleFilterEvaluator(this, TitleRowFilterType.Text) },
{ TitleRowFilterType.Directory, new TitleFilterEvaluator(this, TitleRowFilterType.Directory) },
{ TitleRowFilterType.Ready, new TitleFilterEvaluator(this, TitleRowFilterType.Ready) },
{ TitleRowFilterType.Flagged, new TitleFilterEvaluator(this, TitleRowFilterType.Flagged) },
{ TitleRowFilterType.CurrentlySubmitted, new TitleFilterEvaluator(this, TitleRowFilterType.CurrentlySubmitted) },
Expand All @@ -210,6 +227,7 @@ public override void ClearAll()
IncreaseSuspendLevel();
base.ClearAll();
ClearAllPropertyState();
Directory = null;
WordCount = 0;
Tags.Clear();
IsTagFilterAny = true;
Expand Down Expand Up @@ -262,6 +280,7 @@ public override bool OnDataRowFilter(DataRow item)
return
filterEvaluators[TitleRowFilterType.Id].Evaluate(item) &&
filterEvaluators[TitleRowFilterType.Text].Evaluate(item) &&
filterEvaluators[TitleRowFilterType.Directory].Evaluate(item) &&
filterEvaluators[TitleRowFilterType.Ready].Evaluate(item) &&
filterEvaluators[TitleRowFilterType.Flagged].Evaluate(item) &&
filterEvaluators[TitleRowFilterType.CurrentlySubmitted].Evaluate(item) &&
Expand Down
4 changes: 4 additions & 0 deletions src/Panama/Core/Filter/TitleRowFilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public enum TitleRowFilterType
/// </summary>
Text,
/// <summary>
/// Filter according to the directory where a title is stored
/// </summary>
Directory,
/// <summary>
/// Title is flagged as ready
/// </summary>
Ready,
Expand Down
20 changes: 15 additions & 5 deletions src/Panama/View/Title/TitleCustomFilter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
tk:Property.RowHeights="Auto,Auto,Auto,Auto,*"
Style="{StaticResource DataEntryPanelStyle}">

<!-- Title -->
<StackPanel Grid.ColumnSpan="2">
<TextBlock Text="{x:Static r:Strings.TextTitle}"/>
<TextBox
Expand All @@ -41,20 +42,29 @@
Delay=500}"/>
</StackPanel>

<StackPanel Grid.Row="1">
<!-- Directory -->
<StackPanel Grid.Row="1" Grid.ColumnSpan="2">
<TextBlock Text="Path"/>
<TextBox
Text="{Binding Filters.Directory,
UpdateSourceTrigger=PropertyChanged,
Delay=500}"/>
</StackPanel>

<!-- Flags -->
<StackPanel Grid.Row="2">
<tk:ThreeWay Header="{x:Static r:Strings.TextReady}" State="{Binding Filters.ReadyState}"/>
<tk:ThreeWay Header="{x:Static r:Strings.TextFlagged}" State="{Binding Filters.FlaggedState}"/>
<tk:ThreeWay Header="{x:Static r:Strings.TextPublished}" State="{Binding Filters.PublishedState}"/>
</StackPanel>

<StackPanel Grid.Row="1" Grid.Column="1">
<StackPanel Grid.Row="2" Grid.Column="1">
<tk:ThreeWay Header="{x:Static r:Strings.TextSubmitted}" State="{Binding Filters.CurrentlySubmittedState}"/>
<tk:ThreeWay Header="{x:Static r:Strings.TextEverSubmitted}" State="{Binding Filters.EverSubmittedState}"/>
<tk:ThreeWay Header="{x:Static r:Strings.TextSelfPublished}" State="{Binding Filters.SelfPublishedState}"/>
</StackPanel>

<StackPanel Grid.Row="2" Grid.ColumnSpan="2">

<StackPanel Grid.Row="3" Grid.ColumnSpan="2">
<TextBlock>
<Run Text="Word Count"/>
<Run
Expand All @@ -72,7 +82,7 @@
<Grid
Grid.Row="4" Grid.ColumnSpan="2"
tk:Property.RowHeights="Auto,*,Auto,Auto"
tk:Property.ColumnWidths="232,232">
tk:Property.ColumnWidths="340,340">

<conl:TitledSeparator
Title="{x:Static r:Strings.TextAssignedToFilter}"/>
Expand Down

0 comments on commit cefca0c

Please sign in to comment.