mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Adds user settings management
Adds the UserSettings aggregate with pagination and alpha picker preferences, keyed to a user with a dedicated UserId foreign key. Adds GET and PUT /users/me/settings API endpoints, a localized Tools > Settings page with save confirmation, the EF migration for the UserSettings table, and unit, integration and security tests.
This commit is contained in:
1 parent
c3f8786fe4
commit
2354e21d42
65 files changed
+4711
-21
No files matched your search
@@ -106,7 +106,7 @@
|
||||
@_localizer["Tools"]
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="tools/options" class="nav-link"><span>@_localizer["Options"]</span></a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Index", "Settings")" class="nav-link"><span>@_localizer["Settings"]</span></a></li>
|
||||
</ul>
|
||||
}
|
||||
<div class="mobile-menu-heading">
|
||||
@@ -211,7 +211,7 @@
|
||||
</li>
|
||||
@if (User?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
<li><a href="tools/options" class="nav-link">@_localizer["Options"]</a></li>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Index", "Settings")" class="nav-link">@_localizer["Settings"]</a></li>
|
||||
}
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
@*
|
||||
/tools/settings
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.UsersManagement
|
||||
@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 IUrlService _urlService
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
@model UserSettingsModel
|
||||
|
||||
<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="enlightenment-panel shadow-effect mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="user-settings-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">
|
||||
@_localizer["Settings"]
|
||||
</h1>
|
||||
</div>
|
||||
<div class="form-container">
|
||||
<!-- Pagination -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="IsPaginationEnabled">@_localizer["EnablePagination"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" asp-for="IsPaginationEnabled" class="enlightenment-checkbox-hidden" />
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionEnablePagination"]</small>
|
||||
</div>
|
||||
<!-- Items per page -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="ItemsPerPage">@_localizer["ItemsPerPage"]</label>
|
||||
<span class="mandatory-field">*</span>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<input asp-for="ItemsPerPage" min="1" step="1" class="enlightenment-input" />
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionItemsPerPage"]</small>
|
||||
</div>
|
||||
<!-- Alpha picker -->
|
||||
<div class="form-row">
|
||||
<div class="form-label">
|
||||
<label asp-for="IgnoreThePrefixForAlphaPicker">@_localizer["IgnoreThePrefixForAlphaPicker"]</label>:
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="enlightenment-checkbox-label">
|
||||
<input type="checkbox" asp-for="IgnoreThePrefixForAlphaPicker" class="enlightenment-checkbox-hidden" />
|
||||
<span class="enlightenment-checkbox"></span>
|
||||
</label>
|
||||
</div>
|
||||
<small class="form-label text-disabled form-description">@_localizer["DescriptionIgnoreThePrefixForAlphaPicker"]</small>
|
||||
</div>
|
||||
<div class="form-row" style="justify-content: center;">
|
||||
<button type="submit" class="confirm-button h-22px">@_localizer["Save"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
|
||||
const form = document.getElementById('user-settings-form');
|
||||
const checkboxIsPaginationEnabled = document.getElementById('IsPaginationEnabled');
|
||||
const inputItemsPerPage = document.getElementById('ItemsPerPage');
|
||||
const checkboxIgnoreThePrefixForAlphaPicker = document.getElementById('IgnoreThePrefixForAlphaPicker');
|
||||
|
||||
// toggle the enabled state of the items per page input based on the pagination checkbox
|
||||
function updateItemsPerPageEnabledState() {
|
||||
inputItemsPerPage.disabled = !checkboxIsPaginationEnabled.checked;
|
||||
}
|
||||
|
||||
// load the settings of the current user
|
||||
async function loadUserSettingsAsync() {
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetUserSettings", "Settings")');
|
||||
if (data) {
|
||||
checkboxIsPaginationEnabled.checked = data.isPaginationEnabled === true;
|
||||
inputItemsPerPage.value = data.itemsPerPage;
|
||||
checkboxIgnoreThePrefixForAlphaPicker.checked = data.ignoreThePrefixForAlphaPicker === true;
|
||||
updateItemsPerPageEnabledState();
|
||||
}
|
||||
}
|
||||
|
||||
// save the settings of the current user
|
||||
async function handleSaveUserSettingsAsync() {
|
||||
const formData = {
|
||||
IsPaginationEnabled: checkboxIsPaginationEnabled.checked,
|
||||
ItemsPerPage: Number(inputItemsPerPage.value),
|
||||
IgnoreThePrefixForAlphaPicker: checkboxIgnoreThePrefixForAlphaPicker.checked
|
||||
};
|
||||
const data = await callApiPostAsync('@_urlService.GetAbsoluteUrl("UpdateUserSettings", "Settings")', formData);
|
||||
if (data && data.isUpdated === true)
|
||||
notificationService.show('@_localizer["SettingsSaved"]', NotificationType.SUCCESS);
|
||||
}
|
||||
|
||||
// on form submit event
|
||||
const handleSubmit = async function(e) {
|
||||
e.preventDefault();
|
||||
await handleSaveUserSettingsAsync();
|
||||
};
|
||||
|
||||
// on pagination checkbox change, update the enabled state of the items per page input
|
||||
const handlePaginationCheckboxChange = function() {
|
||||
updateItemsPerPageEnabledState();
|
||||
};
|
||||
|
||||
// add listeners
|
||||
form.addEventListener('submit', handleSubmit);
|
||||
checkboxIsPaginationEnabled.addEventListener('change', handlePaginationCheckboxChange);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
form.removeEventListener('submit', handleSubmit);
|
||||
checkboxIsPaginationEnabled.removeEventListener('change', handlePaginationCheckboxChange);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
await loadUserSettingsAsync();
|
||||
}
|
||||
|
||||
// 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>
|
||||
}
|
||||
Reference in new issue
Block a user