Сериализация сущностей для отображения в веб-интерфейсе
This commit is contained in:
@@ -5,41 +5,33 @@
|
||||
ViewData["Title"] = "Entity";
|
||||
}
|
||||
|
||||
<h1>Entity</h1>
|
||||
<h1>Entity: @Model.FullEntity.Entity.Name</h1>
|
||||
|
||||
<div>
|
||||
<h4>Class</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Entity.Entity)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Entity.Entity.Description)
|
||||
</dd>
|
||||
@* <dt class="col-sm-2"> *@
|
||||
@* @Html.DisplayNameFor(model => model.Entity.Hp) *@
|
||||
@* </dt> *@
|
||||
@* <dd class="col-sm-10"> *@
|
||||
@* @Html.DisplayFor(model => model.Entity.Hp) *@
|
||||
@* </dd> *@
|
||||
@* <dt class="col-sm-2"> *@
|
||||
@* @Html.DisplayNameFor(model => model.Entity.Spellcasting) *@
|
||||
@* </dt> *@
|
||||
@* <dd class="col-sm-10"> *@
|
||||
@* @Html.DisplayFor(model => model.Entity.Spellcasting) *@
|
||||
@* </dd> *@
|
||||
@* <dt class="col-sm-2"> *@
|
||||
@* @Html.DisplayNameFor(model => model.Entity.Tradition) *@
|
||||
@* </dt> *@
|
||||
@* <dd class="col-sm-10"> *@
|
||||
@* @Html.DisplayFor(model => model.Entity.Tradition) *@
|
||||
@* </dd> *@
|
||||
@* <dt class="col-sm-2"> *@
|
||||
@* @Html.DisplayNameFor(model => model.Entity.AdditionalTrainedSkills) *@
|
||||
@* </dt> *@
|
||||
@* <dd class="col-sm-10"> *@
|
||||
@* @Html.DisplayFor(model => model.Entity.AdditionalTrainedSkills) *@
|
||||
@* </dd> *@
|
||||
</dl>
|
||||
</div>
|
||||
@foreach (var group in Model.SerializationResult.Groups)
|
||||
{
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<h5>@group.Name</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row">
|
||||
@foreach (var field in group.Fields)
|
||||
{
|
||||
<dt class="col-sm-3">@field.Name</dt>
|
||||
<dd class="col-sm-9">
|
||||
<span class="text-muted">[@field.Type]</span>
|
||||
@if (field.IsImplemented)
|
||||
{
|
||||
@Html.Raw(field.DisplayValue)
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-warning text-dark">НЕ РЕАЛИЗОВАНО:</span>
|
||||
@Html.Raw(field.DisplayValue)
|
||||
}
|
||||
</dd>
|
||||
}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -5,60 +5,46 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pf2e.Common;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Database.Model;
|
||||
using Pf2e.Database.Model.Base;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
using Pf2e.Database.Model.Structure;
|
||||
using Pf2e.Web.Helpers;
|
||||
|
||||
namespace Pf2e.Web.Pages
|
||||
{
|
||||
public class EntityModel : PageModel
|
||||
public class EntityModel(Pf2eDbContext context) : PageModel
|
||||
{
|
||||
private readonly Pf2e.Database.Pf2eDbContext _context;
|
||||
private readonly Pf2eDbContext _context = context;
|
||||
|
||||
public EntityModel(Pf2e.Database.Pf2eDbContext context)
|
||||
public FullEntity FullEntity { get; set; } = null!;
|
||||
public EntitySerializer.SerializationResult SerializationResult { get; set; } = null!;
|
||||
|
||||
public IActionResult OnGet(string type, string slug)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
// Получаем тип сущности
|
||||
EntityType entityType = EntityTypeModel.Enum<EntityType>(type);
|
||||
|
||||
public IEntity Entity;
|
||||
// Находим сущность по slug и типу
|
||||
Entity? entity = _context.Entities.FirstOrDefault(e =>
|
||||
e.Slug == slug && e.Type == entityType
|
||||
);
|
||||
|
||||
public Dictionary<string, string> Fields = [];
|
||||
|
||||
public Dictionary<string, List<Entity>> References = [];
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(string type, string slug)
|
||||
{
|
||||
Entity entity =
|
||||
_context
|
||||
.Entities.Where(e =>
|
||||
e.Slug == slug && e.Type == EntityTypeModel.Enum<EntityType>(type)
|
||||
)
|
||||
.Include(e => e.Sources)
|
||||
.ThenInclude(s => s.Source)
|
||||
.Include(e => e.Keywords)
|
||||
.Include(e => e.Externals)
|
||||
.ThenInclude(x => x.Target)
|
||||
.Include(e => e.Traits)
|
||||
.ThenInclude(t => t.Entity)
|
||||
.FirstOrDefault() ?? throw new("Entity is null");
|
||||
/*
|
||||
if (id == null)
|
||||
if (entity == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var class = await _context.Classes.FirstOrDefaultAsync(m => m.Id == id);
|
||||
// Создаём FullEntity
|
||||
FullEntity = new(_context, entity);
|
||||
|
||||
if (class is not null)
|
||||
{
|
||||
Class = class;
|
||||
// Сериализуем для отображения
|
||||
EntitySerializer serializer = new();
|
||||
SerializationResult = serializer.Serialize(FullEntity);
|
||||
|
||||
return Page();
|
||||
}
|
||||
*/
|
||||
return NotFound();
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-page="./Details" asp-route-id="@item.Id">
|
||||
<a asp-page="./Entity" asp-route-type="@item.Type" asp-route-slug="@item.Slug">
|
||||
@Html.DisplayFor(modelItem => item.Name[LocaleType.English])
|
||||
</a>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user