diff --git a/BTCPayServer/Controllers/NotificationsController.cs b/BTCPayServer/Controllers/NotificationsController.cs index fdc703458..d1f41ed69 100644 --- a/BTCPayServer/Controllers/NotificationsController.cs +++ b/BTCPayServer/Controllers/NotificationsController.cs @@ -60,21 +60,6 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Index)); } - [HttpGet] - public async Task 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 FlipRead(string id) { @@ -89,5 +74,35 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(Index)); } + + [HttpPost] + public async Task MassAction(string command, string csvGuids) + { + List 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)); + } } } diff --git a/BTCPayServer/Views/Notifications/Index.cshtml b/BTCPayServer/Views/Notifications/Index.cshtml index 00e256920..864119360 100644 --- a/BTCPayServer/Views/Notifications/Index.cshtml +++ b/BTCPayServer/Views/Notifications/Index.cshtml @@ -23,7 +23,16 @@
- Generate Test Notification + + Generate Test Notification
@@ -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(); + } + }