From 565c84c4ab4f693882677b958c61d35b3c794b25 Mon Sep 17 00:00:00 2001 From: MBucari Date: Fri, 17 Mar 2023 21:59:37 -0600 Subject: [PATCH] Add series # to grid display (#529) --- Source/DataLayer/EfClasses/SeriesBook.cs | 5 +++-- Source/DataLayer/EntityExtensions.cs | 13 +++++++++---- .../LibationUiBase/GridView/GridEntry[TStatus].cs | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/DataLayer/EfClasses/SeriesBook.cs b/Source/DataLayer/EfClasses/SeriesBook.cs index 825d2515..fa430a65 100644 --- a/Source/DataLayer/EfClasses/SeriesBook.cs +++ b/Source/DataLayer/EfClasses/SeriesBook.cs @@ -8,7 +8,7 @@ namespace DataLayer internal int BookId { get; private set; } public string Order { get; private set; } - public float Index => StringLib.ExtractFirstNumber(Order); + public float Index { get; } public Series Series { get; private set; } public Book Book { get; private set; } @@ -22,7 +22,8 @@ namespace DataLayer Series = series; Book = book; Order = order; - } + Index = StringLib.ExtractFirstNumber(Order); + } public void UpdateOrder(string order) { diff --git a/Source/DataLayer/EntityExtensions.cs b/Source/DataLayer/EntityExtensions.cs index acf0b866..d5b264cf 100644 --- a/Source/DataLayer/EntityExtensions.cs +++ b/Source/DataLayer/EntityExtensions.cs @@ -18,9 +18,9 @@ namespace DataLayer /// True if exists and IsLiberated. Else false public static bool PDF_Exists(this Book book) => book.UserDefinedItem.PdfStatus == LiberatedStatus.Liberated; - public static string SeriesSortable(this Book book) => Formatters.GetSortName(book.SeriesNames()); + public static string SeriesSortable(this Book book) => Formatters.GetSortName(book.SeriesNames(true)); public static bool HasPdf(this Book book) => book.Supplements.Any(); - public static string SeriesNames(this Book book) + public static string SeriesNames(this Book book, bool includeIndex = false) { if (book.SeriesLink is null) return ""; @@ -28,7 +28,7 @@ namespace DataLayer // first: alphabetical by name var withNames = book.SeriesLink .Where(s => !string.IsNullOrWhiteSpace(s.Series.Name)) - .Select(s => s.Series.Name) + .Select(getSeriesNameString) .OrderBy(a => a) .ToList(); // then un-named are alpha by series id @@ -40,7 +40,12 @@ namespace DataLayer var all = withNames.Union(nullNames).ToList(); return string.Join(", ", all); - } + + string getSeriesNameString(SeriesBook sb) + => includeIndex && !string.IsNullOrWhiteSpace(sb.Order) && sb.Order != "-1" + ? $"{sb.Series.Name} (#{sb.Order})" + : sb.Series.Name; + } public static string[] CategoriesNames(this Book book) => book.Category is null ? new string[0] : book.Category.ParentCategory is null ? new[] { book.Category.Name } diff --git a/Source/LibationUiBase/GridView/GridEntry[TStatus].cs b/Source/LibationUiBase/GridView/GridEntry[TStatus].cs index 2e5c08b0..4aa8fdde 100644 --- a/Source/LibationUiBase/GridView/GridEntry[TStatus].cs +++ b/Source/LibationUiBase/GridView/GridEntry[TStatus].cs @@ -104,7 +104,7 @@ namespace LibationUiBase.GridView Liberate.Expanded = expanded; Title = Book.Title; - Series = Book.SeriesNames(); + Series = Book.SeriesNames(includeIndex: true); Length = GetBookLengthString(); //Ratings are changed using Update(), which is a problem for Avalonia data bindings because //the reference doesn't change. Clone the rating so that it updates within Avalonia properly.