Обновления веб-отображения

This commit is contained in:
2025-10-07 00:12:20 +04:00
parent aecabfbb56
commit 5df20825c7
12 changed files with 377 additions and 201 deletions
+7 -9
View File
@@ -1,4 +1,4 @@
@page "{type}/{slug}"
@page "/{type}/{slug}"
@model Pf2e.Web.Pages.EntityModel
@{
@@ -17,18 +17,16 @@
<dl class="row">
@foreach (var field in group.Fields)
{
<dt class="col-sm-3">@field.Name</dt>
<dt class="col-sm-3">
@field.Name
<span class="text-muted">[@field.Type]</span>
</dt>
<dd class="col-sm-9">
<span class="text-muted">[@field.Type]</span>
@if (field.IsImplemented)
{
@Html.Raw(field.DisplayValue)
}
else
@if (!field.IsImplemented)
{
<span class="badge bg-warning text-dark">НЕ РЕАЛИЗОВАНО:</span>
@Html.Raw(field.DisplayValue)
}
@Html.Raw(field.DisplayValue)
</dd>
}
</dl>
+34 -8
View File
@@ -26,39 +26,65 @@ namespace Pf2e.Web.Pages
public IActionResult OnGet(string type, string slug)
{
// Добавим отладочную информацию
System.Diagnostics.Debug.WriteLine($"EntityModel.OnGet called with type: {type}, slug: {slug}");
System.Diagnostics.Debug.WriteLine(
$"EntityModel.OnGet called with type: {type}, slug: {slug}"
);
// Логируем в консоль для веб-сервера
Console.WriteLine($"EntityModel.OnGet called with type: {type}, slug: {slug}");
try
{
// Получаем тип сущности
EntityType entityType = EntityTypeModel.Enum<EntityType>(type);
System.Diagnostics.Debug.WriteLine($"EntityType resolved to: {entityType}");
Console.WriteLine($"EntityType resolved to: {entityType}");
// Находим сущность по slug и типу
Entity? entity = _context.Entities.FirstOrDefault(e =>
e.Slug.ToLower() == slug.ToLower() && e.Type == entityType
);
Entity? entity = _context
.Entities.AsNoTracking()
.FirstOrDefault(e =>
e.Slug.ToLower() == slug.ToLower() && e.Type == entityType
);
if (entity == null)
{
System.Diagnostics.Debug.WriteLine($"Entity not found: type={entityType}, slug={slug}");
System.Diagnostics.Debug.WriteLine(
$"Entity not found: type={entityType}, slug={slug}"
);
Console.WriteLine($"Entity not found: type={entityType}, slug={slug}");
return NotFound();
}
System.Diagnostics.Debug.WriteLine($"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}");
System.Diagnostics.Debug.WriteLine(
$"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}"
);
Console.WriteLine(
$"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}"
);
// Создаём FullEntity
FullEntity = new(_context, entity);
FullEntity = new(_context, entityType, entity.Id);
// Сериализуем для отображения
EntitySerializer serializer = new();
SerializationResult = serializer.Serialize(FullEntity);
// Set breadcrumbs
var typeName = Pf2e.Web.Helpers.PgNameHelper.GetPgName(entityType);
ViewData["Breadcrumbs"] = new List<(string, string)>
{
("Home", "/"),
(entityType.ToString(), $"/{typeName}"),
(entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English], "")
};
return Page();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error in EntityModel.OnGet: {ex.Message}");
Console.WriteLine($"Error in EntityModel.OnGet: {ex.Message}");
return NotFound();
}
}
+23 -20
View File
@@ -10,24 +10,15 @@ using Pf2e.Database;
using Pf2e.Database.Model.Base;
using Pf2e.Database.Model.Enum;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Pf2e.Web.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class EntityTypeModel : PageModel
public class EntityTypeModel(Pf2eDbContext context) : PageModel
{
private readonly Pf2eDbContext _context;
public EntityTypeModel(Pf2eDbContext context)
{
_context = context;
}
[BindProperty(SupportsGet = true)]
public int? PageNum { get; set; } = 1;
public IList<Entity> Entity { get; set; } = default!;
public IList<Entity> Entity { get; set; } = null!;
public EntityType CurrentType;
@@ -41,7 +32,7 @@ namespace Pf2e.Web.Pages
{
// Добавим отладочную информацию
System.Diagnostics.Debug.WriteLine($"EntityTypeModel.OnGet called with type: {type}");
try
{
CurrentType = Enum<EntityType>(type);
@@ -53,18 +44,26 @@ namespace Pf2e.Web.Pages
return NotFound();
}
int count = _context.Entities.Count(entity => entity.Type == CurrentType);
int count = context.Entities.Count(entity => entity.Type == CurrentType);
System.Diagnostics.Debug.WriteLine($"Count for {CurrentType}: {count}");
LastPage = (int)Math.Ceiling(count / (double)PerPage);
Entity = _context
Entity = context
.Entities.Where(entity => entity.Type == CurrentType)
.Skip((CurrentPage - 1) * PerPage)
.Take(PerPage)
.ToList();
System.Diagnostics.Debug.WriteLine($"Returning page with {Entity.Count} entities");
// Set breadcrumbs
ViewData["Breadcrumbs"] = new List<(string, string)>
{
("Home", "/"),
(CurrentType.ToString(), ""),
};
return Page();
}
@@ -72,12 +71,14 @@ namespace Pf2e.Web.Pages
/// Преобразование значения из JSON в перечисление.
/// </summary>
/// <param name="value">Значение, которое нужно преобразовать</param>
/// <returns>Объект типа `T`, если преобразование успешно, иначе выбрасывает исключение</returns>
/// <returns>Объект типа <c>T</c>, если преобразование успешно, иначе выбрасывает исключение</returns>
public static T Enum<T>(string value)
where T : Enum
{
System.Diagnostics.Debug.WriteLine($"Trying to resolve enum value: {value} for type {typeof(T)}");
System.Diagnostics.Debug.WriteLine(
$"Trying to resolve enum value: {value} for type {typeof(T)}"
);
foreach (System.Reflection.FieldInfo field in typeof(T).GetFields())
{
List<string> variants = [field.Name];
@@ -90,8 +91,10 @@ namespace Pf2e.Web.Pages
variants.Add(pgAttribute.PgName);
}
System.Diagnostics.Debug.WriteLine($"Checking field: {field.Name}, variants: {string.Join(", ", variants)}");
System.Diagnostics.Debug.WriteLine(
$"Checking field: {field.Name}, variants: {string.Join(", ", variants)}"
);
if (variants.Contains(value))
{
System.Diagnostics.Debug.WriteLine($"Matched field: {field.Name}");
+5
View File
@@ -24,5 +24,10 @@ public class IndexModel : PageModel
Data = Context
.Entities.GroupBy(e => e.Type)
.ToDictionary(entities => entities.Key, entities => entities.Count());
ViewData["Breadcrumbs"] = new List<(string, string)>
{
("Home", "")
};
}
}
+5
View File
@@ -13,6 +13,11 @@ public class PrivacyModel : PageModel
public void OnGet()
{
ViewData["Breadcrumbs"] = new List<(string, string)>
{
("Home", "/"),
("Privacy Policy", "")
};
}
}
+22
View File
@@ -32,6 +32,28 @@
</nav>
</header>
<div class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
@if (ViewData["Breadcrumbs"] != null)
{
@foreach (var crumb in (List<(string, string)>)ViewData["Breadcrumbs"]!)
{
if (!string.IsNullOrEmpty(crumb.Item2))
{
<li class="breadcrumb-item"><a href="@crumb.Item2">@crumb.Item1</a></li>
}
else
{
<li class="breadcrumb-item active" aria-current="page">@crumb.Item1</li>
}
}
}
else
{
<li class="breadcrumb-item active" aria-current="page">Home</li>
}
</ol>
</nav>
<main role="main" class="pb-3">
@RenderBody()
</main>