From 94e8bf4a720a290be5613b986901a89cd8a1056a Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Tue, 14 Jul 2020 19:58:52 -0700 Subject: [PATCH] Allow mass-archiving of invoices closes #1709 --- .../Controllers/InvoiceController.UI.cs | 18 + .../Services/Invoices/InvoiceRepository.cs | 18 + .../Views/Invoice/ListInvoices.cshtml | 608 +++++++++--------- 3 files changed, 353 insertions(+), 291 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 211707ff9..c573f7245 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -290,6 +290,24 @@ namespace BTCPayServer.Controllers return RedirectToAction(nameof(invoice), new { invoiceId }); } + [HttpPost] + public async Task MassAction(string command, string[] selectedItems) + { + if (selectedItems != null) + { + switch (command) + { + case "archive": + await _InvoiceRepository.MassArchive(selectedItems); + TempData[WellKnownTempData.SuccessMessage] = $"{selectedItems.Length} invoice(s) archived."; + + break; + } + } + + return RedirectToAction(nameof(ListInvoices)); + } + [HttpGet] [Route("i/{invoiceId}")] [Route("i/{invoiceId}/{paymentMethodId}")] diff --git a/BTCPayServer/Services/Invoices/InvoiceRepository.cs b/BTCPayServer/Services/Invoices/InvoiceRepository.cs index 1af271460..042d46644 100644 --- a/BTCPayServer/Services/Invoices/InvoiceRepository.cs +++ b/BTCPayServer/Services/Invoices/InvoiceRepository.cs @@ -403,6 +403,24 @@ retry: } } + public async Task MassArchive(string[] invoiceIds) + { + using (var context = _ContextFactory.CreateContext()) + { + var items = context.Invoices.Where(a => invoiceIds.Contains(a.Id)); + if (items == null) { + return; + } + + foreach (InvoiceData invoice in items) + { + invoice.Archived = true; + } + + await context.SaveChangesAsync(); + } + } + public async Task ToggleInvoiceArchival(string invoiceId, bool archived) { using (var context = _ContextFactory.CreateContext()) diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 6689736df..b42d98b08 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -45,318 +45,344 @@ -
- -
-
-
- -
- - -
- - + + +
+ + +
+ + - @{ - var storeIds = string.Join( - "", - Model.StoreIds.Select(storeId => $",storeid:{storeId}") - ); - } - - -
-
- - -
-
-
- - @* Custom Range Modal *@ - - - @* Custom Range Modal *@ +
+
+
+ Create a new invoice -
-
- - - - - - - - - - - - - @foreach (var invoice in Model.Invoices) - { - - - - - - - - - + else + { + + @(Model.Skip + 1)–@(Model.Skip + Model.Invoices.Count), Total: @Model.Total + + } + +
  • + » +
  • + } - -
    - Date - - - - OrderIdInvoiceIdStatusAmountActions
    - - @invoice.Date.ToBrowserDate() - - - @if (invoice.RedirectUrl != string.Empty) - { - @invoice.OrderId - } - else - { - @invoice.OrderId - } - @invoice.InvoiceId - @if(invoice.Details.Archived) - { - archived - } - @if (invoice.CanMarkStatus) - { -
    - - + + + + + + + + + + + + +
    + + + @* Custom Range Modal *@ + + + @* Custom Range Modal *@ + + +
    +
    + + + + - + + + + + + + + + @foreach (var invoice in Model.Invoices) + { + + + + + + + + + + + + + } + +
    + @if (Model.Total > 0) { - @invoice.StatusString + } - - @invoice.AmountCurrency - @if (invoice.ShowCheckout) + + + Date + + + + OrderIdInvoiceIdStatusAmountActions
    + + + + @invoice.Date.ToBrowserDate() + + + @if (invoice.RedirectUrl != string.Empty) + { + @invoice.OrderId + } + else + { + @invoice.OrderId + } + @invoice.InvoiceId + @if(invoice.Details.Archived) + { + archived + } + @if (invoice.CanMarkStatus) + { +
    + + +
    + } + else + { + @invoice.StatusString + } +
    @invoice.AmountCurrency + @if (invoice.ShowCheckout) + { + + Checkout + [^] + @if (!invoice.CanMarkStatus) + { + - + } + + } +   + Details + + + +
    +
    - - @{ - string ListInvoicesPage(int prevNext, int count) - { - var skip = Model.Skip; - if (prevNext == -1) + + @{ + string ListInvoicesPage(int prevNext, int count) { - skip = Math.Max(0, Model.Skip - Model.Count); - } - else if (prevNext == 1) - { - skip = Model.Skip + count; - } + var skip = Model.Skip; + if (prevNext == -1) + { + skip = Math.Max(0, Model.Skip - Model.Count); + } + else if (prevNext == 1) + { + skip = Model.Skip + count; + } - var act = Url.Action("ListInvoices", new - { - searchTerm = Model.SearchTerm, - skip = skip, - count = count, - }); + var act = Url.Action("ListInvoices", new + { + searchTerm = Model.SearchTerm, + skip = skip, + count = count, + }); - return act; + return act; + } } - } +
    -
    - +