btcpayserver/BTCPayServer/SearchString.cs
d11n e2d0b7c5f7
Store centric UI: Part 3 (#3224)
* Set store context in cookie

* Fix page id usages in view

* Move Pay Button to nav

* Move integrations to plugins nav

* Store switch links to wallet if present

* Test fixes

* Nav fixes

* Fix altcoin view

* Main nav updates

* Wallet setttings nav update

* Move storeId cookie fallback to cookie auth handler

* View fixes

* Test fixes

* Fix profile check

* Rename integrations nav extension point to store-integrations-nav-list

* Allow strings for Active page/category for plugins

* Make invoice list filter based on store context

* Do not set context if we are running authorizer through tag helper

* Fix test and unfiltered invoices

* Add permission helper for wallet links

* Add sanity checks for payment requests and invoices

* Store context in home controller

* Fix PayjoinViaUI test

* Store context for notifications

* Minor UI improvements

* Store context for userstores and vault controller

* Bring back integrations page

* Rename notifications nav pages file

* Fix user stores controller policies

* Controller policy fixes from code review

* CookieAuthHandler: Simplify CanViewInvoices case

* Revert "Controller policy fixes from code review"

This reverts commit 97e8b8379c.

* Simplify LayoutSimple

* Fix CanViewInvoices condition

Co-authored-by: Kukks <evilkukka@gmail.com>
2021-12-31 16:36:38 +09:00

84 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace BTCPayServer
{
public class SearchString
{
readonly string _OriginalString;
public SearchString(string str)
{
str = str ?? string.Empty;
str = str.Trim();
_OriginalString = str.Trim();
TextSearch = _OriginalString;
var splitted = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Filters
= splitted
.Select(t => t.Split(new char[] { ':' }, 2, StringSplitOptions.RemoveEmptyEntries))
.Where(kv => kv.Length == 2)
.Select(kv => new KeyValuePair<string, string>(kv[0].ToLowerInvariant().Trim(), kv[1]))
.ToMultiValueDictionary(o => o.Key, o => o.Value);
var val = splitted.FirstOrDefault(a => a?.IndexOf(':', StringComparison.OrdinalIgnoreCase) == -1);
if (val != null)
TextSearch = val.Trim();
else
TextSearch = "";
}
public string TextSearch { get; private set; }
public MultiValueDictionary<string, string> Filters { get; private set; }
public override string ToString()
{
return _OriginalString;
}
internal string[] GetFilterArray(string key)
{
return Filters.ContainsKey(key) ? Filters[key].ToArray() : null;
}
internal bool? GetFilterBool(string key)
{
if (!Filters.ContainsKey(key))
return null;
return bool.TryParse(Filters[key].First(), out var r) ?
r : (bool?)null;
}
internal DateTimeOffset? GetFilterDate(string key, int timezoneOffset)
{
if (!Filters.ContainsKey(key))
return null;
var val = Filters[key].First();
// handle special string values
if (val == "-24h")
return DateTimeOffset.UtcNow.AddHours(-24).AddMinutes(timezoneOffset);
else if (val == "-3d")
return DateTimeOffset.UtcNow.AddDays(-3).AddMinutes(timezoneOffset);
else if (val == "-7d")
return DateTimeOffset.UtcNow.AddDays(-7).AddMinutes(timezoneOffset);
// default parsing logic
var success = DateTimeOffset.TryParse(val, null as IFormatProvider, DateTimeStyles.AssumeUniversal, out var r);
if (success)
{
r = r.AddMinutes(timezoneOffset);
return r;
}
return null;
}
internal bool ContainsFilter(string key) => Filters.ContainsKey(key);
}
}