Skip to content

Commit

Permalink
Add ability to clear individual filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Webreaper committed Oct 31, 2023
1 parent 6715ab6 commit 9dad051
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 34 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions Damselfly.Core.DbModels/Damselfly.Core.DbModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@

<ItemGroup>
<Folder Include="Authentication\" />
<Folder Include="Interfaces\" />
<Folder Include="Utils\" />
<Folder Include="Models\" />
<Folder Include="Models\SideCars\" />
<Folder Include="Images\" />
<Folder Include="Models\API Models\" />
<Folder Include="Models\ConfigSettings\" />
<Folder Include="Models\TransformationModels\" />
</ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions Damselfly.Core.DbModels/Interfaces/ISearchHint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Damselfly.Core.ScopedServices.Interfaces;

public interface ISearchHint
{
Action Clear { get; set; }
string Description { get; set; }
}
2 changes: 2 additions & 0 deletions Damselfly.Core.DbModels/Interfaces/ISearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface ISearchService
OrientationType? Orientation { get; set; }

string SearchBreadcrumbs { get; }
IEnumerable<ISearchHint> SearchHints { get; }

void SetDateRange(DateTime? min, DateTime? max);

void Refresh();
Expand Down
10 changes: 10 additions & 0 deletions Damselfly.Core.DbModels/Models/API Models/SearchHint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using Damselfly.Core.ScopedServices.Interfaces;

namespace Damselfly.Core.DbModels.Models.API_Models;

public class SearchHint : ISearchHint
{
public Action Clear { get; set; }
public string Description { get; set; }
}
100 changes: 70 additions & 30 deletions Damselfly.Core.ScopedServices/BaseSearchService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using System.Globalization;
using Damselfly.Core.Constants;
using Damselfly.Core.DbModels;
using Damselfly.Core.DbModels.Models.API_Models;
using Damselfly.Core.Models;
using Damselfly.Core.ScopedServices.Interfaces;
using Damselfly.Core.Utils;
Expand Down Expand Up @@ -309,33 +310,58 @@ public OrientationType? Orientation

public SearchQuery Query { get; } = new();

public string SearchBreadcrumbs
public IEnumerable<ISearchHint> SearchHints
{
get
{
var hints = new List<string>();
var hints = new List<ISearchHint>();

if ( !string.IsNullOrEmpty(SearchText) )
hints.Add($"Text: {SearchText}");

if ( Folder != null )
hints.Add($"Folder: {Folder.Name}");
if( !string.IsNullOrEmpty( SearchText) )
{
var text = (TagsOnly ? "Text (tags only): " : "Text: ") + SearchText;
hints.Add( new SearchHint{ Description = text, Clear = () => SearchText = String.Empty });
}

if ( Person != null )
hints.Add($"Person: {Person.Name}");
if( Folder != null )
hints.Add( new SearchHint { Description = $"Folder: {Folder.Name}", Clear = () => Folder = null });

Check warning on line 326 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Cannot convert null literal to non-nullable reference type.

Check warning on line 326 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

if( Person != null )
hints.Add( new SearchHint { Description = $"Person: {Person.Name}", Clear = () => Person = null });

Check warning on line 329 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Cannot convert null literal to non-nullable reference type.

Check warning on line 329 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

if ( MinRating != null )
hints.Add($"Rating: at least {MinRating} stars");
if( Tag != null )
hints.Add( new SearchHint { Description = $"Tag: {Tag.Keyword}", Clear = () => Tag = null });

Check warning on line 332 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (javascript)

Cannot convert null literal to non-nullable reference type.

Check warning on line 332 in Damselfly.Core.ScopedServices/BaseSearchService.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

if( MinRating != null )
hints.Add( new SearchHint { Description = $"Rating: at least {MinRating} stars", Clear = () => MinRating = null });

if (SimilarToId != null)
{
var image = _imageCache.GetCachedImage(SimilarToId.Value).Result;
if( image is not null )
hints.Add($"Looks Like: {image.FileName}");
hints.Add( new SearchHint { Description = $"Looks Like: {image.FileName}", Clear = () => SimilarToId = null } );
}

string dateString = string.Empty;
if( MaxSizeKB.HasValue && MinSizeKB.HasValue )
{
dateString = $"Between {MinSizeKB.Value}KB and {MaxSizeKB.Value}KB";
}
else
{
if( MaxSizeKB.HasValue )
dateString = $"Less than: {MaxSizeKB.Value}KB";

if ( Tag != null )
hints.Add($"Tag: {Tag.Keyword}");
if( MinSizeKB.HasValue )
dateString = $"At least: {MinSizeKB.Value}KB";
}

if( ! string.IsNullOrEmpty(dateString) )
hints.Add( new SearchHint { Description = dateString, Clear = () =>
{
MinSizeKB = null;
MaxSizeKB = null;
}
} );

var dateRange = string.Empty;
if ( MinDate.HasValue )
Expand All @@ -350,39 +376,53 @@ public string SearchBreadcrumbs
}

if ( !string.IsNullOrEmpty(dateRange) )
hints.Add($"Date: {dateRange}");
hints.Add( new SearchHint {Description = $"Date: {dateRange}", Clear = () =>
{
MinDate = null;
MaxDate = null; }
});

if ( UntaggedImages )
hints.Add("Untagged images");

if (Month.HasValue)
hints.Add( new SearchHint {Description = "Untagged Images", Clear = () => UntaggedImages = false });

if( !IncludeChildFolders )
hints.Add( new SearchHint {Description = "Exclude child folders", Clear = () => IncludeChildFolders = true });

if( Month.HasValue )
{
string monthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Month.Value);
hints.Add($"During {monthName}");
hints.Add( new SearchHint { Description = $"During: {monthName}", Clear = () => Month = null } );
}

