mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Adds a theme caching toggle to the user settings
This commit is contained in:
1 parent
60b551558f
commit
3da7167538
43 files changed
+1611
-56
No files matched your search
@@ -30,4 +30,9 @@ public class UserSettingsDto
|
||||
/// Gets or sets whether the "The" prefix of library item titles is ignored by the alpha picker, or not.
|
||||
/// </summary>
|
||||
public bool IgnoreThePrefixForAlphaPicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the theme data served to this user is cached, or not.
|
||||
/// </summary>
|
||||
public bool IsThemeCachingEnabled { get; set; } = true;
|
||||
}
|
||||
+23
-1
@@ -3,9 +3,12 @@ using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -18,14 +21,17 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.GetUserSettings;
|
||||
public class GetUserSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly ThemeCachePreferenceService _themeCachePreferenceService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetUserSettingsEndpoint(IApiHttpClient apiHttpClient)
|
||||
/// <param name="themeCachePreferenceService">Injected service for storing the per-user theme cache preference.</param>
|
||||
public GetUserSettingsEndpoint(IApiHttpClient apiHttpClient, ThemeCachePreferenceService themeCachePreferenceService)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_themeCachePreferenceService = themeCachePreferenceService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,6 +54,22 @@ public class GetUserSettingsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
UserSettingsDto response = await _apiHttpClient.GetAsync<UserSettingsDto>(ApiRoutes.Users.GET_USER_SETTINGS, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// refresh the per-user theme cache preference from the stored settings, so the handler always applies the latest value
|
||||
Guid? userId = GetCurrentUserId();
|
||||
if (userId is not null)
|
||||
await _themeCachePreferenceService.SetAsync(userId.Value, response.IsThemeCachingEnabled, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the currently authenticated user.
|
||||
/// </summary>
|
||||
/// <returns>The unique identifier of the current user, or <see langword="null"/> when the request is anonymous.</returns>
|
||||
private Guid? GetCurrentUserId()
|
||||
{
|
||||
string? userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
return Guid.TryParse(userId, out Guid parsedUserId) ? parsedUserId : null;
|
||||
}
|
||||
}
|
||||
+23
-1
@@ -3,9 +3,12 @@ using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.UsersManagement;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Common.Services;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -18,14 +21,17 @@ namespace Lumina.Presentation.Web.Core.Endpoints.Tools.Settings.UpdateUserSettin
|
||||
public class UpdateUserSettingsEndpoint : BaseEndpoint<UserSettingsDto, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
private readonly ThemeCachePreferenceService _themeCachePreferenceService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public UpdateUserSettingsEndpoint(IApiHttpClient apiHttpClient)
|
||||
/// <param name="themeCachePreferenceService">Injected service for storing the per-user theme cache preference.</param>
|
||||
public UpdateUserSettingsEndpoint(IApiHttpClient apiHttpClient, ThemeCachePreferenceService themeCachePreferenceService)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
_themeCachePreferenceService = themeCachePreferenceService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,6 +55,22 @@ public class UpdateUserSettingsEndpoint : BaseEndpoint<UserSettingsDto, IResult>
|
||||
public override async Task<IResult> ExecuteAsync(UserSettingsDto request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _apiHttpClient.PutAsync<Web.Common.Requests.Common.EmptyRequest, UserSettingsDto>(ApiRoutes.Users.UPDATE_USER_SETTINGS, request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// keep the per-user theme cache preference in sync with the stored settings, so the handler applies it immediately
|
||||
Guid? userId = GetCurrentUserId();
|
||||
if (userId is not null)
|
||||
await _themeCachePreferenceService.SetAsync(userId.Value, request.IsThemeCachingEnabled, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return JsonSuccess(new { isUpdated = true });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the currently authenticated user.
|
||||
/// </summary>
|
||||
/// <returns>The unique identifier of the current user, or <see langword="null"/> when the request is anonymous.</returns>
|
||||
private Guid? GetCurrentUserId()
|
||||
{
|
||||
string? userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
return Guid.TryParse(userId, out Guid parsedUserId) ? parsedUserId : null;
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>Wenn aktiviert, werden Bibliothekselemente, deren Titel mit "The" beginnt, in der Alpha-Auswahl unter dem ersten Buchstaben des folgenden Wortes gruppiert, z. B. wird "The Rasmus" unter R aufgeführt.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Themencache aktivieren</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Gibt an, ob die von der Anwendung bereitgestellten Themendateien zwischengespeichert werden. Deaktivieren Sie diese Option beim Bearbeiten von Themendateien, damit die Änderungen sofort erscheinen.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>When enabled, library items whose title begins with "The" are grouped under the first letter of the following word in the alpha picker, e.g. "The Rasmus" is listed under R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Enable theme caching</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Whether the theme files served by the application are cached. Turn this off while editing theme files so the changes appear immediately.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>Cuando está habilitado, los elementos de la biblioteca cuyo título comienza con "The" se agrupan bajo la primera letra de la palabra siguiente en el selector alfabético, por ejemplo, "The Rasmus" se lista bajo R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Habilitar caché de temas</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Controla si los archivos de temas servidos por la aplicación se almacenan en caché. Desactívelo mientras edita archivos de temas para que los cambios aparezcan inmediatamente.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>Lorsque cette option est activée, les éléments de la bibliothèque dont le titre commence par "The" sont regroupés sous la première lettre du mot suivant dans le sélecteur alphabétique, par exemple "The Rasmus" est répertorié sous R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Activer le cache des thèmes</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Contrôle si les fichiers de thèmes servis par l'application sont mis en cache. Désactivez-le pendant la modification des fichiers de thèmes afin que les changements apparaissent immédiatement.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>Se abilitato, gli elementi della libreria il cui titolo inizia con "The" vengono raggruppati sotto la prima lettera della parola successiva nel selettore alfabetico, ad esempio "The Rasmus" è elencato sotto R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Abilita la cache dei temi</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Controlla se i file dei temi serviti dall'applicazione vengono memorizzati nella cache. Disattivalo mentre modifichi i file dei temi affinché le modifiche appaiano immediatamente.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>有効にすると、タイトルが「The」で始まるライブラリの項目は、アルファピッカーで次の単語の最初の文字の下にグループ化されます。たとえば「The Rasmus」は「R」の下に表示されます。</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>テーマキャッシュを有効にする</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>アプリケーションが提供するテーマファイルをキャッシュするかどうかを制御します。テーマファイルを編集している間はオフにして、変更がすぐに反映されるようにします。</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>When enabled, library items whose title begins with "The" are grouped under the first letter of the following word in the alpha picker, e.g. "The Rasmus" is listed under R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Enable theme caching</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Whether the theme files served by the application are cached. Turn this off while editing theme files so the changes appear immediately.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>Când este activată, elementele bibliotecii al căror titlu începe cu "The" sunt grupate sub prima literă a cuvântului următor în selectorul alfabetic, de exemplu "The Rasmus" este listat sub R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Activează cache-ul temelor</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Controlează dacă fișierele temelor servite de aplicație sunt puse în cache. Dezactivați această opțiune în timp ce editați fișierele temelor, pentru ca modificările să apară imediat.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>При включении элементы библиотеки, название которых начинается с "The", группируются в алфавитном указателе под первой буквой следующего слова, например "The Rasmus" отображается под буквой R.</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>Включить кэширование тем</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>Определяет, кэшируются ли файлы тем, предоставляемые приложением. Отключите эту опцию при редактировании файлов тем, чтобы изменения отображались сразу.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -39,4 +39,10 @@
|
||||
<data name="DescriptionIgnoreThePrefixForAlphaPicker" xml:space="preserve">
|
||||
<value>启用后,标题以"The"开头的库项目将在字母选择器中按后一个词的首字母分组,例如"The Rasmus"会列在R下。</value>
|
||||
</data>
|
||||
<data name="EnableThemeCaching" xml:space="preserve">
|
||||
<value>启用主题缓存</value>
|
||||
</data>
|
||||
<data name="DescriptionEnableThemeCaching" xml:space="preserve">
|
||||
<value>控制应用程序提供的主题文件是否缓存。编辑主题文件时请关闭此选项,以便更改立即生效。</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -65,6 +65,19 @@
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionIgnoreThePrefixForAlphaPicker"]</small>
|
||||
</div>
|
||||
<!-- Theme caching -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="IsThemeCachingEnabled">@_localizer["EnableThemeCaching"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" asp-for="IsThemeCachingEnabled" class="enlightenment-checkbox-hidden" />
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionEnableThemeCaching"]</small>
|
||||
</div>
|
||||
<div class="form-row" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px">@_localizer["Save"]</button>
|
||||
</div>
|
||||
@@ -82,6 +95,7 @@
|
||||
const checkboxIsPaginationEnabled = document.getElementById('IsPaginationEnabled');
|
||||
const inputItemsPerPage = document.getElementById('ItemsPerPage');
|
||||
const checkboxIgnoreThePrefixForAlphaPicker = document.getElementById('IgnoreThePrefixForAlphaPicker');
|
||||
const checkboxIsThemeCachingEnabled = document.getElementById('IsThemeCachingEnabled');
|
||||
|
||||
// toggle the enabled state of the items per page input based on the pagination checkbox
|
||||
function updateItemsPerPageEnabledState() {
|
||||
@@ -95,6 +109,7 @@
|
||||
checkboxIsPaginationEnabled.checked = data.isPaginationEnabled === true;
|
||||
inputItemsPerPage.value = data.itemsPerPage;
|
||||
checkboxIgnoreThePrefixForAlphaPicker.checked = data.ignoreThePrefixForAlphaPicker === true;
|
||||
checkboxIsThemeCachingEnabled.checked = data.isThemeCachingEnabled === true;
|
||||
updateItemsPerPageEnabledState();
|
||||
}
|
||||
}
|
||||
@@ -104,7 +119,8 @@
|
||||
const formData = {
|
||||
IsPaginationEnabled: checkboxIsPaginationEnabled.checked,
|
||||
ItemsPerPage: Number(inputItemsPerPage.value),
|
||||
IgnoreThePrefixForAlphaPicker: checkboxIgnoreThePrefixForAlphaPicker.checked
|
||||
IgnoreThePrefixForAlphaPicker: checkboxIgnoreThePrefixForAlphaPicker.checked,
|
||||
IsThemeCachingEnabled: checkboxIsThemeCachingEnabled.checked
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl(WebRoutes.Settings.UPDATE_USER_SETTINGS)', formData);
|
||||
if (data && data.isUpdated === true)
|
||||
|
||||
Reference in new issue
Block a user