From 58856c0d709092129790af16dcf29e160b243aa1 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Wed, 28 Jul 2021 14:11:49 -0500 Subject: [PATCH] Filtering Bugs (#447) # Fixed - Fixed: Fixed an issue with filtering, after applying a filter, the cards on screen did not update with the correct information - Fixed: Pagination is now slighlty smaller (only 8 pages) as on mobile, it was cutting off screen. # Changed - Changed: During library scan and series updates, Series names for Epubs will now trim excess white space =============================================== * Fixed issue where some formats could get returned with another format filter. * Filtering was not properly flushing DOM on filter change, updated trackbyidentity to account for filter * One more fix for the filtering bug * Made pagination UI slightly smaller to better fit on mobile phones. Trim() series names for Epub files and Trim() on series update for appropriate fields. * Removed a no longer needed animation. --- API/Controllers/SeriesController.cs | 8 +++--- API/Data/SeriesRepository.cs | 23 +++++++++------ API/Extensions/FilterDtoExtensions.cs | 28 +++++++++++++++++++ API/Services/BookService.cs | 8 +++--- .../card-detail-layout.component.html | 10 ++++--- .../card-detail-layout.component.ts | 2 +- UI/Web/src/styles.scss | 11 +++++--- 7 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 API/Extensions/FilterDtoExtensions.cs diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs index 09d4fd206..b739b62bd 100644 --- a/API/Controllers/SeriesController.cs +++ b/API/Controllers/SeriesController.cs @@ -133,10 +133,10 @@ namespace API.Controllers { return BadRequest("A series already exists in this library with this name. Series Names must be unique to a library."); } - series.Name = updateSeries.Name; - series.LocalizedName = updateSeries.LocalizedName; - series.SortName = updateSeries.SortName; - series.Summary = updateSeries.Summary; + series.Name = updateSeries.Name.Trim(); + series.LocalizedName = updateSeries.LocalizedName.Trim(); + series.SortName = updateSeries.SortName.Trim(); + series.Summary = updateSeries.Summary.Trim(); _unitOfWork.SeriesRepository.Update(series); diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs index 04d281870..afaf17f5b 100644 --- a/API/Data/SeriesRepository.cs +++ b/API/Data/SeriesRepository.cs @@ -1,10 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using API.Comparators; using API.DTOs; using API.DTOs.Filtering; using API.Entities; +using API.Entities.Enums; using API.Extensions; using API.Helpers; using API.Interfaces; @@ -78,8 +80,9 @@ namespace API.Data public async Task> GetSeriesDtoForLibraryIdAsync(int libraryId, int userId, UserParams userParams, FilterDto filter) { + var formats = filter.GetSqlFilter(); var query = _context.Series - .Where(s => s.LibraryId == libraryId && (filter.MangaFormat == null || s.Format == filter.MangaFormat)) + .Where(s => s.LibraryId == libraryId && formats.Contains(s.Format)) .OrderBy(s => s.SortName) .ProjectTo(_mapper.ConfigurationProvider) .AsNoTracking(); @@ -307,6 +310,8 @@ namespace API.Data /// public async Task> GetRecentlyAdded(int libraryId, int userId, UserParams userParams, FilterDto filter) { + var formats = filter.GetSqlFilter(); + if (libraryId == 0) { var userLibraries = _context.Library @@ -317,7 +322,7 @@ namespace API.Data .ToList(); var allQuery = _context.Series - .Where(s => userLibraries.Contains(s.LibraryId) && (filter.MangaFormat == null || s.Format == filter.MangaFormat)) + .Where(s => userLibraries.Contains(s.LibraryId) && formats.Contains(s.Format)) .AsNoTracking() .OrderByDescending(s => s.Created) .ProjectTo(_mapper.ConfigurationProvider) @@ -327,7 +332,7 @@ namespace API.Data } var query = _context.Series - .Where(s => s.LibraryId == libraryId && (filter.MangaFormat == null || s.Format == filter.MangaFormat)) + .Where(s => s.LibraryId == libraryId && formats.Contains(s.Format)) .AsNoTracking() .OrderByDescending(s => s.Created) .ProjectTo(_mapper.ConfigurationProvider) @@ -346,9 +351,9 @@ namespace API.Data /// public async Task> GetInProgress(int userId, int libraryId, UserParams userParams, FilterDto filter) { - + var formats = filter.GetSqlFilter(); var series = _context.Series - .Where(s => filter.MangaFormat == null || s.Format == filter.MangaFormat) + .Where(s => formats.Contains(s.Format)) .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new { Series = s, @@ -367,14 +372,16 @@ namespace API.Data series = series.Where(s => s.AppUserId == userId && s.PagesRead > 0 && s.PagesRead < s.Series.Pages - && userLibraries.Contains(s.Series.LibraryId)); + && userLibraries.Contains(s.Series.LibraryId) + && formats.Contains(s.Series.Format)); } else { series = series.Where(s => s.AppUserId == userId && s.PagesRead > 0 && s.PagesRead < s.Series.Pages - && s.Series.LibraryId == libraryId); + && s.Series.LibraryId == libraryId + && formats.Contains(s.Series.Format)); } var retSeries = series diff --git a/API/Extensions/FilterDtoExtensions.cs b/API/Extensions/FilterDtoExtensions.cs new file mode 100644 index 000000000..1b6689d49 --- /dev/null +++ b/API/Extensions/FilterDtoExtensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using API.DTOs.Filtering; +using API.Entities.Enums; + +namespace API.Extensions +{ + public static class FilterDtoExtensions + { + private static IList _allFormats = Enum.GetValues(); + + public static IList GetSqlFilter(this FilterDto filter) + { + var format = filter.MangaFormat; + if (format != null) + { + return new List() + { + (MangaFormat) format + }; + } + else + { + return _allFormats; + } + } + } +} diff --git a/API/Services/BookService.cs b/API/Services/BookService.cs index dbc3400dd..6c02b68db 100644 --- a/API/Services/BookService.cs +++ b/API/Services/BookService.cs @@ -323,10 +323,10 @@ namespace API.Services Edition = string.Empty, Format = MangaFormat.Epub, Filename = Path.GetFileName(filePath), - Title = specialName, + Title = specialName.Trim(), FullFilePath = filePath, IsSpecial = false, - Series = series, + Series = series.Trim(), Volumes = seriesIndex.Split(".")[0] }; } @@ -342,10 +342,10 @@ namespace API.Services Edition = string.Empty, Format = MangaFormat.Epub, Filename = Path.GetFileName(filePath), - Title = epubBook.Title, + Title = epubBook.Title.Trim(), FullFilePath = filePath, IsSpecial = false, - Series = epubBook.Title, + Series = epubBook.Title.Trim(), Volumes = Parser.Parser.DefaultVolume }; } diff --git a/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.html b/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.html index 0238a1a97..4520816d2 100644 --- a/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.html +++ b/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.html @@ -1,10 +1,12 @@
-
+

-  {{header}} {{pagination.totalItems}} +  {{header}}  + + {{pagination.totalItems}}

@@ -24,6 +26,7 @@
+
@@ -45,13 +48,12 @@
diff --git a/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.ts b/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.ts index 82c4a74e0..aab49eff7 100644 --- a/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.ts +++ b/UI/Web/src/app/shared/card-detail-layout/card-detail-layout.component.ts @@ -66,7 +66,7 @@ export class CardDetailLayoutComponent implements OnInit { constructor() { } ngOnInit(): void { - this.trackByIdentity = (index: number, item: any) => `${this.header}_${this.pagination?.currentPage}_${index}`; + this.trackByIdentity = (index: number, item: any) => `${this.header}_${this.pagination?.currentPage}_${this.filterForm.get('filter')?.value}_${item.id}_${index}`; } onPageChange(page: number) { diff --git a/UI/Web/src/styles.scss b/UI/Web/src/styles.scss index 270c9b8d1..1ce68054c 100644 --- a/UI/Web/src/styles.scss +++ b/UI/Web/src/styles.scss @@ -8,10 +8,7 @@ @import '~swiper/swiper.scss'; -// Custom animation for ng-lazyload-image -img.ng-lazyloaded { - //animation: fadein .5s; // I think it might look better without animation -} + @keyframes fadein { from { opacity: 0; } to { opacity: 1; } @@ -114,3 +111,9 @@ body { display: none; } } + +// Debug styles +.redlines * { + outline: 1px solid red; + outline-offset: -1px; +} \ No newline at end of file