mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds first draft of books media library view.
This commit is contained in:
1 parent
6fa154a2e7
commit
a4b1d0ff66
20 files changed
+1109
-17
No files matched your search
@@ -15,6 +15,8 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -26,6 +28,10 @@ namespace Lumina.DataAccess.Core.Repositories.Books;
|
||||
/// </summary>
|
||||
internal sealed class BookRepository : IBookRepository
|
||||
{
|
||||
private static readonly MethodInfo s_toLowerMethod = typeof(string).GetMethod(nameof(string.ToLower), Type.EmptyTypes)!;
|
||||
private static readonly MethodInfo s_startsWithMethod = typeof(string).GetMethod(nameof(string.StartsWith), [typeof(string)])!;
|
||||
private static readonly MethodInfo s_substringMethod = typeof(string).GetMethod(nameof(string.Substring), [typeof(int)])!;
|
||||
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
|
||||
/// <summary>
|
||||
@@ -126,7 +132,7 @@ internal sealed class BookRepository : IBookRepository
|
||||
booksQuery = booksQuery.Where(filterSpecification.ToExpression());
|
||||
|
||||
// apply sorting based on the specified sortBy and sortOrder parameters
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending);
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.IgnoreThePrefixForAlphaPicker);
|
||||
|
||||
// if no pagination was requested, return all the books of the library
|
||||
if (paginationData is null)
|
||||
@@ -255,7 +261,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// <param name="booksQuery">The query to sort.</param>
|
||||
/// <param name="sortBy">The field to sort by (case-insensitive).</param>
|
||||
/// <param name="sortOrder">The direction of the sorting.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder)
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder, bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
return sortBy?.ToLower() switch
|
||||
{
|
||||
@@ -269,11 +276,46 @@ internal sealed class BookRepository : IBookRepository
|
||||
? booksQuery.OrderByDescending(book => book.MetadataProvider)
|
||||
: booksQuery.OrderBy(book => book.MetadataProvider),
|
||||
_ => sortOrder == SortOrder.Descending
|
||||
? booksQuery.OrderByDescending(book => book.Title)
|
||||
: booksQuery.OrderBy(book => book.Title),
|
||||
? booksQuery.OrderByDescending(BuildTitleSortKey(ignoreThePrefixForAlphaPicker))
|
||||
: booksQuery.OrderBy(BuildTitleSortKey(ignoreThePrefixForAlphaPicker)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the expression that derives the title sort key of a book, matching the effective title used by the alpha filter:
|
||||
/// the title lowercased, falling back to the original title when the title is <see langword="null"/> or empty, and optionally
|
||||
/// stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
/// <returns>An expression that evaluates to the title sort key of a book.</returns>
|
||||
private static Expression<Func<BookEntity, string>> BuildTitleSortKey(bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
ParameterExpression book = Expression.Parameter(typeof(BookEntity), "book");
|
||||
|
||||
Expression titleProperty = Expression.Property(book, nameof(BookEntity.Title));
|
||||
|
||||
// the raw title: the title, unless it is null or empty, in which case the original title (or an empty string) is used
|
||||
BinaryExpression isTitleMissing = Expression.OrElse(
|
||||
Expression.Equal(titleProperty, Expression.Constant(null, typeof(string))),
|
||||
Expression.Equal(titleProperty, Expression.Constant(string.Empty)));
|
||||
Expression rawTitle = Expression.Condition(isTitleMissing,
|
||||
Expression.Coalesce(Expression.Property(book, nameof(BookEntity.OriginalTitle)), Expression.Constant(string.Empty)),
|
||||
titleProperty);
|
||||
|
||||
MethodCallExpression lowerTitle = Expression.Call(rawTitle, s_toLowerMethod);
|
||||
|
||||
// when ignoring the "The " prefix, strip a leading "the " from the lowercased title
|
||||
Expression effectiveTitle = lowerTitle;
|
||||
if (ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
MethodCallExpression startsWithThe = Expression.Call(lowerTitle, s_startsWithMethod, Expression.Constant("the "));
|
||||
MethodCallExpression strippedTitle = Expression.Call(lowerTitle, s_substringMethod, Expression.Constant(4));
|
||||
effectiveTitle = Expression.Condition(startsWithThe, strippedTitle, lowerTitle);
|
||||
}
|
||||
|
||||
return Expression.Lambda<Func<BookEntity, string>>(effectiveTitle, book);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a filter specification for querying books.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Lumina.Presentation.Web.Common.Enums.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the sort order.
|
||||
/// </summary>
|
||||
public enum SortOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Ascending order.
|
||||
/// </summary>
|
||||
Ascending,
|
||||
|
||||
/// <summary>
|
||||
/// Descending order.
|
||||
/// </summary>
|
||||
Descending
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the query parameters used to retrieve the lightweight details of the books of a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public class BookLibraryItemsQueryModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library whose books are retrieved.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the page of results to retrieve.
|
||||
/// </summary>
|
||||
public int? CurrentPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum number of books to retrieve per page.
|
||||
/// </summary>
|
||||
public int? PerPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the search term used to filter results.
|
||||
/// </summary>
|
||||
public string? SearchTerm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alpha key used to filter the results by the first character of their title, for the alpha picker.
|
||||
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
|
||||
/// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
public string? FilterAlphaKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the leading "The " prefix of a title is ignored when computing the alpha key, or not.
|
||||
/// </summary>
|
||||
public bool IgnoreThePrefixForAlphaPicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the field by which to sort the results.
|
||||
/// </summary>
|
||||
public string? SortBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the direction in which to sort the results.
|
||||
/// </summary>
|
||||
public SortOrder? SortOrder { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a lightweight book element, containing only the properties needed by the client for card-style navigation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class BookLiteModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the book.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the book.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release year of the book (re-release year, if available, or original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the cover of the book, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a paginated collection of lightweight book elements, together with pagination metadata.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}; Count: {Count}")]
|
||||
public class PaginatedBookLiteModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of lightweight book elements associated with this instance.
|
||||
/// </summary>
|
||||
public IReadOnlyList<BookLiteModel> Data { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current page number in a paginated collection.
|
||||
/// </summary>
|
||||
public int CurrentPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of items to include per page in paginated results.
|
||||
/// </summary>
|
||||
public int PerPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of elements available in the paginated result set.
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of pages based on elements available in the result set and per page.
|
||||
/// </summary>
|
||||
public int NumberOfPages { get; set; }
|
||||
}
|
||||
+74
-4
@@ -1,22 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.Library.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for books related operations.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("{culture}library/written-content-library/books-library/books")]
|
||||
[Route("{culture}/library/written-content-library/books-library/books")]
|
||||
public class BooksController : Controller
|
||||
{
|
||||
[HttpGet("")]
|
||||
public IActionResult Index()
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public BooksController(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml");
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for browsing the books of a media library.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are browsed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> Index(Guid? libraryId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (libraryId is null)
|
||||
return RedirectToAction("Index", "Home");
|
||||
|
||||
LibraryModel library = await _apiHttpClient.GetAsync<LibraryModel>($"libraries/{libraryId}", cancellationToken).ConfigureAwait(false);
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml", library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight details of the books of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The model containing the parameters used to retrieve the books.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("api-get-library-items")]
|
||||
public async Task<IActionResult> GetLibraryItems([FromQuery] BookLibraryItemsQueryModel query, CancellationToken cancellationToken = default)
|
||||
{
|
||||
PaginatedBookLiteModel response = await _apiHttpClient.GetAsync<PaginatedBookLiteModel>(BuildItemsEndpoint(query), cancellationToken).ConfigureAwait(false);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for a single book.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the book to display.</param>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult EditBook(Guid id)
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Item.cshtml");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the lightweight details of the books of a media library, from the provided <paramref name="query"/>.
|
||||
/// </summary>
|
||||
/// <param name="query">The model containing the parameters used to retrieve the books.</param>
|
||||
/// <returns>The API endpoint to which the retrieval request is sent.</returns>
|
||||
private static string BuildItemsEndpoint(BookLibraryItemsQueryModel query)
|
||||
{
|
||||
StringBuilder endpoint = new($"books/lite?libraryId={query.LibraryId}");
|
||||
if (query.CurrentPage is not null)
|
||||
endpoint.Append($"¤tPage={query.CurrentPage}");
|
||||
if (query.PerPage is not null)
|
||||
endpoint.Append($"&perPage={query.PerPage}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SearchTerm))
|
||||
endpoint.Append($"&searchTerm={Uri.EscapeDataString(query.SearchTerm)}");
|
||||
if (!string.IsNullOrWhiteSpace(query.FilterAlphaKey))
|
||||
endpoint.Append($"&filterAlphaKey={Uri.EscapeDataString(query.FilterAlphaKey)}");
|
||||
endpoint.Append($"&ignoreThePrefixForAlphaPicker={query.IgnoreThePrefixForAlphaPicker}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SortBy))
|
||||
endpoint.Append($"&sortBy={Uri.EscapeDataString(query.SortBy)}");
|
||||
if (query.SortOrder is not null)
|
||||
endpoint.Append($"&sortOrder={query.SortOrder}");
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Suchen</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortieren: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortieren: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>Einträge</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>von</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Seite</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Zurück</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Weiter</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Alle</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Diese Bibliothek hat keine Einträge</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Keine Einträge entsprechen den aktuellen Filtern</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Buscar</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordenar: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordenar: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementos</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>de</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Página</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Anterior</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Siguiente</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Todos</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Esta biblioteca no tiene elementos</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Ningún elemento coincide con los filtros actuales</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Rechercher</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Trier : A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Trier : Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>éléments</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>sur</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Précédent</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Suivant</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Tous</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Cette bibliothèque ne contient aucun élément</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Aucun élément ne correspond aux filtres actuels</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Cerca</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordina: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordina: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementi</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>di</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Precedente</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Successivo</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Tutti</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Questa biblioteca non contiene elementi</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Nessun elemento corrisponde ai filtri correnti</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>検索</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>並べ替え: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>並べ替え: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>件</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>ページ</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>前へ</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>次へ</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>すべて</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>このライブラリには項目がありません</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>現在のフィルターに一致する項目はありません</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Caută</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortare: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortare: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elemente</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>din</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Înapoi</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Înainte</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Toate</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Această bibliotecă nu are elemente</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Niciun element nu corespunde filtrelor curente</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Поиск</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Сортировка: А-Я</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Сортировка: Я-А</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>элементов</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>из</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Страница</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Назад</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Вперёд</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Все</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>В этой библиотеке нет элементов</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Ни один элемент не соответствует текущим фильтрам</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>搜索</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>排序: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>排序: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>项</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>页</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>上一页</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>下一页</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>全部</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>此库中没有项目</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>没有项目符合当前筛选条件</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -27,11 +27,15 @@
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
|
||||
const librariesContainer = document.getElementById('libraries-container');
|
||||
const noLibrariesMessage = document.getElementById('no-libraries');
|
||||
|
||||
const documentLoaded = async function () {
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
// get the media libraries
|
||||
// TODO: add setting check whether the user desires this feature or not
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetEnabledLibraries", "LibraryManagement")');
|
||||
@@ -40,33 +44,43 @@
|
||||
librariesContainer.classList.replace('justify-center', 'justify-start');
|
||||
// populate media library items
|
||||
data.forEach((library) => {
|
||||
const libraryDiv = document.createElement('div');
|
||||
libraryDiv.className = 'media-panel';
|
||||
// book libraries are browsable, so their panel is rendered as a link to their browse page
|
||||
const isBrowsable = library.libraryType === 'Book';
|
||||
const browseUrl = isBrowsable
|
||||
? '@_urlService.GetAbsoluteUrl("Index", "Books")' + '?libraryId=' + library.id
|
||||
: null;
|
||||
|
||||
const libraryElement = isBrowsable ? document.createElement('a') : document.createElement('div');
|
||||
libraryElement.className = isBrowsable ? 'media-panel nav-link no-underline' : 'media-panel';
|
||||
if (browseUrl)
|
||||
libraryElement.href = browseUrl;
|
||||
|
||||
// the cover image is optional, so it is only rendered when the library has one
|
||||
const coverImageHtml = library.coverImage
|
||||
? `<img src="${globalConfiguration.serverBasePath}/media/libraries/${library.id}/${library.coverImage.substring(library.coverImage.lastIndexOf('cover.'))}" />`
|
||||
: '';
|
||||
|
||||
libraryDiv.innerHTML = `
|
||||
libraryElement.innerHTML = `
|
||||
${coverImageHtml}
|
||||
<span class="text-light-two"><strong>${library.title}</strong></span>
|
||||
`;
|
||||
|
||||
librariesContainer.appendChild(libraryDiv);
|
||||
librariesContainer.appendChild(libraryElement);
|
||||
});
|
||||
// bind the AJAX navigation behavior to the library links, which were created after the initial navigation binding
|
||||
bindNavigationLinks();
|
||||
} else {
|
||||
noLibrariesMessage.classList.replace('hidden', 'block');
|
||||
librariesContainer.classList.replace('justify-start', 'justify-center');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// add listeners
|
||||
document.addEventListener('DOMContentLoaded', documentLoaded);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', documentLoaded);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
|
||||
+316
-1
@@ -1,2 +1,317 @@
|
||||
@*
|
||||
/library/written-content-library/books-library/books?libraryId=...
|
||||
*@
|
||||
|
||||
<p>All books</p><a href="books/E6B599D6-3819-4FAB-B988-8F027072CF7B" class="nav-link">one</a>
|
||||
@using Lumina.Presentation.Web.Common.Models.Libraries
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model LibraryModel
|
||||
|
||||
<div class="cotton-candy">
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;">
|
||||
<!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="pl-10 pr-10 pb-10">
|
||||
<div class="text-center">
|
||||
<h1 class="text-light-two engraved-title">@(Model.Title ?? string.Empty)</h1>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input id="search-input" type="text" class="enlightenment-input w-200px" placeholder="@_localizer["Search"]" />
|
||||
<button id="search-button" type="button" class="confirm-button">@_localizer["Search"]</button>
|
||||
<button id="sort-toggle" type="button" class="confirm-button">@_localizer["SortAscending"]</button>
|
||||
<span id="count-label" class="text-light-two"></span>
|
||||
</div>
|
||||
<div style="display: flex; align-items: flex-start;">
|
||||
<div id="books-container" class="cards-container justify-start h-100" style="flex: 1; min-width: 0;">
|
||||
<p id="no-items" class="hidden text-light-two">@_localizer["NoItems"]</p>
|
||||
<p id="no-items-matching" class="hidden text-light-two">@_localizer["NoItemsMatchFilters"]</p>
|
||||
</div>
|
||||
<div id="alpha-picker" class="alpha-picker"></div>
|
||||
</div>
|
||||
<div id="pagination" class="form-row mx-auto w-25 hidden" style="justify-content: center;">
|
||||
<button id="prev-page" type="button" class="abort-button">@_localizer["Previous"]</button>
|
||||
<span id="page-indicator" class="text-light-two"></span>
|
||||
<button id="next-page" type="button" class="confirm-button">@_localizer["Next"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
let requestSequence = 0;
|
||||
|
||||
const libraryId = '@(Model.Id ?? Guid.Empty)';
|
||||
const booksContainer = document.getElementById('books-container');
|
||||
const noItemsMessage = document.getElementById('no-items');
|
||||
const noItemsMatchingMessage = document.getElementById('no-items-matching');
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchButton = document.getElementById('search-button');
|
||||
const sortToggle = document.getElementById('sort-toggle');
|
||||
const countLabel = document.getElementById('count-label');
|
||||
const alphaPicker = document.getElementById('alpha-picker');
|
||||
const pagination = document.getElementById('pagination');
|
||||
const prevPageButton = document.getElementById('prev-page');
|
||||
const nextPageButton = document.getElementById('next-page');
|
||||
const pageIndicator = document.getElementById('page-indicator');
|
||||
|
||||
// the special alpha keys for numbers and symbols, followed by the letters
|
||||
const alphaKeys = ['#', '*', ...Array.from({ length: 26 }, (_, index) => String.fromCharCode(65 + index))];
|
||||
|
||||
const state = {
|
||||
currentPage: 1,
|
||||
perPage: null,
|
||||
searchTerm: '',
|
||||
alphaKey: null,
|
||||
ignoreThePrefix: false,
|
||||
sortOrder: 'Ascending'
|
||||
};
|
||||
|
||||
const jsLocalizedStrings = {
|
||||
all: '@_localizer["All"]',
|
||||
items: '@_localizer["Items"]',
|
||||
of: '@_localizer["Of"]',
|
||||
page: '@_localizer["Page"]',
|
||||
sortAscending: '@_localizer["SortAscending"]',
|
||||
sortDescending: '@_localizer["SortDescending"]'
|
||||
};
|
||||
|
||||
// builds the URL of the retrieval endpoint, from the current state
|
||||
function buildItemsUrl() {
|
||||
const url = '@_urlService.GetAbsoluteUrl("GetLibraryItems", "Books")';
|
||||
const params = new URLSearchParams();
|
||||
params.set('libraryId', libraryId);
|
||||
if (state.perPage !== null) {
|
||||
params.set('currentPage', state.currentPage);
|
||||
params.set('perPage', state.perPage);
|
||||
}
|
||||
if (state.searchTerm !== '')
|
||||
params.set('searchTerm', state.searchTerm);
|
||||
if (state.alphaKey !== null)
|
||||
params.set('filterAlphaKey', state.alphaKey);
|
||||
params.set('ignoreThePrefixForAlphaPicker', state.ignoreThePrefix);
|
||||
params.set('sortOrder', state.sortOrder);
|
||||
return `${url}?${params.toString()}`;
|
||||
}
|
||||
|
||||
// retrieves the books and renders them, ignoring stale responses of earlier requests
|
||||
async function loadItemsAsync() {
|
||||
const requestId = ++requestSequence;
|
||||
const response = await callApiGetAsync(buildItemsUrl());
|
||||
if (requestId !== requestSequence)
|
||||
return;
|
||||
if (response)
|
||||
renderItems(response);
|
||||
}
|
||||
|
||||
// renders the retrieved books, the count label and the pagination controls
|
||||
function renderItems(response) {
|
||||
booksContainer.querySelectorAll('.media-panel').forEach(card => card.remove());
|
||||
|
||||
const hasActiveFilters = state.searchTerm !== '' || state.alphaKey !== null;
|
||||
if (response.count === 0) {
|
||||
booksContainer.classList.add('justify-center');
|
||||
noItemsMessage.classList.toggle('hidden', hasActiveFilters);
|
||||
noItemsMatchingMessage.classList.toggle('hidden', !hasActiveFilters);
|
||||
} else {
|
||||
booksContainer.classList.remove('justify-center');
|
||||
noItemsMessage.classList.add('hidden');
|
||||
noItemsMatchingMessage.classList.add('hidden');
|
||||
response.data.forEach(book => booksContainer.appendChild(createBookCard(book)));
|
||||
}
|
||||
|
||||
updateCountLabel(response);
|
||||
updatePagination(response);
|
||||
}
|
||||
|
||||
// creates a portrait card for a book, with its cover image (or a placeholder) and its title
|
||||
function createBookCard(book) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'media-panel';
|
||||
card.style.width = '160px';
|
||||
card.style.height = '240px';
|
||||
|
||||
const image = document.createElement('img');
|
||||
image.src = book.coverPath
|
||||
? `${globalConfiguration.serverBasePath}${book.coverPath}`
|
||||
: `/images/ui/book-placeholder.svg`;
|
||||
image.alt = book.title;
|
||||
|
||||
const titleSpan = document.createElement('span');
|
||||
titleSpan.className = 'text-light-two';
|
||||
const title = document.createElement('strong');
|
||||
title.textContent = book.title;
|
||||
titleSpan.appendChild(title);
|
||||
|
||||
card.appendChild(image);
|
||||
card.appendChild(titleSpan);
|
||||
return card;
|
||||
}
|
||||
|
||||
// updates the count label: total items when pagination is off, displayed range out of total when it is on
|
||||
function updateCountLabel(response) {
|
||||
if (state.perPage === null)
|
||||
countLabel.textContent = `${response.count} ${jsLocalizedStrings.items}`;
|
||||
else if (response.count === 0)
|
||||
countLabel.textContent = `0 ${jsLocalizedStrings.items}`;
|
||||
else {
|
||||
const start = (response.currentPage - 1) * response.perPage + 1;
|
||||
const end = Math.min(response.currentPage * response.perPage, response.count);
|
||||
countLabel.textContent = `${start}-${end} ${jsLocalizedStrings.of} ${response.count}`;
|
||||
}
|
||||
}
|
||||
|
||||
// updates the pagination controls, which are only visible when pagination is enabled
|
||||
function updatePagination(response) {
|
||||
if (state.perPage === null) {
|
||||
pagination.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
const totalPages = Math.max(1, response.numberOfPages);
|
||||
pagination.classList.remove('hidden');
|
||||
pageIndicator.textContent = `${jsLocalizedStrings.page} ${response.currentPage} ${jsLocalizedStrings.of} ${totalPages}`;
|
||||
prevPageButton.disabled = response.currentPage <= 1;
|
||||
nextPageButton.disabled = response.currentPage >= totalPages;
|
||||
}
|
||||
|
||||
// builds the alpha picker column, with the "All" key followed by the numbers, symbols and letters keys
|
||||
function buildAlphaPicker() {
|
||||
const allKey = document.createElement('span');
|
||||
allKey.className = 'alpha-key';
|
||||
allKey.dataset.alphaKey = '';
|
||||
allKey.textContent = jsLocalizedStrings.all;
|
||||
allKey.addEventListener('click', () => handleAlphaKeyClick(null));
|
||||
alphaPicker.appendChild(allKey);
|
||||
|
||||
alphaKeys.forEach(key => {
|
||||
const alphaKey = document.createElement('span');
|
||||
alphaKey.className = 'alpha-key';
|
||||
alphaKey.dataset.alphaKey = key;
|
||||
alphaKey.textContent = key;
|
||||
alphaKey.addEventListener('click', () => handleAlphaKeyClick(key));
|
||||
alphaPicker.appendChild(alphaKey);
|
||||
});
|
||||
|
||||
updateAlphaPickerActiveState();
|
||||
}
|
||||
|
||||
// highlights the currently active key of the alpha picker
|
||||
function updateAlphaPickerActiveState() {
|
||||
alphaPicker.querySelectorAll('.alpha-key').forEach(key => {
|
||||
const keyValue = key.dataset.alphaKey === '' ? null : key.dataset.alphaKey;
|
||||
key.classList.toggle('alpha-key-active', keyValue === state.alphaKey);
|
||||
});
|
||||
}
|
||||
|
||||
// applies the given alpha key (null clears the alpha filter) and reloads the books
|
||||
function handleAlphaKeyClick(key) {
|
||||
state.alphaKey = key;
|
||||
state.currentPage = 1;
|
||||
updateAlphaPickerActiveState();
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// applies the search term and reloads the books
|
||||
function handleSearch() {
|
||||
state.searchTerm = searchInput.value.trim();
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// triggers the search when the Enter key is pressed in the search input
|
||||
function handleSearchKeydown(event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
handleSearch();
|
||||
}
|
||||
}
|
||||
|
||||
// toggles the sort direction and reloads the books
|
||||
function handleSortToggle() {
|
||||
state.sortOrder = state.sortOrder === 'Ascending' ? 'Descending' : 'Ascending';
|
||||
sortToggle.textContent = state.sortOrder === 'Ascending' ? jsLocalizedStrings.sortAscending : jsLocalizedStrings.sortDescending;
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// applies an alpha filter when a letter is pressed while the search input does not have focus; Escape clears the alpha filter
|
||||
function handleAlphaKeydown(event) {
|
||||
if (document.activeElement === searchInput)
|
||||
return;
|
||||
if (event.key.length === 1 && /[a-zA-Z]/.test(event.key))
|
||||
handleAlphaKeyClick(event.key.toUpperCase());
|
||||
else if (event.key === 'Escape')
|
||||
handleAlphaKeyClick(null);
|
||||
}
|
||||
|
||||
// loads the settings of the current user, which drive pagination and the alpha picker prefix handling
|
||||
async function loadSettingsAsync() {
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetUserSettings", "Settings")');
|
||||
if (data) {
|
||||
state.ignoreThePrefix = data.ignoreThePrefixForAlphaPicker === true;
|
||||
state.perPage = data.isPaginationEnabled === true ? data.itemsPerPage : null;
|
||||
}
|
||||
}
|
||||
|
||||
// navigates to the previous page
|
||||
function handlePrevPageClick() {
|
||||
state.currentPage = Math.max(1, state.currentPage - 1);
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// navigates to the next page
|
||||
function handleNextPageClick() {
|
||||
state.currentPage = state.currentPage + 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// add listeners
|
||||
searchButton.addEventListener('click', handleSearch);
|
||||
searchInput.addEventListener('keydown', handleSearchKeydown);
|
||||
sortToggle.addEventListener('click', handleSortToggle);
|
||||
prevPageButton.addEventListener('click', handlePrevPageClick);
|
||||
nextPageButton.addEventListener('click', handleNextPageClick);
|
||||
document.addEventListener('keydown', handleAlphaKeydown);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
searchButton.removeEventListener('click', handleSearch);
|
||||
searchInput.removeEventListener('keydown', handleSearchKeydown);
|
||||
sortToggle.removeEventListener('click', handleSortToggle);
|
||||
prevPageButton.removeEventListener('click', handlePrevPageClick);
|
||||
nextPageButton.removeEventListener('click', handleNextPageClick);
|
||||
document.removeEventListener('keydown', handleAlphaKeydown);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
sortToggle.textContent = jsLocalizedStrings.sortAscending;
|
||||
buildAlphaPicker();
|
||||
await loadSettingsAsync();
|
||||
await loadItemsAsync();
|
||||
}
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -1488,6 +1488,25 @@ th, td {
|
||||
margin-left: auto !important;
|
||||
}
|
||||
|
||||
.alpha-picker {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.alpha-key {
|
||||
padding: 0 0.6rem;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.alpha-key:hover,
|
||||
.alpha-key.alpha-key-active {
|
||||
background-color: #00000066;
|
||||
}
|
||||
|
||||
/* For phones */
|
||||
@media only screen and (max-width: 768px) {
|
||||
main {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 300">
|
||||
<rect width="200" height="300" fill="#1c1c1c" />
|
||||
<g fill="none" stroke="#6DCBFE" stroke-width="6" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M60 90c0-14 10-24 24-24h56c14 0 24 10 24 24v120c0 14-10 24-24 24H84c-14 0-24-10-24-24z" />
|
||||
<path d="M60 94c0-14 10-24 24-24h24v140H84c-14 0-24-10-24-24z" />
|
||||
<path d="M84 150h32" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 447 B |
Reference in new issue
Block a user