mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Save the latest search on invoices
This commit is contained in:
@@ -29,6 +29,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using NBitcoin;
|
using NBitcoin;
|
||||||
using NBitpayClient;
|
using NBitpayClient;
|
||||||
using NBXplorer;
|
using NBXplorer;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using StoreData = BTCPayServer.Data.StoreData;
|
using StoreData = BTCPayServer.Data.StoreData;
|
||||||
|
|
||||||
@@ -597,12 +598,40 @@ namespace BTCPayServer.Controllers
|
|||||||
return Ok("{}");
|
return Ok("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class InvoicePreference
|
||||||
|
{
|
||||||
|
public int? TimezoneOffset { get; set; }
|
||||||
|
public string SearchTerm { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("invoices")]
|
[Route("invoices")]
|
||||||
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
[BitpayAPIConstraint(false)]
|
[BitpayAPIConstraint(false)]
|
||||||
public async Task<IActionResult> ListInvoices(string searchTerm = null, int skip = 0, int count = 50, int timezoneOffset = 0)
|
public async Task<IActionResult> ListInvoices(string searchTerm = null, int skip = 0, int count = 50, int? timezoneOffset = null)
|
||||||
{
|
{
|
||||||
|
// If the user enter an empty searchTerm, then the variable will be null and not empty string
|
||||||
|
// but we want searchTerm to be null only if the user is browsing the page via some link
|
||||||
|
// NOT if the user entered some empty search
|
||||||
|
searchTerm = searchTerm is string ? searchTerm :
|
||||||
|
this.Request.Query.ContainsKey(nameof(searchTerm)) ? string.Empty :
|
||||||
|
null;
|
||||||
|
if (searchTerm is null)
|
||||||
|
{
|
||||||
|
if (this.Request.Cookies.TryGetValue("ListInvoicePreferences", out var str))
|
||||||
|
{
|
||||||
|
var preferences = JsonConvert.DeserializeObject<InvoicePreference>(str);
|
||||||
|
searchTerm = preferences.SearchTerm;
|
||||||
|
timezoneOffset = timezoneOffset is int v ? v : preferences.TimezoneOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var preferences = new InvoicePreference();
|
||||||
|
preferences.SearchTerm = searchTerm;
|
||||||
|
preferences.TimezoneOffset = timezoneOffset;
|
||||||
|
this.Response.Cookies.Append("ListInvoicePreferences", JsonConvert.SerializeObject(preferences));
|
||||||
|
}
|
||||||
var fs = new SearchString(searchTerm);
|
var fs = new SearchString(searchTerm);
|
||||||
var storeIds = fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray();
|
var storeIds = fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray();
|
||||||
|
|
||||||
@@ -614,7 +643,7 @@ namespace BTCPayServer.Controllers
|
|||||||
StoreIds = storeIds,
|
StoreIds = storeIds,
|
||||||
TimezoneOffset = timezoneOffset
|
TimezoneOffset = timezoneOffset
|
||||||
};
|
};
|
||||||
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset);
|
InvoiceQuery invoiceQuery = GetInvoiceQuery(searchTerm, timezoneOffset ?? 0);
|
||||||
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
||||||
invoiceQuery.Count = count;
|
invoiceQuery.Count = count;
|
||||||
invoiceQuery.Skip = skip;
|
invoiceQuery.Skip = skip;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@model InvoicesModel
|
@model InvoicesModel
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Invoices";
|
ViewData["Title"] = "Invoices";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user