Adds client side dialogs

This commit is contained in:
BinaryAlley committed 2024-12-18 22:53:25 +02:00
1 parent b2acd9653b
commit 891aeb3281
46 files changed
+1013 -21

No files matched your search

@@ -15,6 +15,7 @@ public static partial class Errors
public static Error AdminAccountAlreadyCreated => Error.Conflict(description: nameof(AdminAccountAlreadyCreated));
public static Error AdminAccountNotFound => Error.NotFound(description: nameof(AdminAccountNotFound));
public static Error AdminRoleNotFound => Error.NotFound(description: nameof(AdminRoleNotFound));
public static Error AdminRoleCannotBeDeleted => Error.Forbidden(description: nameof(AdminRoleCannotBeDeleted));
public static Error RoleNotFound => Error.NotFound(description: nameof(RoleNotFound));
public static Error PermissionAlreadyExists => Error.Unauthorized(description: nameof(PermissionAlreadyExists));
public static Error RoleAlreadyExists => Error.Conflict(description: nameof(RoleAlreadyExists));
@@ -1,6 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement.Users;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.UsersManagement.Users;
@@ -24,4 +26,14 @@ public static class UserEntityMapping
repositoryEntity.UpdatedOnUtc
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="UserResponse"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<UserResponse> ToResponses(this IEnumerable<UserEntity> repositoryEntities)
{
return repositoryEntities.Select(role => role.ToResponse());
}
}
@@ -62,7 +62,8 @@ public class DeleteRoleCommandHandler : IRequestHandler<DeleteRoleCommand, Error
return getExistingRoleResult.Errors;
else if (getExistingRoleResult.Value is null)
return Errors.Authorization.RoleNotFound;
else if (getExistingRoleResult.Value.RoleName == "Admin")
return Errors.Authorization.AdminRoleCannotBeDeleted;
// delete the role and its permissions
ErrorOr<Deleted> deleteRoleResult = await roleRepository.DeleteByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
if (deleteRoleResult.IsError)
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
/// <summary>
/// Query for retrieving the list of users.
/// </summary>
public record GetUsersQuery() : IRequest<ErrorOr<IEnumerable<UserResponse>>>;
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Errors;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Common.Mapping.UsersManagement.Users;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
/// <summary>
/// Handler for the query to retrieve the list of users.
/// </summary>
public class GetUsersQueryHandler : IRequestHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
private readonly IUserRepository _userRepository;
/// <summary>
/// Initializes a new instance of the <see cref="GetUsersQueryHandler"/> class.
/// </summary>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
public GetUsersQueryHandler(IAuthorizationService authorizationService, ICurrentUserService currentUserService, IUnitOfWork unitOfWork)
{
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_userRepository = unitOfWork.GetRepository<IUserRepository>();
}
/// <summary>
/// Handles the query to retrieve the list of users.
/// </summary>
/// <param name="request">The request to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="UserResponse"/>, or an error message.
/// </returns>
public async ValueTask<ErrorOr<IEnumerable<UserResponse>>> Handle(GetUsersQuery request, CancellationToken cancellationToken)
{
// only admins can see the list of users
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
if (!isAdmin)
return Errors.Authorization.NotAuthorized;
ErrorOr<IEnumerable<UserEntity>> getRolesResult = await _userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
return getRolesResult.Match(value => ErrorOrFactory.From(value.ToResponses()), errors => errors);
}
}
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
@@ -14,5 +14,6 @@ public static partial class ApiRoutes
public const string LOGIN_ACCOUNT = "/auth/login";
public const string RECOVER_PASSWORD = "/auth/recover-password";
public const string CHANGE_PASSWORD = "/auth/change-password";
public const string USERS = "/auth/users";
}
}
@@ -0,0 +1,122 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.DeleteRole;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteRoleEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteRoleEndpointSummary : Summary<DeleteRoleEndpoint, DeleteRoleRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteRoleEndpointSummary"/> class.
/// </summary>
public DeleteRoleEndpointSummary()
{
Summary = "Deletes an authorization role.";
Description = "Deletes an of authorization role and its associated permissions.";
ExampleRequest = new DeleteRoleRequest(
RoleId: Guid.NewGuid()
);
RequestParam(r => r.RoleId, "The Id of the role. Required.");
Response(204, "The authorization role was successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/roles"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/roles"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/roles"
}
}
);
Response(403, "The request failed because the Admin role cannot be deleted, or current user is not an Admin.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "AdminRoleCannotBeDeleted",
instance = "/api/v1/roles",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/roles",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(404, "The request failed because the provided role does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "RoleNotFound",
instance = "/api/v1/roles",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/roles",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"RoleIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -115,6 +115,7 @@ public class UpdateRoleEndpointSummary : Summary<UpdateRoleEndpoint, UpdateRoleR
{
"General.Validation", new[]
{
"RoleIdCannotBeEmpty",
"RoleNameCannotBeNull",
"RoleNameCannotBeEmpty",
"PermissionsListCannotBeNull",
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Lumina.Presentation.Api.Common.Routes.UsersManagement;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Mediator;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
/// <summary>
/// API endpoint for the <c>/auth/users</c> route.
/// </summary>
public class GetUsersEndpoint : BaseEndpoint<EmptyRequest, IResult>
{
private readonly ISender _sender;
/// <summary>
/// Initializes a new instance of the <see cref="GetUsersEndpoint"/> class.
/// </summary>
/// <param name="sender">Injected service for mediating commands and queries.</param>
public GetUsersEndpoint(ISender sender)
{
_sender = sender;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Authentication.USERS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the list of authorization roles.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(EmptyRequest _, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<UserResponse>> result = await _sender.Send(new GetUsersQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,15 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Presentation.Web.Common.Models.UsersManagement;
/// <summary>
/// Represents a model for a user.
/// </summary>
/// <param name="Id">The Id of the user.</param>
/// <param name="Username">The username of the user.</param>
public record UserModel(
Guid Id,
string Username
);
@@ -2,6 +2,7 @@
using Lumina.Presentation.Web.Common.Api;
using Lumina.Presentation.Web.Common.Attributes;
using Lumina.Presentation.Web.Common.Models.Authorization;
using Lumina.Presentation.Web.Common.Models.UsersManagement;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
@@ -50,7 +51,8 @@ public class AdminController : Controller
[HttpGet("manage-permissions")]
public async Task<IActionResult> ManagePermissions(CancellationToken cancellationToken)
{
ViewData["Roles"] = await _apiHttpClient.GetAsync<RoleModel>($"roles/", cancellationToken).ConfigureAwait(false);
ViewData["users"] = await _apiHttpClient.GetAsync<UserModel[]>($"auth/users", cancellationToken).ConfigureAwait(false);
ViewData["roles"] = await _apiHttpClient.GetAsync<RoleModel[]>($"roles/", cancellationToken).ConfigureAwait(false);
return View();
}
@@ -94,7 +96,7 @@ public class AdminController : Controller
/// </summary>
/// <param name="model">The model containing the data of the role to be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
[HttpPost("update-role")]
[HttpPut("update-role")]
public async Task<IActionResult> UpdateRole([FromBody] UpdateRoleRequestModel model, CancellationToken cancellationToken)
{
RolePermissionsModel response = await _apiHttpClient.PutAsync<RolePermissionsModel, UpdateRoleRequestModel>($"roles/", model, cancellationToken).ConfigureAwait(false);
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Administrator-Konto wurde bereits erstellt!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Die Admin-Rolle kann nicht gelöscht werden!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Anwendungsdesign darf nicht leer sein!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Admin account already created!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Admin role cannot be deleted!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Application theme cannot be empty!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>¡La cuenta de administrador ya está creada!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>¡El rol de administrador no puede ser eliminado!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>¡El tema de la aplicación no puede estar vacío!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Le compte administrateur existe déjà!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Le rôle d'administrateur ne peut pas être supprimé !</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Le thème de l'application ne peut pas être vide!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>L'account amministratore è già stato creato!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Il ruolo di amministratore non può essere eliminato!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Il tema dell'applicazione non può essere vuoto!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>管理者アカウントは既に作成されています!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>管理者ロールは削除できません!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>アプリケーションのテーマを選択してください!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Admin account already created!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Admin role cannot be deleted!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Application theme cannot be empty!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Contul de administrator a fost deja creat!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Rolul de administrator nu poate fi șters!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Tema aplicației nu poate fi goală!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>Учетная запись администратора уже создана!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>Роль администратора не может быть удалена!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>Тема приложения не может быть пустой!</value>
</data>
@@ -120,6 +120,9 @@
<data name="AdminAccountAlreadyCreated" xml:space="preserve">
<value>管理员账号已创建!</value>
</data>
<data name="AdminRoleCannotBeDeleted" xml:space="preserve">
<value>管理员角色无法删除!</value>
</data>
<data name="Application theme cannot be empty!" xml:space="preserve">
<value>应用主题不能为空!</value>
</data>
@@ -438,6 +441,9 @@
<data name="ReReleaseYearMustBeBetween1And9999" xml:space="preserve">
<value>重发行年份必须在1到9999之间!</value>
</data>
<data name="RoleAlreadyExists" xml:space="preserve">
<value>角色已存在!</value>
</data>
<data name="RoleCategoryCannotBeEmpty" xml:space="preserve">
<value>角色类别不能为空!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Rolle löschen</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Sind Sie sicher, dass Sie die ausgewählte Rolle löschen möchten?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>Die Rolle wurde erstellt!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Delete role</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Are you sure you want to delete the selected role?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>The role has been created!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Eliminar rol</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>¿Está seguro de que desea eliminar el rol seleccionado?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>¡El rol ha sido creado!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Supprimer le rôle</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Êtes-vous sûr de vouloir supprimer le rôle sélectionné ?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>Le rôle a été créé !</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Elimina ruolo</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Sei sicuro di voler eliminare il ruolo selezionato?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>Il ruolo è stato creato!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>ロールを削除する</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>選択したロールを削除してもよろしいですか?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>ロールが作成されました!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Delete role</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Are you sure you want to delete the selected role?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>The role has been created!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Ștergere rol</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Sunteți sigur că doriți să ștergeți rolul selectat?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>Rolul a fost creat!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>Удалить роль</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>Вы уверены, что хотите удалить выбранную роль?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>Роль была создана!</value>
</data>
@@ -132,6 +132,9 @@
<data name="DeleteRole" xml:space="preserve">
<value>删除角色</value>
</data>
<data name="DeleteRoleConfirm" xml:space="preserve">
<value>您确定要删除选定的角色吗?</value>
</data>
<data name="RoleCreated" xml:space="preserve">
<value>角色已创建!</value>
</data>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Abbrechen</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Abbrechen</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Bestätigung</value>
</data>
<data name="Error" xml:space="preserve">
<value>Fehler</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignorieren</value>
</data>
<data name="Information" xml:space="preserve">
<value>Information</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigation fehlgeschlagen!</value>
</data>
<data name="No" xml:space="preserve">
<value>Nein</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Wiederholen</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Vollhöhe Umschalten</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Sichtbarkeit Umschalten</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Warnung</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Ja</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Abort</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmation</value>
</data>
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignore</value>
</data>
<data name="Information" xml:space="preserve">
<value>Information</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigation failed!</value>
</data>
<data name="No" xml:space="preserve">
<value>No</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Retry</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Toggle Full Height</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Toggle Visibility</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Warning</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Yes</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Anular</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancelar</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmación</value>
</data>
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignorar</value>
</data>
<data name="Information" xml:space="preserve">
<value>Información</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>¡Navegación fallida!</value>
</data>
<data name="No" xml:space="preserve">
<value>No</value>
</data>
<data name="Ok" xml:space="preserve">
<value>Aceptar</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Reintentar</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Alternar Altura Completa</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Alternar Visibilidad</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Advertencia</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Sí</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Abandonner</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Annuler</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmation</value>
</data>
<data name="Error" xml:space="preserve">
<value>Erreur</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignorer</value>
</data>
<data name="Information" xml:space="preserve">
<value>Information</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigation échouée !</value>
</data>
<data name="No" xml:space="preserve">
<value>Non</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Réessayer</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Basculer Hauteur Complète</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Basculer Visibilité</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Avertissement</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Oui</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Interrompi</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Annulla</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Conferma</value>
</data>
<data name="Error" xml:space="preserve">
<value>Errore</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignora</value>
</data>
<data name="Information" xml:space="preserve">
<value>Informazione</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigazione fallita!</value>
</data>
<data name="No" xml:space="preserve">
<value>No</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Riprova</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Attiva/Disattiva Altezza Piena</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Attiva/Disattiva Visibilità</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Avviso</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Sì</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>中止する</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>キャンセル</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>確認</value>
</data>
<data name="Error" xml:space="preserve">
<value>エラー</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>無視する</value>
</data>
<data name="Information" xml:space="preserve">
<value>情報</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>ナビゲーションに失敗しました!</value>
</data>
<data name="No" xml:space="preserve">
<value>いいえ</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>再試行</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>全高表示切替</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>表示切替</value>
</data>
<data name="Warning" xml:space="preserve">
<value>警告</value>
</data>
<data name="Yes" xml:space="preserve">
<value>はい</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Abort</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmation</value>
</data>
<data name="Error" xml:space="preserve">
<value>Error</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignore</value>
</data>
<data name="Information" xml:space="preserve">
<value>Information</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigation failed!</value>
</data>
<data name="No" xml:space="preserve">
<value>No</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Retry</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Toggle Full Height</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Toggle Visibility</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Warning</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Yes</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Anulare</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Anulare</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Confirmare</value>
</data>
<data name="Error" xml:space="preserve">
<value>Eroare</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Ignorare</value>
</data>
<data name="Information" xml:space="preserve">
<value>Informație</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Navigarea a eșuat!</value>
</data>
<data name="No" xml:space="preserve">
<value>Nu</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Reîncercare</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Comutare Înălțime Completă</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Comutare Vizibilitate</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Avertizare</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Da</value>
</data>
</root>
@@ -117,13 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>Прервать</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>Отмена</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>Подтверждение</value>
</data>
<data name="Error" xml:space="preserve">
<value>Ошибка</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>Игнорировать</value>
</data>
<data name="Information" xml:space="preserve">
<value>Информация</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>Навигация не удалась!</value>
</data>
<data name="No" xml:space="preserve">
<value>Нет</value>
</data>
<data name="Ok" xml:space="preserve">
<value>OK</value>
</data>
<data name="Retry" xml:space="preserve">
<value>Повторить</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>Переключить Полную Высоту</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>Переключить Видимость</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Предупреждение</value>
</data>
<data name="Yes" xml:space="preserve">
<value>Да</value>
</data>
</root>
@@ -117,10 +117,46 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Abort" xml:space="preserve">
<value>中止</value>
</data>
<data name="Cancel" xml:space="preserve">
<value>取消</value>
</data>
<data name="Confirmation" xml:space="preserve">
<value>确认</value>
</data>
<data name="Error" xml:space="preserve">
<value>错误</value>
</data>
<data name="Ignore" xml:space="preserve">
<value>忽略</value>
</data>
<data name="Information" xml:space="preserve">
<value>信息</value>
</data>
<data name="NavigationFailed" xml:space="preserve">
<value>导航失败!</value>
</data>
<data name="No" xml:space="preserve">
<value>否</value>
</data>
<data name="Ok" xml:space="preserve">
<value>确定</value>
</data>
<data name="Retry" xml:space="preserve">
<value>重试</value>
</data>
<data name="ToggleFullHeight" xml:space="preserve">
<value>切换全高</value>
</data>
<data name="ToggleVisibility" xml:space="preserve">
<value>切换可见性</value>
</data>
<data name="Warning" xml:space="preserve">
<value>警告</value>
</data>
<data name="Yes" xml:space="preserve">
<value>是</value>
</data>
</root>
@@ -110,9 +110,10 @@
};
const isRoleSelected = formData.roleId !== '';
const url = isRoleSelected ? '@_urlService.GetAbsoluteUrl("UpdateRole", "Admin")' : '@_urlService.GetAbsoluteUrl("CreateRole", "Admin")';
const data = await callApiPostAsync(url, formData);
const data = isRoleSelected ?
await callApiPutAsync('@_urlService.GetAbsoluteUrl("UpdateRole", "Admin")', formData) :
await callApiPostAsync('@_urlService.GetAbsoluteUrl("CreateRole", "Admin")', formData);
if (data) {
await fetchRoles();
notificationService.show(isRoleSelected ? '@_localizer["RoleUpdated"]' : '@_localizer["RoleCreated"]', NotificationType.SUCCESS);
@@ -121,21 +122,15 @@
btnDeleteRole.addEventListener('click', async function(e) {
const roleId = document.getElementById('authorization-roles-selected-id').value;
// const confirmDelete = await showDialog(
// translationService.Translate(Terms.ConfirmRoleDelete),
// translationService.Translate(Terms.Confirmation),
// 'YES_NO'
// );
// if (confirmDelete) {
const url = '@_urlService.GetAbsoluteUrl("DeleteRole", "Admin", new { roleId = default(Guid) })';
const success = await callApiDeleteAsync(url.replace('/@(default(Guid))', `/${roleId}`)); // roleId needs to be replaced here, because GetAbsoluteUrl is server side, roleId is client side
if (success) {
await fetchRoles();
notificationService.show('@_localizer["RoleDeleted"]', NotificationType.SUCCESS);
}
// }
// ask the user for confirmation before deleting the role
if (await dialogService.show('@_localizer["DeleteRoleConfirm"]', jsLocalizedDialogs.confirmation, DialogButtons.YES_NO_CANCEL, DialogIcon.QUESTION) === DialogButton.YES) {
const url = '@_urlService.GetAbsoluteUrl("DeleteRole", "Admin", new { roleId = default(Guid) })';
const success = await callApiDeleteAsync(url.replace('/@(default(Guid))', `/${roleId}`)); // roleId needs to be replaced here, because GetAbsoluteUrl is server side, roleId is client side
if (success) {
await fetchRoles();
notificationService.show('@_localizer["RoleDeleted"]', NotificationType.SUCCESS);
}
}
});
// on role dropdown change
@@ -16,6 +16,7 @@
<link rel="stylesheet" href="~/css/file-system-tree-view-node.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/navigation-menu.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/notification.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/dialog.css" asp-append-version="true" />
<link rel="stylesheet" href="~/css/textbox.css" asp-append-version="true" />
<link rel="stylesheet" href="~/Lumina.Presentation.Web.styles.css" asp-append-version="true" />
</head>
@@ -51,8 +52,25 @@
var jsLocalizedMessages = {
navigationFailed: '@_localizer["NavigationFailed"]',
};
var jsLocalizedDialogs = {
// button texts
ok: '@_localizer["Ok"]',
cancel: '@_localizer["Cancel"]',
yes: '@_localizer["Yes"]',
no: '@_localizer["No"]',
retry: '@_localizer["Retry"]',
abort: '@_localizer["Abort"]',
ignore: '@_localizer["Ignore"]',
// default titles
confirmation: '@_localizer["Confirmation"]',
warning: '@_localizer["Warning"]',
error: '@_localizer["Error"]',
information: '@_localizer["Information"]'
};
</script>
<script defer src="~/js/notifications.js" asp-append-version="true"></script>
<script defer src="~/js/dialogs.js" asp-append-version="true"></script>
<script defer src="~/js/site.js" asp-append-version="true"></script>
<div data-section="scripts">
@await RenderSectionAsync("Scripts", required: false)
@@ -0,0 +1,121 @@
.dialog-modal-background {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #000000;
opacity: 0.6;
z-index: 1998;
}
.dialog-container {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 999;
width: 400px;
max-width: 90%;
}
.dialog {
background: linear-gradient(135deg, #404040, #232323);
border-radius: 4px;
border-top: 1px solid #505050;
border-left: 1px solid #505050;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
box-shadow: 5px 5px 5px var(--shadow-color);
overflow: hidden;
animation: fadeIn 0.3s ease-out;
position: relative;
}
.dialog-content {
padding: 20px;
}
.dialog-header {
padding-bottom: 15px;
border-bottom: 1px solid #000;
position: relative;
}
.dialog-header h2 {
margin: 0;
color: var(--text-foreground);
font-family: monospace;
font-size: 1.1rem;
}
.dialog-shine-effect {
background: linear-gradient(to right, transparent, #fff, transparent);
width: 100%;
top: -1px;
height: 1px;
position: absolute;
pointer-events: none;
}
.dialog-body {
padding: 20px;
color: var(--text-foreground);
font-family: monospace;
display: flex;
gap: 15px;
align-items: flex-start;
}
.dialog-icon {
width: 24px;
height: 24px;
flex-shrink: 0;
}
.dialog-icon.info {
background-image: url('path-to-info-icon.svg');
}
.dialog-icon.warning {
background-image: url('path-to-warning-icon.svg');
}
.dialog-icon.error {
background-image: url('path-to-error-icon.svg');
}
.dialog-icon.question {
background-image: url('path-to-question-icon.svg');
}
.dialog-message {
flex-grow: 1;
word-wrap: break-word;
overflow-wrap: break-word;
word-break: break-word;
hyphens: auto;
white-space: pre-wrap;
}
.dialog-buttons {
display: flex;
justify-content: flex-end;
padding-top: 15px;
gap: 10px;
border-top: 1px solid #000;
}
.dialog-button {
padding: 2px 16px;
font-weight: 500;
}
@keyframes dialogAppear {
to {
opacity: 1;
transform: translateY(0);
}
}
@@ -0,0 +1,182 @@
/**
* Enum-like object for dialog buttons.
* @readonly
* @enum {string}
*/
const DialogButton = {
OK: 'ok',
CANCEL: 'cancel',
YES: 'yes',
NO: 'no',
RETRY: 'retry',
ABORT: 'abort',
IGNORE: 'ignore'
};
/**
* Enum-like object for dialog icons.
* @readonly
* @enum {string}
*/
const DialogIcon = {
NONE: 'none',
INFO: 'info',
WARNING: 'warning',
ERROR: 'error',
QUESTION: 'question'
};
/**
* Enum-like object for predefined button combinations.
* @readonly
* @enum {Array<DialogButton>}
*/
const DialogButtons = {
OK: [DialogButton.OK],
OK_CANCEL: [DialogButton.OK, DialogButton.CANCEL],
YES_NO: [DialogButton.YES, DialogButton.NO],
YES_NO_CANCEL: [DialogButton.YES, DialogButton.NO, DialogButton.CANCEL],
RETRY_CANCEL: [DialogButton.RETRY, DialogButton.CANCEL],
ABORT_RETRY_IGNORE: [DialogButton.ABORT, DialogButton.RETRY, DialogButton.IGNORE]
};
/**
* Manages the creation and display of modal dialogs.
*/
class DialogService {
constructor() {
this.dialogQueue = [];
this.isDialogOpen = false;
// create dialog container inside the article element
const articleElement = document.querySelector('article');
this.container = document.createElement('div');
this.container.className = 'dialog-container';
articleElement.appendChild(this.container);
}
/**
* Shows a modal dialog and returns a Promise that resolves with the clicked button.
* @param {string} message - The message to display in the dialog.
* @param {string} title - The title of the dialog.
* @param {Array<DialogButton>} buttons - Array of buttons to display.
* @param {DialogIcon} icon - The icon to display.
* @returns {Promise<DialogButton>} A promise that resolves with the clicked button.
*/
show(message, title = jsLocalizedDialogs.confirmation, buttons = DialogButtons.OK, icon = DialogIcon.NONE) {
const dialogPromise = new Promise((resolve) => {
const dialog = {
message,
title,
buttons,
icon,
resolve
};
this.dialogQueue.push(dialog);
if (!this.isDialogOpen)
this.showNextDialog();
});
return dialogPromise;
}
/**
* Shows the next dialog in the queue.
* @private
*/
showNextDialog() {
if (this.dialogQueue.length === 0) {
this.isDialogOpen = false;
return;
}
this.isDialogOpen = true;
const dialog = this.dialogQueue[0];
this.displayDialog(dialog);
}
/**
* Creates and displays a dialog element in the DOM.
* @private
* @param {Object} dialog - The dialog configuration object.
*/
displayDialog(dialog) {
const modalBackground = document.getElementById('modal-background-article');
modalBackground.style.display = 'block';
this.container.style.display = 'block';
const dialogElement = document.createElement('div');
dialogElement.className = 'dialog';
dialogElement.innerHTML = `
<div class="dialog-content">
<div class="dialog-header">
<h2>${dialog.title}</h2>
</div>
<div class="dialog-body">
${dialog.icon !== DialogIcon.NONE ? `<div class="dialog-icon ${dialog.icon}"></div>` : ''}
<div class="dialog-message">${dialog.message}</div>
</div>
<div class="dialog-buttons">
${dialog.buttons.map(button =>
`<button class="dialog-button ${button === 'yes' || button === 'ok' ? 'confirm-button' : 'abort-button'}" data-button="${button}">
${this.getLocalizedButtonText(button)}
</button>`
).join('')}
</div>
</div>
`;
// add click handlers for buttons
const buttons = dialogElement.querySelectorAll('.dialog-button');
buttons.forEach(button => {
button.addEventListener('click', () => this.handleButtonClick(button.dataset.button));
});
// add keyboard support
const keyHandler = (e) => {
if (e.key === 'Escape' && dialog.buttons.includes(DialogButton.CANCEL))
this.handleButtonClick(DialogButton.CANCEL);
if (e.key === 'Enter' && dialog.buttons.includes(DialogButton.OK))
this.handleButtonClick(DialogButton.OK);
};
document.addEventListener('keydown', keyHandler);
this.container.appendChild(dialogElement);
}
/**
* Handles button clicks and resolves the dialog promise.
* @private
* @param {DialogButton} buttonType - The type of button clicked.
*/
handleButtonClick(buttonType) {
const currentDialog = this.dialogQueue.shift();
const dialogElement = this.container.querySelector('.dialog');
if (dialogElement)
dialogElement.remove();
if (this.dialogQueue.length === 0) {
const modalBackground = document.getElementById('modal-background-article');
modalBackground.style.display = 'none';
this.container.style.display = 'none';
}
currentDialog.resolve(buttonType);
this.showNextDialog();
}
/**
* Gets the localized text for a button type.
* @private
* @param {DialogButton} buttonType - The button type.
* @returns {string} The localized button text.
*/
getLocalizedButtonText(buttonType) {
return jsLocalizedDialogs[buttonType.toLowerCase()] || buttonType;
}
}
// create a global instance of the DialogService
const dialogService = new DialogService();