web: add basic ASP.NET Core web interface
This commit is contained in:
parent
495edc3c5e
commit
95a7e5e821
26
PluralKit.Web/Pages/Error.cshtml
Normal file
26
PluralKit.Web/Pages/Error.cshtml
Normal file
@ -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>
|
23
PluralKit.Web/Pages/Error.cshtml.cs
Normal file
23
PluralKit.Web/Pages/Error.cshtml.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace PluralKit.Web.Pages
|
||||||
|
{
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
public class ErrorModel : PageModel
|
||||||
|
{
|
||||||
|
public string RequestId { get; set; }
|
||||||
|
|
||||||
|
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
PluralKit.Web/Pages/Index.cshtml
Normal file
10
PluralKit.Web/Pages/Index.cshtml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
@page
|
||||||
|
@model IndexModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Home page";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h1 class="display-4">Welcome</h1>
|
||||||
|
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||||
|
</div>
|
16
PluralKit.Web/Pages/Index.cshtml.cs
Normal file
16
PluralKit.Web/Pages/Index.cshtml.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace PluralKit.Web.Pages
|
||||||
|
{
|
||||||
|
public class IndexModel : PageModel
|
||||||
|
{
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
PluralKit.Web/Pages/Shared/_Layout.cshtml
Normal file
38
PluralKit.Web/Pages/Shared/_Layout.cshtml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>@ViewData["Title"] - PluralKit.Web</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css"/>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: "PT Sans", sans-serif;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<main role="main" class="p-3">
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="border-top footer text-muted">
|
||||||
|
<div class="container">
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
@RenderSection("Scripts", required: false)
|
||||||
|
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/feather-icons/4.21.0/feather.min.js"></script>
|
||||||
|
<script>
|
||||||
|
feather.replace();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
122
PluralKit.Web/Pages/ViewSystem.cshtml
Normal file
122
PluralKit.Web/Pages/ViewSystem.cshtml
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
@page "/s/{systemId}"
|
||||||
|
@model PluralKit.Web.Pages.ViewSystem
|
||||||
|
|
||||||
|
<div class="system">
|
||||||
|
<ul class="taglist">
|
||||||
|
<li>
|
||||||
|
<i data-feather="hash"></i>
|
||||||
|
@Model.System.Hid
|
||||||
|
</li>
|
||||||
|
|
||||||
|
@if (Model.System.Tag != null)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<i data-feather="tag"></i>
|
||||||
|
@Model.System.Tag
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.System.UiTz != null)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<i data-feather="clock"></i>
|
||||||
|
@Model.System.UiTz
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@if (Model.System.Name != null)
|
||||||
|
{
|
||||||
|
<h1>@Model.System.Name</h1>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.System.Description != null)
|
||||||
|
{
|
||||||
|
<p>@Model.System.Description</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Members</h2>
|
||||||
|
@foreach (var member in Model.Members)
|
||||||
|
{
|
||||||
|
<div class="member-card">
|
||||||
|
<div class="member-avatar" style="background-image: url(@(member.AvatarUrl)"></div>
|
||||||
|
<div class="member-body">
|
||||||
|
<span class="member-name">@member.Name</span>
|
||||||
|
<p class="member-description">@member.Description</p>
|
||||||
|
|
||||||
|
<ul class="taglist">
|
||||||
|
<li>
|
||||||
|
<i data-feather="hash"></i>
|
||||||
|
@member.Hid
|
||||||
|
</li>
|
||||||
|
|
||||||
|
@if (member.Birthday != null)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<i data-feather="calendar"></i>
|
||||||
|
@member.BirthdayString
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (member.Pronouns != null)
|
||||||
|
{
|
||||||
|
<li>
|
||||||
|
<i data-feather="message-circle"></i>
|
||||||
|
@member.Pronouns
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<style>
|
||||||
|
.taglist {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
color: #aaa;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.taglist li {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 1rem;
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.taglist .feather {
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: -2px;
|
||||||
|
width: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.member-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.member-avatar {
|
||||||
|
margin: 1.5rem 1rem 0 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
background-size: cover;
|
||||||
|
background-position: top center;
|
||||||
|
flex-basis: 4rem;
|
||||||
|
height: 4rem;
|
||||||
|
border: 4px solid white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.member-body {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 1rem 1rem 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.member-name {
|
||||||
|
font-size: 13pt;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
}
|
32
PluralKit.Web/Pages/ViewSystem.cshtml.cs
Normal file
32
PluralKit.Web/Pages/ViewSystem.cshtml.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
|
||||||
|
namespace PluralKit.Web.Pages
|
||||||
|
{
|
||||||
|
public class ViewSystem : PageModel
|
||||||
|
{
|
||||||
|
private SystemStore _systems;
|
||||||
|
private MemberStore _members;
|
||||||
|
|
||||||
|
public ViewSystem(SystemStore systems, MemberStore members)
|
||||||
|
{
|
||||||
|
_systems = systems;
|
||||||
|
_members = members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PKSystem System { get; set; }
|
||||||
|
public IEnumerable<PKMember> Members { get; set; }
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnGet(string systemId)
|
||||||
|
{
|
||||||
|
System = await _systems.GetByHid(systemId);
|
||||||
|
if (System == null) return NotFound();
|
||||||
|
|
||||||
|
Members = await _members.GetBySystem(System);
|
||||||
|
|
||||||
|
return Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
PluralKit.Web/Pages/_ViewImports.cshtml
Normal file
3
PluralKit.Web/Pages/_ViewImports.cshtml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@using PluralKit.Web
|
||||||
|
@namespace PluralKit.Web.Pages
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
3
PluralKit.Web/Pages/_ViewStart.cshtml
Normal file
3
PluralKit.Web/Pages/_ViewStart.cshtml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@{
|
||||||
|
Layout = "Shared/_Layout";
|
||||||
|
}
|
21
PluralKit.Web/PluralKit.Web.csproj
Normal file
21
PluralKit.Web/PluralKit.Web.csproj
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PluralKit.Core\PluralKit.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
19
PluralKit.Web/Program.cs
Normal file
19
PluralKit.Web/Program.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using Microsoft.AspNetCore;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
|
namespace PluralKit.Web
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
CreateWebHostBuilder(args).Build().Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||||
|
{
|
||||||
|
return WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
PluralKit.Web/Startup.cs
Normal file
55
PluralKit.Web/Startup.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System.Data;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Npgsql;
|
||||||
|
|
||||||
|
namespace PluralKit.Web
|
||||||
|
{
|
||||||
|
public class Startup
|
||||||
|
{
|
||||||
|
public Startup(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IConfiguration Configuration { get; }
|
||||||
|
|
||||||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
var config = Configuration.GetSection("PluralKit").Get<CoreConfig>();
|
||||||
|
|
||||||
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||||
|
|
||||||
|
services
|
||||||
|
.AddSingleton<IDbConnection, NpgsqlConnection>(_ => new NpgsqlConnection(config.Database))
|
||||||
|
.AddSingleton<SystemStore>()
|
||||||
|
.AddSingleton<MemberStore>()
|
||||||
|
.AddSingleton(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
public async void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
|
{
|
||||||
|
if (env.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseExceptionHandler("/Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
//app.UseHttpsRedirection();
|
||||||
|
app.UseMvc();
|
||||||
|
|
||||||
|
var conn = app.ApplicationServices.GetRequiredService<IDbConnection>();
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
await Schema.CreateTables(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluralKit.Bot", "PluralKit.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluralKit.Core", "PluralKit.Core\PluralKit.Core.csproj", "{5DBE037D-179D-4C05-8A28-35E37129C961}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluralKit.Core", "PluralKit.Core\PluralKit.Core.csproj", "{5DBE037D-179D-4C05-8A28-35E37129C961}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluralKit.Web", "PluralKit.Web\PluralKit.Web.csproj", "{975F9DED-78D1-4742-8412-DF70BB381E92}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -18,5 +20,9 @@ Global
|
|||||||
{5DBE037D-179D-4C05-8A28-35E37129C961}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5DBE037D-179D-4C05-8A28-35E37129C961}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{5DBE037D-179D-4C05-8A28-35E37129C961}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5DBE037D-179D-4C05-8A28-35E37129C961}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5DBE037D-179D-4C05-8A28-35E37129C961}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5DBE037D-179D-4C05-8A28-35E37129C961}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{975F9DED-78D1-4742-8412-DF70BB381E92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{975F9DED-78D1-4742-8412-DF70BB381E92}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{975F9DED-78D1-4742-8412-DF70BB381E92}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{975F9DED-78D1-4742-8412-DF70BB381E92}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
Reference in New Issue
Block a user