mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
Providing support for mass actions on notifications, delete first
This commit is contained in:
parent
3680e03cdb
commit
7e9bf9598d
@ -60,21 +60,6 @@ namespace BTCPayServer.Controllers
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
{
|
||||
// TODO: Refactor
|
||||
var claimWithId = User.Claims.SingleOrDefault(a => a.Type == ClaimTypes.NameIdentifier);
|
||||
if (claimWithId == null)
|
||||
return RedirectToAction("Index", "Home");
|
||||
|
||||
var notif = _db.Notifications.SingleOrDefault(a => a.Id == id && a.ApplicationUserId == claimWithId.Value);
|
||||
_db.Notifications.Remove(notif);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> FlipRead(string id)
|
||||
{
|
||||
@ -89,5 +74,35 @@ namespace BTCPayServer.Controllers
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> MassAction(string command, string csvGuids)
|
||||
{
|
||||
List<string> parsedGuids = null;
|
||||
try
|
||||
{
|
||||
parsedGuids = csvGuids.Split(',').ToList();
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (parsedGuids != null)
|
||||
{
|
||||
if (command == "delete")
|
||||
{
|
||||
// TODO: Refactor
|
||||
var claimWithId = User.Claims.SingleOrDefault(a => a.Type == ClaimTypes.NameIdentifier);
|
||||
if (claimWithId == null)
|
||||
return RedirectToAction("Index", "Home");
|
||||
|
||||
var toRemove = _db.Notifications.Where(a => a.ApplicationUserId == claimWithId.Value && parsedGuids.Contains(a.Id));
|
||||
_db.Notifications.RemoveRange(toRemove);
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,16 @@
|
||||
</div>
|
||||
<div class="row button-row">
|
||||
<div class="col-lg-6">
|
||||
<a asp-action="Generate" class="btn btn-primary" role="button" id="Generate"><span class="fa fa-plus"></span> Generate Test Notification</a>
|
||||
<span class="dropdown" style="display:none;" id="MassAction">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Actions
|
||||
</button>
|
||||
<form method="post" asp-action="MassAction" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||
@Html.Hidden("csvGuids")
|
||||
<button type="submit" class="dropdown-item" name="command" value="delete"><i class="fa fa-trash-o"></i> Delete</button>
|
||||
</form>
|
||||
</span>
|
||||
<a class="btn btn-primary" role="button" asp-action="Generate" id="Generate"><span class="fa fa-plus"></span> Generate Test Notification</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -77,4 +86,24 @@
|
||||
$.post("/Notifications/FlipRead/" + $(sender).parent().data("guid"), function (data) {
|
||||
});
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$(".selector").change(updateSelectors);
|
||||
updateSelectors();
|
||||
});
|
||||
|
||||
function updateSelectors() {
|
||||
var count = $(".selector:checked").length;
|
||||
if (count > 0) {
|
||||
$("#MassAction").children().eq(0).text("Batch Action (" + count + ")");
|
||||
$("#MassAction").show();
|
||||
var csvGuids = [];
|
||||
$(".selector:checked").each(function () {
|
||||
csvGuids.push($(this).data("guid"));
|
||||
});
|
||||
$("#csvGuids").val(csvGuids.join(","));
|
||||
} else {
|
||||
$("#MassAction").hide();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user