if ( FaceSearch.HasValue )
hints.Add($"{FaceSearch.Humanize()}");

if ( Orientation.HasValue )
hints.Add($"{Orientation.Humanize()}");

if ( CameraId > 0 )
{
var cam = _service.Cameras.FirstOrDefault(x => x.CameraId == CameraId);
if ( cam != null )
hints.Add($"Camera: {cam.Model}");
hints.Add( new SearchHint{ Description = $"Camera: {cam.Model}", Clear = () => CameraId = null});
}

if ( LensId > 0 )
{
var lens = _service.Lenses.FirstOrDefault(x => x.LensId == LensId);
if ( lens != null )
hints.Add($"Lens: {lens.Model}");
hints.Add( new SearchHint{ Description = $"Lens: {lens.Model}", Clear = () => LensId = null});
}

if ( FaceSearch.HasValue )
hints.Add( new SearchHint{ Description = FaceSearch.Humanize(), Clear = () => FaceSearch = null});

if( !IncludeChildFolders )
hints.Add( $"Exclude child folders" );
if ( Orientation.HasValue )
hints.Add( new SearchHint{ Description = Orientation.Humanize(), Clear = () => Orientation = null});

return hints;
}
}

public string SearchBreadcrumbs
{
get
{
var hints = new List<string>();

if( hints.Any() )
return string.Join(", ", hints);
Expand Down
19 changes: 18 additions & 1 deletion Damselfly.Web.Client/Shared/SearchBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,24 @@
<button class="btn btn-primary damselfly-searchtools" title="Tag Management" @onclick="@TagManagement">
<i class="fas fa-tags"/>
</button>
<label class="damselfly-browsetoollabel" title="Current Search Parameters">@searchService.SearchBreadcrumbs</label>
@if( searchService.SearchHints.Any() )
{
<div class="search-hints">
<MudChipSet>
@foreach( var hint in searchService.SearchHints )
{
<MudChip OnClose="@hint.Clear" Size="Size.Small">
@hint.Description
</MudChip>
}
</MudChipSet>
</div>
}
else
{
<label class="damselfly-browsetoollabel" >No filter.</label>
}

</div>

<div class="damselfly-browsetools">
Expand Down
4 changes: 4 additions & 0 deletions Damselfly.Web.Client/wwwroot/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ html, body {
font-weight: bold;
}

.search-hints {
max-width: 700px;
}

.imagegrid-loader {
width: 24px;
height: 24px;
Expand Down
2 changes: 1 addition & 1 deletion Damselfly.Web.Client/wwwroot/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const CACHE_VERSION='4.1.0-20231031073255'
const CACHE_VERSION='4.1.0-20231031103234'

0 comments on commit 9dad051

Please sign in to comment.