account details view
lineage summary doesn't work
This commit is contained in:
parent
d22faae2f6
commit
488a89614a
35
WebInterface/Controllers/AccountsController.cs
Normal file
35
WebInterface/Controllers/AccountsController.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using vassago.Models;
|
||||||
|
using vassago.WebInterface.Models;
|
||||||
|
|
||||||
|
namespace vassago.WebInterface.Controllers;
|
||||||
|
|
||||||
|
public class AccountsController(ChattingContext db) : Controller
|
||||||
|
{
|
||||||
|
private ChattingContext Database => db;
|
||||||
|
|
||||||
|
public async Task<IActionResult> Index()
|
||||||
|
{
|
||||||
|
return Database.Accounts != null ?
|
||||||
|
View(await Database.Accounts.ToListAsync()) :
|
||||||
|
Problem("Entity set '_db.Accounts' is null.");
|
||||||
|
}
|
||||||
|
public async Task<IActionResult> Details(Guid id)
|
||||||
|
{
|
||||||
|
var account = await Database.Accounts
|
||||||
|
.Include(a => a.IsUser)
|
||||||
|
.Include(a => a.SeenInChannel)
|
||||||
|
.FirstAsync(a => a.Id == id);
|
||||||
|
return Database.Accounts != null ?
|
||||||
|
View(account) :
|
||||||
|
Problem("Entity set '_db.Accounts' is null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
public IActionResult Error()
|
||||||
|
{
|
||||||
|
return View(new ErrorPageViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
|
}
|
||||||
|
}
|
@ -163,7 +163,7 @@ public class HomeController : Controller
|
|||||||
}
|
}
|
||||||
private void serializeAccount(ref StringBuilder sb, Account currentAccount)
|
private void serializeAccount(ref StringBuilder sb, Account currentAccount)
|
||||||
{
|
{
|
||||||
sb.Append($"{{\"text\": \"{currentAccount.DisplayName}\"}}");
|
sb.Append($"{{\"text\": \"<a href=\\\"{Url.ActionLink(action: "Details", controller: "Accounts", values: new {id = currentAccount.Id})}\\\">{currentAccount.DisplayName}</a>\"}}");
|
||||||
}
|
}
|
||||||
private void serializeUser(ref StringBuilder sb, ref List<Account> allAccounts, User currentUser)
|
private void serializeUser(ref StringBuilder sb, ref List<Account> allAccounts, User currentUser)
|
||||||
{
|
{
|
||||||
|
40
WebInterface/Controllers/api/UsersController.cs
Normal file
40
WebInterface/Controllers/api/UsersController.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using vassago.Models;
|
||||||
|
using vassago.ProtocolInterfaces.DiscordInterface;
|
||||||
|
|
||||||
|
namespace vassago.Controllers.api;
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class UsersController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILogger<ChannelsController> _logger;
|
||||||
|
|
||||||
|
public UsersController(ILogger<ChannelsController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPatch]
|
||||||
|
[Produces("application/json")]
|
||||||
|
public IActionResult Patch([FromBody] User user)
|
||||||
|
{
|
||||||
|
var fromDb = Rememberer.SearchUser(u => u.Id == user.Id);
|
||||||
|
if (fromDb == null)
|
||||||
|
{
|
||||||
|
_logger.LogError($"attempt to update user {user.Id}, not found");
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogDebug($"patching {user.DisplayName} (id: {user.Id})");
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: settable values: display name
|
||||||
|
//fromDb.DisplayName = user.DisplayName;
|
||||||
|
Rememberer.RememberUser(fromDb);
|
||||||
|
return Ok(fromDb);
|
||||||
|
}
|
||||||
|
}
|
66
WebInterface/Views/Accounts/Details.cshtml
Normal file
66
WebInterface/Views/Accounts/Details.cshtml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
@model Account
|
||||||
|
@using Newtonsoft.Json
|
||||||
|
@using System.Text
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Account details";
|
||||||
|
}
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">belongs to user</th>
|
||||||
|
<td>@Model.IsUser.DisplayName</td>
|
||||||
|
<td><button alt="to do" disabled>separate</button></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Seen in channel</th>
|
||||||
|
<td><div class="protocol-icon"> </div>@Model.SeenInChannel.LineageSummary<a href="/Channels/Details/@Model.SeenInChannel.Id">@Model.SeenInChannel.DisplayName</a></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Permission Tags</th>
|
||||||
|
<td>
|
||||||
|
<div id="tagsTree"></div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
@section Scripts{
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
@{
|
||||||
|
var accountAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const userOnLoad = @Html.Raw(accountAsString);
|
||||||
|
function jsonifyUser() {
|
||||||
|
var userNow = structuredClone(userOnLoad);
|
||||||
|
userNow.Accounts = null;
|
||||||
|
userNow.DisplayName = document.querySelector("#displayName").value;
|
||||||
|
console.log(userNow);
|
||||||
|
return userNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTagsTree() {
|
||||||
|
@{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append("[{text: \"permission tags\", \"expanded\":true, nodes: [");
|
||||||
|
var first = true;
|
||||||
|
for (int i = 0; i < 1; i++)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
sb.Append(',');
|
||||||
|
sb.Append($"{{text: \"<input type=\\\"checkbox\\\" > is goated (w/ sauce)</input>\"}}");
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
sb.Append("]}]");
|
||||||
|
}
|
||||||
|
console.log(@Html.Raw(sb.ToString()));
|
||||||
|
var tree = @Html.Raw(sb.ToString());
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
$('#tagsTree').bstreeview({ data: getTagsTree() });
|
||||||
|
document.querySelectorAll("input[type=checkbox]").forEach(node => { node.onchange = () => { patchModel(jsonifyUser(), '/api/Users/') } });
|
||||||
|
</script>
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
@using System.ComponentModel
|
@using System.ComponentModel
|
||||||
@using Newtonsoft.Json
|
@using Newtonsoft.Json
|
||||||
|
@using System.Text;
|
||||||
@model Tuple<Channel, Enumerations.LewdnessFilterLevel, Enumerations.MeannessFilterLevel>
|
@model Tuple<Channel, Enumerations.LewdnessFilterLevel, Enumerations.MeannessFilterLevel>
|
||||||
@{
|
@{
|
||||||
var ThisChannel = Model.Item1;
|
var ThisChannel = Model.Item1;
|
||||||
@ -91,7 +92,16 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Accounts</th>
|
<th scope="row">Accounts</th>
|
||||||
<td>@(ThisChannel.Users?.Count ?? 0)</td>
|
<td>
|
||||||
|
@if((ThisChannel.Users?.Count ?? 0) > 0)
|
||||||
|
{
|
||||||
|
@Html.Raw("<div id=\"accountsTree\"></div>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
@Html.Raw("none")
|
||||||
|
}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
@ -133,7 +143,27 @@
|
|||||||
var tree = @Html.Raw(ViewData["channelsTree"]);
|
var tree = @Html.Raw(ViewData["channelsTree"]);
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function accountsTree() {
|
||||||
|
@{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append("[{text: \"accounts\", \"expanded\":true, nodes: [");
|
||||||
|
var first = true;
|
||||||
|
foreach (var acc in ThisChannel.Users.OrderBy(a => a.SeenInChannel.LineageSummary))
|
||||||
|
{
|
||||||
|
if(!first)
|
||||||
|
sb.Append(',');
|
||||||
|
sb.Append($"{{text: \"<div class=\\\"account {acc.Protocol}\\\"><div class=\\\"protocol-icon\\\"> </div>{acc.SeenInChannel.LineageSummary}/<a href=\\\"/Accounts/Details/{acc.Id}\\\">{acc.DisplayName}</a>\"}}");
|
||||||
|
first=false;
|
||||||
|
}
|
||||||
|
sb.Append("]}]");
|
||||||
|
}
|
||||||
|
//console.log(@Html.Raw(sb.ToString()));
|
||||||
|
var tree = @Html.Raw(sb.ToString());
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
$('#channelsTree').bstreeview({ data: channelsTree() });
|
$('#channelsTree').bstreeview({ data: channelsTree() });
|
||||||
|
$('#accountsTree').bstreeview({ data: accountsTree() });
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
@ -7,22 +7,24 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="text" id="displayName" value="@Model.DisplayName"></input> <button onclick="patchModel(jsonifyUser(), @Html.Raw("'/api/Users/'"))">update</button></td>
|
<th scope="row">Display Name (here)</th>
|
||||||
|
<td><input type="text" id="displayName" value="@Model.DisplayName"></input> <button
|
||||||
|
onclick="patchModel(jsonifyUser(), @Html.Raw("'/api/Users/'"))" disabled alt"todo">update</button></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="row">Accounts</th>
|
||||||
<td>
|
<td>
|
||||||
<div id="accountsTree"></div>
|
<div id="accountsTree"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="row">Permission Tags</th>
|
||||||
<td>
|
<td>
|
||||||
<div id="tagsTree"></div>
|
<div id="tagsTree"></div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<a asp-controller="Accounts" asp-action="Details" asp-route-id="1">placeholderlink</a>
|
|
||||||
|
|
||||||
|
|
||||||
@section Scripts{
|
@section Scripts{
|
||||||
|
|
||||||
@ -47,7 +49,7 @@
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("[{text: \"accounts\", \"expanded\":true, nodes: [");
|
sb.Append("[{text: \"accounts\", \"expanded\":true, nodes: [");
|
||||||
var first = true;
|
var first = true;
|
||||||
foreach (var acc in Model.Accounts)
|
foreach (var acc in Model.Accounts.OrderBy(a => a.SeenInChannel.LineageSummary))
|
||||||
{
|
{
|
||||||
if (!first)
|
if (!first)
|
||||||
sb.Append(',');
|
sb.Append(',');
|
||||||
|
Reference in New Issue
Block a user