mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Renders themed pages as swappable sections with path-mirrored template scopes and a Razor fallback
This commit is contained in:
1 parent
f17e685239
commit
e37bb3ecc6
24 files changed
+351
-187
No files matched your search
+41
-3
@@ -2,12 +2,17 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Primitives;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Lumina.Presentation.Web.Core.Themes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -19,18 +24,32 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Library.WrittenContentLibrary.B
|
||||
/// </summary>
|
||||
public class BooksIndexViewEndpoint : BaseEndpoint<GetBooksViewRequest, IResult>
|
||||
{
|
||||
// the resource base name deliberately excludes the "Core.Resources" segment: the localization factory re-roots it
|
||||
// with the configured ResourcesPath, so "Lumina.Presentation.Web.Views.X" resolves to the embedded
|
||||
// "Lumina.Presentation.Web.Core.Resources.Views.X" resource; including "Core" here would insert it twice
|
||||
private const string VIEW_RESOURCE_BASE_NAME = "Lumina.Presentation.Web.Views.Library.WrittenContentLibrary.BookLibrary.Books.Index";
|
||||
private const string VIEW_RESOURCE_LOCATION = "Lumina.Presentation.Web";
|
||||
// the page key mirrors the path of the Razor view under Core/Views, so that theme templates can override it at the page, section or default scope
|
||||
private const string VIEW_PAGE_KEY = "library/written-content-library/book-library/books/index";
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly IUrlService _urlService;
|
||||
private readonly ThemePageRenderer _themePageRenderer;
|
||||
private readonly IStringLocalizer _localizer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksIndexViewEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
/// <param name="urlService">Injected service for generating URLs from action and controller names, with localization.</param>
|
||||
public BooksIndexViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService)
|
||||
/// <param name="themePageRenderer">Injected service for rendering themed pages.</param>
|
||||
/// <param name="stringLocalizerFactory">Injected factory used to create the localizer of the view resources.</param>
|
||||
public BooksIndexViewEndpoint(IApiHttpClient apiHttpClient, IUrlService urlService, ThemePageRenderer themePageRenderer, IStringLocalizerFactory stringLocalizerFactory)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_urlService = urlService;
|
||||
_themePageRenderer = themePageRenderer;
|
||||
_localizer = stringLocalizerFactory.Create(VIEW_RESOURCE_BASE_NAME, VIEW_RESOURCE_LOCATION);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,7 +65,7 @@ public class BooksIndexViewEndpoint : BaseEndpoint<GetBooksViewRequest, IResult>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the books browsing view.
|
||||
/// Displays the books browsing view, rendered by the active theme with a fallback to the Razor view.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing 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>
|
||||
@@ -55,6 +74,25 @@ public class BooksIndexViewEndpoint : BaseEndpoint<GetBooksViewRequest, IResult>
|
||||
if (request.LibraryId is null)
|
||||
return Results.Redirect(_urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED)!);
|
||||
LibraryDto library = await _apiHttpClient.GetAsync<LibraryDto>(ApiRoutes.Libraries.GET_LIBRARY_BY_ID.Replace("{id}", request.LibraryId.Value.ToString()), cancellationToken).ConfigureAwait(false);
|
||||
return View("/Core/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml", library);
|
||||
|
||||
ThemePageDto pageModel = new()
|
||||
{
|
||||
PageKey = VIEW_PAGE_KEY,
|
||||
Title = library.Title ?? string.Empty,
|
||||
Description = string.Empty,
|
||||
PageData = new Dictionary<string, object?>
|
||||
{
|
||||
["libraryId"] = library.Id?.ToString() ?? request.LibraryId.Value.ToString(),
|
||||
["itemsUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Books.GET_LIBRARY_ITEMS) ?? string.Empty,
|
||||
["settingsUrl"] = _urlService.GetAbsoluteUrl(WebRoutes.Settings.GET_USER_SETTINGS) ?? string.Empty,
|
||||
["strings"] = ThemePageDataFactory.CreateLocalizedStrings(_localizer)
|
||||
}
|
||||
};
|
||||
|
||||
Result<ThemePageRenderResultDto> renderResult = await _themePageRenderer.RenderAsync(pageModel, requestedThemeId: null, cancellationToken).ConfigureAwait(false);
|
||||
if (renderResult.IsFailure)
|
||||
return View("/Core/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml", library);
|
||||
|
||||
return View("/Core/Views/Shared/_ThemedView.cshtml", new ThemeViewDto(renderResult.Value.Content, renderResult.Value.Script, pageModel.AssetBase));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class ThemeAssetsEndpoint : BaseEndpoint<GetThemeAssetRequest, IResult>
|
||||
return Results.Problem(statusCode: StatusCodes.Status400BadRequest, detail: "The theme id and the asset path are required.");
|
||||
|
||||
BlobDataDto blob = await _apiHttpClient.GetBlobAsync(
|
||||
ApiRoutes.Themes.GET_THEME_ASSET.Replace("{themeId}", request.ThemeId).Replace("{assetPath}", request.Path), cancellationToken).ConfigureAwait(false);
|
||||
ApiRoutes.Themes.GET_THEME_ASSET.Replace("{themeId}", request.ThemeId).Replace("{*assetPath}", request.Path), cancellationToken).ConfigureAwait(false);
|
||||
return Results.File(blob.Data, blob.ContentType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user