forked from adam/discord-bot-shtik
user management UI
Some checks failed
gitea/vassago/pipeline/head There was a failure building this commit
Some checks failed
gitea/vassago/pipeline/head There was a failure building this commit
This commit is contained in:
parent
9648ea563b
commit
e0c7bdb35f
@ -12,7 +12,7 @@ public class User
|
|||||||
public List<Account> Accounts { get; set; }
|
public List<Account> Accounts { get; set; }
|
||||||
|
|
||||||
//if I ever get lots and lots of tags, or some automatic way to register a feature's arbitrary tags, then I can move this off.
|
//if I ever get lots and lots of tags, or some automatic way to register a feature's arbitrary tags, then I can move this off.
|
||||||
public bool Tag_CanTwitchSummon { get; set; }
|
//public bool Tag_CanTwitchSummon { get; set; }
|
||||||
|
|
||||||
public string DisplayName
|
public string DisplayName
|
||||||
{
|
{
|
||||||
|
@ -24,8 +24,16 @@ public class UsersController : Controller
|
|||||||
}
|
}
|
||||||
public async Task<IActionResult> Details(Guid id)
|
public async Task<IActionResult> Details(Guid id)
|
||||||
{
|
{
|
||||||
|
var user = await _db.Users
|
||||||
|
.Include(u => u.Accounts)
|
||||||
|
.FirstAsync(u => u.Id == id);
|
||||||
|
var allTheChannels = await _db.Channels.ToListAsync();
|
||||||
|
foreach(var acc in user.Accounts)
|
||||||
|
{
|
||||||
|
acc.SeenInChannel = allTheChannels.FirstOrDefault(c => c.Id == acc.SeenInChannel.Id);
|
||||||
|
}
|
||||||
return _db.Users != null ?
|
return _db.Users != null ?
|
||||||
View(await _db.Users.Include(u => u.Accounts).FirstAsync(u => u.Id == id)) :
|
View(user) :
|
||||||
Problem("Entity set '_db.Users' is null.");
|
Problem("Entity set '_db.Users' is null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@model User
|
@model User
|
||||||
|
@using Newtonsoft.Json
|
||||||
@using System.Text
|
@using System.Text
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "User details";
|
ViewData["Title"] = "User details";
|
||||||
@ -6,39 +7,42 @@
|
|||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Display Name</th>
|
<td><input type="text" id="displayName" value="@Model.DisplayName"></input> <button onclick="patchModel(jsonifyUser(), @Html.Raw("'/api/Users/'"))">update</button></td>
|
||||||
<td>@Model.DisplayName</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{
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var detailLink='<a asp-controller="Accounts" asp-action="Details" asp-route-id="accid">Details</a>;
|
@{
|
||||||
@foreach (var acc in Model.Accounts)
|
var userAsString = JsonConvert.SerializeObject(Model, new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
<div class="account @acc.Protocol">
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
<div class="protocol-icon"> </div>
|
});
|
||||||
@Html.DisplayFor(acc => acc.DisplayName)
|
|
||||||
<a asp-controller="Accounts" asp-action="Details" asp-route-id="@acc.Id">Details</a>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
function getTree() {
|
const userOnLoad = @Html.Raw(userAsString);
|
||||||
|
function jsonifyUser() {
|
||||||
|
var userNow = structuredClone(userOnLoad);
|
||||||
|
userNow.Accounts = null;
|
||||||
|
userNow.DisplayName = document.querySelector("#displayName").value;
|
||||||
|
//userNow.Tag_CanTwitchSummon = document.querySelector("#tagCanTwitchSummon").checked;
|
||||||
|
console.log(userNow);
|
||||||
|
return userNow;
|
||||||
|
}
|
||||||
|
function getAccountsTree() {
|
||||||
@{
|
@{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append("[{text: \"accounts\", \"expanded\":true, nodes: [");
|
sb.Append("[{text: \"accounts\", \"expanded\":true, nodes: [");
|
||||||
@ -47,16 +51,36 @@
|
|||||||
{
|
{
|
||||||
if(!first)
|
if(!first)
|
||||||
sb.Append(',');
|
sb.Append(',');
|
||||||
sb.Append($"{{text: \"<div class=\"account {acc.Protocol}\"><div class=\"protocol-icon\"> </div>{Html.DisplayFor(acc => acc.DisplayName)}Details\"}}");
|
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;
|
first=false;
|
||||||
}
|
}
|
||||||
sb.Append("}]");
|
sb.Append("]}]");
|
||||||
}
|
}
|
||||||
|
console.log(@Html.Raw(sb.ToString()));
|
||||||
var tree = @Html.Raw(sb.ToString());
|
var tree = @Html.Raw(sb.ToString());
|
||||||
console.log(tree);
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#accountsTree').bstreeview({ data: getTree() });
|
function getTagsTree() {
|
||||||
|
@{
|
||||||
|
sb = new StringBuilder();
|
||||||
|
sb.Append("[{text: \"permission tags\", \"expanded\":true, nodes: [");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
$('#accountsTree').bstreeview({ data: getAccountsTree() });
|
||||||
|
$('#tagsTree').bstreeview({ data: getTagsTree() });
|
||||||
|
document.querySelectorAll("input[type=checkbox]").forEach(node => {node.onchange = () => {patchModel(jsonifyUser(), '/api/Users/')}});
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user