mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Filters the home page by library category from the navigation menu.
This commit is contained in:
1 parent
b29803ac77
commit
c7aab63552
3 files changed
+67
-14
No files matched your search
@@ -152,14 +152,17 @@ public sealed class ThemeNavBuilder
|
|||||||
];
|
];
|
||||||
if (canCreateLibraries)
|
if (canCreateLibraries)
|
||||||
items.Add(new ThemeNavEntryDto(Localize("AddNewLibrary"), _urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.ADD_LIBRARY), "nav-link", []));
|
items.Add(new ThemeNavEntryDto(Localize("AddNewLibrary"), _urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.ADD_LIBRARY), "nav-link", []));
|
||||||
|
// The written content and audio entries open the home page filtered to the libraries of their category, so that browsing starts
|
||||||
|
// from the libraries the user owns (or from every library, for administrators), instead of from a single library picked upfront.
|
||||||
|
string librariesCatalogUrl = _urlService.GetAbsoluteUrl(WebRoutes.Home.INDEX_CULTURED) ?? string.Empty;
|
||||||
items.Add(new ThemeNavEntryDto(Localize("WrittenContent"), Url: null, CssClass: null,
|
items.Add(new ThemeNavEntryDto(Localize("WrittenContent"), Url: null, CssClass: null,
|
||||||
[
|
[
|
||||||
new ThemeNavEntryDto(Localize("Books"), "library/written-content-library/books-library/books", "nav-link", []),
|
new ThemeNavEntryDto(Localize("Books"), $"{librariesCatalogUrl}?category=books", "nav-link", []),
|
||||||
new ThemeNavEntryDto(Localize("Magazines"), "library/written-content/magazines", "nav-link", [])
|
new ThemeNavEntryDto(Localize("Magazines"), "library/written-content/magazines", "nav-link", [])
|
||||||
]));
|
]));
|
||||||
items.Add(new ThemeNavEntryDto(Localize("Audio"), Url: null, CssClass: null,
|
items.Add(new ThemeNavEntryDto(Localize("Audio"), Url: null, CssClass: null,
|
||||||
[
|
[
|
||||||
new ThemeNavEntryDto(Localize("Music"), "library/audio/music", "nav-link", []),
|
new ThemeNavEntryDto(Localize("Music"), $"{librariesCatalogUrl}?category=music", "nav-link", []),
|
||||||
new ThemeNavEntryDto(Localize("Interviews"), "library/audio/interviews", "nav-link", [])
|
new ThemeNavEntryDto(Localize("Interviews"), "library/audio/interviews", "nav-link", [])
|
||||||
]));
|
]));
|
||||||
items.Add(new ThemeNavEntryDto(Localize("Video"), Url: null, CssClass: null,
|
items.Add(new ThemeNavEntryDto(Localize("Video"), Url: null, CssClass: null,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
@*
|
@*
|
||||||
/
|
/
|
||||||
|
?category=... (optional quick-navigation filter: lists only the libraries of the category)
|
||||||
*@
|
*@
|
||||||
|
|
||||||
@using Lumina.Presentation.Web.Common.DTO.Libraries
|
@using Lumina.Presentation.Web.Common.DTO.Libraries
|
||||||
@@ -9,6 +10,11 @@
|
|||||||
@{
|
@{
|
||||||
// Generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler.
|
// 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();
|
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||||
|
// The optional quick-navigation category the page is filtered to; empty when the page lists every enabled library.
|
||||||
|
// The value is restricted to the known categories, so that an arbitrary query value is never reflected back into the page.
|
||||||
|
var category = Context.Request.Query["category"].ToString().ToLowerInvariant();
|
||||||
|
if (category != "books" && category != "music")
|
||||||
|
category = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@inject IViewLocalizer _localizer
|
@inject IViewLocalizer _localizer
|
||||||
@@ -30,6 +36,25 @@
|
|||||||
const cleanupFunctions = [];
|
const cleanupFunctions = [];
|
||||||
let isInitialized = false;
|
let isInitialized = false;
|
||||||
|
|
||||||
|
// The category the page is filtered to, empty when it lists every enabled library.
|
||||||
|
const libraryCategory = '@category';
|
||||||
|
// Library types that have a browsing page in this application, mapped to it, so that the library cards link to their contents.
|
||||||
|
const libraryBrowseUrls = {
|
||||||
|
'Book': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'EBook': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'ComicBook': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'Manga': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'GraphicNovel': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'AcademicPaper': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'SheetMusic': '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)',
|
||||||
|
'Music': '@_urlService.GetAbsoluteUrl(WebRoutes.Music.ARTISTS_INDEX)'
|
||||||
|
};
|
||||||
|
// The quick-navigation categories of the navigation menu, mapped to the library types they list.
|
||||||
|
const libraryCategoryTypes = {
|
||||||
|
'books': ['Book', 'EBook', 'ComicBook', 'Manga', 'GraphicNovel', 'AcademicPaper', 'SheetMusic'],
|
||||||
|
'music': ['Music']
|
||||||
|
};
|
||||||
|
|
||||||
// The element references are captured once, so that the cleanup can unbind their listeners even after the AJAX navigator has swapped the content out of the document.
|
// The element references are captured once, so that the cleanup can unbind their listeners even after the AJAX navigator has swapped the content out of the document.
|
||||||
const librariesContainer = document.getElementById('libraries-container');
|
const librariesContainer = document.getElementById('libraries-container');
|
||||||
const noLibrariesMessage = document.getElementById('no-libraries');
|
const noLibrariesMessage = document.getElementById('no-libraries');
|
||||||
@@ -41,16 +66,19 @@
|
|||||||
// Get the media libraries.
|
// Get the media libraries.
|
||||||
// TODO: add setting check whether the user desires this feature or not.
|
// TODO: add setting check whether the user desires this feature or not.
|
||||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_ENABLED_LIBRARIES)');
|
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl(WebRoutes.LibraryManagement.GET_ENABLED_LIBRARIES)');
|
||||||
if (data && data.length > 0) {
|
// When the page is filtered to a category, only the libraries of the types of that category are listed; otherwise, every enabled library is listed.
|
||||||
noLibrariesMessage.classList.replace('block', 'hidden');
|
const categoryTypes = libraryCategory ? (libraryCategoryTypes[libraryCategory] || null) : null;
|
||||||
librariesContainer.classList.replace('justify-center', 'justify-start');
|
const libraries = data && categoryTypes ? data.filter((library) => categoryTypes.includes(library.libraryType)) : data;
|
||||||
|
if (libraries && libraries.length > 0) {
|
||||||
|
noLibrariesMessage.classList.add('hidden');
|
||||||
|
librariesContainer.classList.remove('justify-center');
|
||||||
|
librariesContainer.classList.add('justify-start');
|
||||||
// Populate media library items.
|
// Populate media library items.
|
||||||
data.forEach((library) => {
|
libraries.forEach((library) => {
|
||||||
// Book libraries are browsable, so their panel is rendered as a link to their browse page.
|
// Libraries that have a browsing page are rendered as a link to it; the others are rendered as a plain panel.
|
||||||
const isBrowsable = library.libraryType === 'Book';
|
const browseBase = libraryBrowseUrls[library.libraryType] || null;
|
||||||
const browseUrl = isBrowsable
|
const browseUrl = browseBase ? browseBase + '?libraryId=' + library.id : null;
|
||||||
? '@_urlService.GetAbsoluteUrl(WebRoutes.Books.INDEX)' + '?libraryId=' + library.id
|
const isBrowsable = browseUrl !== null;
|
||||||
: null;
|
|
||||||
|
|
||||||
const libraryElement = isBrowsable ? document.createElement('a') : document.createElement('div');
|
const libraryElement = isBrowsable ? document.createElement('a') : document.createElement('div');
|
||||||
libraryElement.className = isBrowsable ? 'media-panel nav-link no-underline' : 'media-panel';
|
libraryElement.className = isBrowsable ? 'media-panel nav-link no-underline' : 'media-panel';
|
||||||
@@ -72,8 +100,9 @@
|
|||||||
// Bind the AJAX navigation behavior to the library links, which were created after the initial navigation binding.
|
// Bind the AJAX navigation behavior to the library links, which were created after the initial navigation binding.
|
||||||
bindNavigationLinks();
|
bindNavigationLinks();
|
||||||
} else {
|
} else {
|
||||||
noLibrariesMessage.classList.replace('hidden', 'block');
|
noLibrariesMessage.classList.remove('hidden');
|
||||||
librariesContainer.classList.replace('justify-start', 'justify-center');
|
librariesContainer.classList.remove('justify-start');
|
||||||
|
librariesContainer.classList.add('justify-center');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,27 @@ public class ThemeNavBuilderTests
|
|||||||
Assert.DoesNotContain(librarySection.Items, entry => entry.Label == "Localized-AddNewLibrary");
|
Assert.DoesNotContain(librarySection.Items, entry => entry.Label == "Localized-AddNewLibrary");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task BuildAsync_WhenUserIsAuthenticated_ShouldLinkWrittenContentAndAudioEntriesToTheFilteredLibraryCatalog()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
_mockHttpContextAccessor.HttpContext.Returns(TestHttpContextFactory.Create(user: TestHttpContextFactory.CreateAuthenticatedUser()));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
ThemeNavMenuDto result = await _sut.BuildAsync(CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
// The written content and audio entries open the home page filtered to the libraries of their category, so that browsing starts
|
||||||
|
// from the libraries of that category, instead of from a single library picked upfront.
|
||||||
|
ThemeNavSectionDto librarySection = FindSection(result, "Localized-Library")!;
|
||||||
|
ThemeNavEntryDto writtenContentEntry = librarySection.Items.First(entry => entry.Label == "Localized-WrittenContent");
|
||||||
|
ThemeNavEntryDto audioEntry = librarySection.Items.First(entry => entry.Label == "Localized-Audio");
|
||||||
|
Assert.Contains(writtenContentEntry.Children, entry => entry.Label == "Localized-Books" && entry.Url == "http://localhost/en-us?category=books");
|
||||||
|
Assert.Contains(writtenContentEntry.Children, entry => entry.Label == "Localized-Magazines" && entry.Url == "library/written-content/magazines");
|
||||||
|
Assert.Contains(audioEntry.Children, entry => entry.Label == "Localized-Music" && entry.Url == "http://localhost/en-us?category=music");
|
||||||
|
Assert.Contains(audioEntry.Children, entry => entry.Label == "Localized-Interviews" && entry.Url == "library/audio/interviews");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task BuildAsync_WhenUserIsAdmin_ShouldIncludeAdministratorSection()
|
public async Task BuildAsync_WhenUserIsAdmin_ShouldIncludeAdministratorSection()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user