Files
lubelog/Views/Admin/Index.cshtml
2024-01-13 11:48:20 -07:00

106 lines
4.2 KiB
Plaintext

@{
ViewData["Title"] = "Admin";
}
@model AdminViewModel
<div class="container">
<div class="row">
<div class="col-5">
<div class="row">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="enableAutoNotify" checked>
<label class="form-check-label" for="enableAutoNotify">Auto Notify(via Email)</label>
</div>
<button onclick="generateNewToken()" class="btn btn-primary btn-md mt-1 mb-1"><i class="bi bi-pencil-square me-2"></i>Generate User Token</button>
</div>
<table class="table table-hover">
<thead>
<tr class="d-flex">
<th scope="col" class="col-4">Token</th>
<th scope="col" class="col-6">Issued To</th>
<th scope="col" class="col-2">Delete</th>
</tr>
</thead>
<tbody>
@foreach (Token token in Model.Tokens)
{
<tr class="d-flex">
<td class="col-4" style="cursor:pointer;" onclick="copyToClipboard(this)">@token.Body</td>
<td class="col-6 text-truncate">@token.EmailAddress</td>
<td class="col-2">
<button type="button" class="btn btn-danger" onclick="deleteToken(@token.Id, this)"><i class="bi bi-trash"></i></button>
</td>
</tr>
}
</tbody>
</table>
</div>
<div class="col-7">
<table class="table table-hover">
<thead>
<tr class="d-flex">
<th scope="col" class="col-4">UserName</th>
<th scope="col" class="col-2">Is Admin</th>
<th scope="col" class="col-4">Reset Password</th>
<th scope="col" class="col-2">Delete</th>
</tr>
</thead>
<tbody>
@foreach (UserData userData in Model.Users)
{
<tr class="d-flex" style="cursor:pointer;">
<td class="col-4">@userData.UserName</td>
<td class="col-2">@userData.Id</td>
<td class="col-4">@userData.Id</td>
<td class="col-2">@userData.Id</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
<script>
function reloadPage() {
window.location.reload();
}
function deleteToken(tokenId) {
$.post(`/Admin/DeleteToken?tokenId=${tokenId}`, function (data) {
if (data) {
reloadPage();
}
});
}
function copyToClipboard(e) {
var textToCopy = e.textContent;
navigator.clipboard.writeText(textToCopy);
successToast("Copied to Clipboard");
}
function generateNewToken(){
Swal.fire({
title: 'Generate Token',
html: `
<input type="text" id="inputEmail" class="swal2-input" placeholder="Email Address">
`,
confirmButtonText: 'Generate',
focusConfirm: false,
preConfirm: () => {
const emailAddress = $("#inputEmail").val();
if (!emailAddress) {
Swal.showValidationMessage(`Please enter an email address`)
}
return { emailAddress }
},
}).then(function (result) {
if (result.isConfirmed) {
var autoNotify = $("#enableAutoNotify").is(":checked");
$.get('/Admin/GenerateNewToken', {emailAddress: result.value.emailAddress, autoNotify: autoNotify}, function (data) {
if (data.success) {
reloadPage();
} else {
errorToast(data.message)
}
});
}
});
}
</script>