Глобальный рефакторинг пространств имён
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
@page
|
||||
@model Pf2e.Web.Pages.EntityModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Entity";
|
||||
}
|
||||
|
||||
<h1>Entity</h1>
|
||||
|
||||
<div>
|
||||
<h4>Class</h4>
|
||||
<hr />
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Class.Entity)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Class.Entity.Description)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Class.Hp)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Class.Hp)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Class.Spellcasting)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Class.Spellcasting)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Class.Tradition)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Class.Tradition)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Class.AdditionalTrainedSkills)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Class.AdditionalTrainedSkills)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Database.Model;
|
||||
using Pf2e.Database.Model.Base;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
using Pf2e.Database.Model.Structure;
|
||||
|
||||
namespace Pf2e.Web.Pages
|
||||
{
|
||||
public class EntityModel : PageModel
|
||||
{
|
||||
private readonly Pf2e.Database.Pf2eDbContext _context;
|
||||
|
||||
public EntityModel(Pf2e.Database.Pf2eDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IEntity Entity;
|
||||
|
||||
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)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var class = await _context.Classes.FirstOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if (class is not null)
|
||||
{
|
||||
Class = class;
|
||||
|
||||
return Page();
|
||||
}
|
||||
*/
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
@page
|
||||
@using Pf2e.Database.Model.Common.I18n
|
||||
@model EntityTypeModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Entities — " + Model.CurrentType;
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].Id)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].Name)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].Type)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].Slug)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].Rarity)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].IsTranslated)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].IsChecked)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Entity[0].IsLegacy)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Entity)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-page="./Details" asp-route-id="@item.Id">
|
||||
@Html.DisplayFor(modelItem => item.Name[LocaleType.English])
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Type)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Slug)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Rarity)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.IsTranslated)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.IsChecked)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.IsLegacy)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination">
|
||||
<li class="page-item @(Model.CurrentPage == 1 ? "disabled" : "")">
|
||||
<a class="page-link" asp-page="./EntityType" asp-route-type="@Model.CurrentType" asp-route-pageNum="@(Model.CurrentPage - 1)">Previous</a>
|
||||
</li>
|
||||
@foreach (var num in Model.Pagination)
|
||||
{
|
||||
@if (num == Model.CurrentPage)
|
||||
{
|
||||
<li class="page-item active">
|
||||
<a class="page-link" asp-page="./EntityType" asp-route-type="@Model.CurrentType" asp-route-pageNum="@(num)">@num</a>
|
||||
</li>
|
||||
}
|
||||
else if (num == -1)
|
||||
{
|
||||
<li class="page-item disabled">
|
||||
<a class="page-link" href="#">...</a>
|
||||
</li>
|
||||
}
|
||||
else
|
||||
{
|
||||
<li class="page-item">
|
||||
<a class="page-link" asp-page="./EntityType" asp-route-type="@Model.CurrentType" asp-route-pageNum="@(num)">@num</a>
|
||||
</li>
|
||||
}
|
||||
}
|
||||
<li class="page-item @(Model.CurrentPage == Model.LastPage ? "disabled" : "")">
|
||||
<a class="page-link" asp-page="./EntityType" asp-route-type="@Model.CurrentType" asp-route-pageNum="@(Model.CurrentPage + 1)">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NpgsqlTypes;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Database.Model.Base;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
|
||||
namespace Pf2e.Web.Pages
|
||||
{
|
||||
public class EntityTypeModel : PageModel
|
||||
{
|
||||
private readonly Pf2eDbContext _context;
|
||||
|
||||
public EntityTypeModel(Pf2eDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[BindProperty(SupportsGet = true)]
|
||||
public int? PageNum { get; set; }
|
||||
|
||||
public IList<Entity> Entity { get; set; } = default!;
|
||||
|
||||
public EntityType CurrentType;
|
||||
|
||||
public int LastPage;
|
||||
|
||||
public int CurrentPage => PageNum ?? 1;
|
||||
|
||||
public const int PerPage = 30;
|
||||
|
||||
public void OnGet(string type)
|
||||
{
|
||||
CurrentType = Enum<EntityType>(type);
|
||||
|
||||
int count = _context.Entities.Count(entity => entity.Type == CurrentType);
|
||||
|
||||
LastPage = (int)Math.Ceiling(count / (double)PerPage);
|
||||
|
||||
Entity = _context
|
||||
.Entities.Where(entity => entity.Type == CurrentType)
|
||||
.Skip((CurrentPage - 1) * PerPage)
|
||||
.Take(PerPage)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Преобразование значения из JSON в перечисление.
|
||||
/// </summary>
|
||||
/// <param name="value">Значение, которое нужно преобразовать</param>
|
||||
/// <returns>Объект типа `T`, если преобразование успешно, иначе выбрасывает исключение</returns>
|
||||
public static T Enum<T>(string value)
|
||||
where T : Enum
|
||||
{
|
||||
foreach (System.Reflection.FieldInfo field in typeof(T).GetFields())
|
||||
{
|
||||
List<string> variants = [field.Name];
|
||||
|
||||
if (
|
||||
Attribute.GetCustomAttribute(field, typeof(PgNameAttribute))
|
||||
is PgNameAttribute pgAttribute
|
||||
)
|
||||
{
|
||||
variants.Add(pgAttribute.PgName);
|
||||
}
|
||||
|
||||
if (variants.Contains(value))
|
||||
{
|
||||
return (T)field.GetValue(null)!;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"Can't resolve enum value \"{value}\" for type {typeof(T)}");
|
||||
}
|
||||
|
||||
public List<int> Pagination
|
||||
{
|
||||
get
|
||||
{
|
||||
List<int> pages = [1];
|
||||
|
||||
int start = Math.Max(2, CurrentPage - 1);
|
||||
int end = Math.Min(LastPage - 1, CurrentPage + 1);
|
||||
|
||||
if (start > 2)
|
||||
pages.Add(-1);
|
||||
|
||||
for (int i = start; i <= end; i++)
|
||||
pages.Add(i);
|
||||
|
||||
if (end < LastPage - 1)
|
||||
pages.Add(-1);
|
||||
|
||||
if (LastPage > 1)
|
||||
pages.Add(LastPage);
|
||||
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model ErrorModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace Pf2e.Web.Pages;
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
@page
|
||||
@model IndexModel
|
||||
@{
|
||||
ViewData["Title"] = "Home page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Type</td>
|
||||
<td>Rows</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in Model.Data)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<a asp-page="./EntityType" asp-route-type="@row.Key">
|
||||
@row.Key
|
||||
</a>
|
||||
</td>
|
||||
<td>@row.Value</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Pf2e.Database;
|
||||
using Pf2e.Database.Model.Enum;
|
||||
|
||||
namespace Pf2e.Web.Pages;
|
||||
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
|
||||
public readonly Pf2eDbContext Context;
|
||||
|
||||
public Dictionary<EntityType, int> Data { get; set; } = new();
|
||||
|
||||
public IndexModel(ILogger<IndexModel> logger, Pf2eDbContext context)
|
||||
{
|
||||
_logger = logger;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
Data = Context
|
||||
.Entities.GroupBy(e => e.Type)
|
||||
.ToDictionary(entities => entities.Key, entities => entities.Count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@page
|
||||
@model PrivacyModel
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace Pf2e.Web.Pages;
|
||||
public class PrivacyModel : PageModel
|
||||
{
|
||||
private readonly ILogger<PrivacyModel> _logger;
|
||||
|
||||
public PrivacyModel(ILogger<PrivacyModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Pf2eWeb</title>
|
||||
<script type="importmap"></script>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/Pf2eWeb.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">Pf2eWeb</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2025 - Pf2eWeb - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0077cc;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
|
||||
color: #fff;
|
||||
background-color: #1b6ec2;
|
||||
border-color: #1861ac;
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
line-height: 60px;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/dist/jquery.validate.unobtrusive.min.js"></script>
|
||||
@@ -0,0 +1,3 @@
|
||||
@using Pf2e.Web
|
||||
@namespace Pf2e.Web.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
Reference in New Issue
Block a user