Fixed: Frontend error sorting book index by status

Fixes #1426
This commit is contained in:
ta264
2021-12-23 21:41:43 +00:00
parent 29c7404185
commit 6d8adec7dc
2 changed files with 6 additions and 15 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ export const sortPredicates = {
status: function(item) { status: function(item) {
let result = 0; let result = 0;
const hasBookFile = !!item.statistics.bookFileCount; const hasBookFile = !!item.statistics?.bookFileCount;
const isAvailable = Date.parse(item.releaseDate) < new Date(); const isAvailable = Date.parse(item.releaseDate) < new Date();
if (isAvailable) { if (isAvailable) {
@@ -27,22 +27,12 @@ namespace NzbDrone.Core.AuthorStats
public List<BookStatistics> AuthorStatistics() public List<BookStatistics> AuthorStatistics()
{ {
var time = DateTime.UtcNow; return Query(Builder());
#pragma warning disable CS0472
return Query(Builder().OrWhere<Book>(x => x.ReleaseDate < time)
.OrWhere<BookFile>(x => x.Id != null));
#pragma warning restore
} }
public List<BookStatistics> AuthorStatistics(int authorId) public List<BookStatistics> AuthorStatistics(int authorId)
{ {
var time = DateTime.UtcNow; return Query(Builder().Where<Author>(x => x.Id == authorId));
#pragma warning disable CS0472
return Query(Builder().OrWhere<Book>(x => x.ReleaseDate < time)
.OrWhere<BookFile>(x => x.Id != null)
.Where<Author>(x => x.Id == authorId));
#pragma warning restore
} }
private List<BookStatistics> Query(SqlBuilder builder) private List<BookStatistics> Query(SqlBuilder builder)
@@ -61,13 +51,14 @@ namespace NzbDrone.Core.AuthorStats
SUM(COALESCE(BookFiles.Size, 0)) AS SizeOnDisk, SUM(COALESCE(BookFiles.Size, 0)) AS SizeOnDisk,
1 AS TotalBookCount, 1 AS TotalBookCount,
CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE 1 END AS AvailableBookCount, CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE 1 END AS AvailableBookCount,
CASE WHEN Books.Monitored = 1 OR BookFiles.Id IS NOT NULL THEN 1 ELSE 0 END AS BookCount, CASE WHEN (Books.Monitored = 1 AND (Books.ReleaseDate < @currentDate) OR Books.ReleaseDate IS NULL) OR BookFiles.Id IS NOT NULL THEN 1 ELSE 0 END AS BookCount,
CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE COUNT(BookFiles.Id) END AS BookFileCount") CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE COUNT(BookFiles.Id) END AS BookFileCount")
.Join<Edition, Book>((e, b) => e.BookId == b.Id) .Join<Edition, Book>((e, b) => e.BookId == b.Id)
.Join<Book, Author>((book, author) => book.AuthorMetadataId == author.AuthorMetadataId) .Join<Book, Author>((book, author) => book.AuthorMetadataId == author.AuthorMetadataId)
.LeftJoin<Edition, BookFile>((t, f) => t.Id == f.EditionId) .LeftJoin<Edition, BookFile>((t, f) => t.Id == f.EditionId)
.Where<Edition>(x => x.Monitored == true) .Where<Edition>(x => x.Monitored == true)
.GroupBy<Author>(x => x.Id) .GroupBy<Author>(x => x.Id)
.GroupBy<Book>(x => x.Id); .GroupBy<Book>(x => x.Id)
.AddParameters(new Dictionary<string, object> { { "currentDate", DateTime.UtcNow } });
} }
} }