Add basic settings page
parent
730c8364e8
commit
f64d7a8126
|
@ -350,3 +350,4 @@ MigrationBackup/
|
|||
.ionide/
|
||||
Upload/
|
||||
LANCommander/Icon/
|
||||
LANCommander/Settings.yml
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
using LANCommander.Models;
|
||||
using LANCommander.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LANCommander.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class SettingsController : Controller
|
||||
{
|
||||
private readonly SettingService SettingService;
|
||||
|
||||
public SettingsController(SettingService settingService)
|
||||
{
|
||||
SettingService = settingService;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return RedirectToAction(nameof(General));
|
||||
}
|
||||
|
||||
public IActionResult General()
|
||||
{
|
||||
var settings = SettingService.GetSettings();
|
||||
|
||||
return View(settings);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult General(LANCommanderSettings settings)
|
||||
{
|
||||
SettingService.SaveSettings(settings);
|
||||
|
||||
return RedirectToAction(nameof(General));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
namespace LANCommander.Models
|
||||
{
|
||||
public class LANCommanderSettings
|
||||
{
|
||||
public string IGDBClientId { get; set; }
|
||||
public string IGDBClientSecret { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using LANCommander.Models;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace LANCommander.Services
|
||||
{
|
||||
public class SettingService
|
||||
{
|
||||
private const string SettingsFilename = "Settings.yml";
|
||||
|
||||
public LANCommanderSettings GetSettings()
|
||||
{
|
||||
if (File.Exists(SettingsFilename))
|
||||
{
|
||||
var contents = File.ReadAllText(SettingsFilename);
|
||||
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.IgnoreUnmatchedProperties()
|
||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
return deserializer.Deserialize<LANCommanderSettings>(contents);
|
||||
}
|
||||
else
|
||||
return new LANCommanderSettings();
|
||||
}
|
||||
|
||||
public void SaveSettings(LANCommanderSettings settings)
|
||||
{
|
||||
var serializer = new SerializerBuilder()
|
||||
.WithNamingConvention(PascalCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
File.WriteAllText(SettingsFilename, serializer.Serialize(settings));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
@model LANCommander.Models.LANCommanderSettings
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Settings";
|
||||
}
|
||||
|
||||
<div class="container-xl">
|
||||
<!-- Page title -->
|
||||
<div class="page-header d-print-none">
|
||||
<div class="row align-items-center">
|
||||
<div class="col">
|
||||
<div class="page-pretitle">Settings</div>
|
||||
<h2 class="page-title">
|
||||
General
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-body">
|
||||
<div class="container-xl">
|
||||
<div class="card">
|
||||
<div class="row g-0">
|
||||
@{
|
||||
await Html.RenderPartialAsync("_SidebarPartial");
|
||||
}
|
||||
|
||||
<form method="post" class="col d-flex flex-column">
|
||||
<div class="card-body">
|
||||
<h2 class="mb-4">General</h2>
|
||||
<h3 class="card-title mt-4">IGDB Credentials</h3>
|
||||
<p class="card-subtitle">In order to use IGDB metadata, you need a Twitch developer account. <a href="https://api-docs.igdb.com/#account-creation" target="_blank">Click here</a> for more details.</p>
|
||||
<div class="row g-3">
|
||||
<div class="col-md">
|
||||
<label asp-for="IGDBClientId" class="form-label"></label>
|
||||
<input asp-for="IGDBClientId" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md">
|
||||
<label asp-for="IGDBClientSecret" class="form-label"></label>
|
||||
<input asp-for="IGDBClientSecret" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-footer bg-transparent mt-auto">
|
||||
<div class="btn-list justify-content-end">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{
|
||||
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<div class="col-3 d-none d-md-block border-end">
|
||||
<div class="card-body">
|
||||
<div class="list-group list-group-transparent">
|
||||
<a asp-action="General" asp-controller="Settings" class="list-group-item list-group-item-action d-flex align-items-center">General</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -13,6 +13,7 @@
|
|||
</div>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
|
||||
<a asp-controller="Settings" asp-controller="General" class="dropdown-item">Settings</a>
|
||||
<a asp-area="Identity" asp-page="/Account/Manage/Index" class="dropdown-item">Profile & account</a>
|
||||
<a asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })" class="dropdown-item">Logout</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue