Skip to content

Commit 675a57d

Browse files
committed
Allow decorating filter cookie name
1 parent 83dd48a commit 675a57d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Griddly.Mvc/GriddlyContext.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ namespace Griddly.Mvc
55
{
66
public class GriddlyContext
77
{
8-
public string Name { get; set; }
8+
string _name;
9+
string _cookieName;
10+
11+
public string Name
12+
{
13+
get => _name;
14+
set
15+
{
16+
_name = value;
17+
18+
_cookieName = "gf_" + Name;
19+
20+
if (GriddlySettings.DecorateCookieName != null)
21+
_cookieName = GriddlySettings.DecorateCookieName(_cookieName);
22+
}
23+
}
24+
925
public bool IsDefaultSkipped { get; set; }
1026
public bool IsDeepLink { get; set; }
1127

1228
public GriddlyFilterCookieData CookieData { get; set; }
1329

14-
public string CookieName => "gf_" + Name;
30+
public string CookieName => _cookieName;
1531

1632
public Dictionary<string, object> Defaults { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
1733
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

Griddly.Mvc/GriddlyParameterAttribute.cs

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public static void AddCookieDataIfNeeded(GriddlyContext context, HttpContext htt
230230
if (context.SortFields?.Length > 0)
231231
data.SortFields = context.SortFields;
232232

233+
cookie.Name = context.CookieName; // cookie name could be different than the default
233234
cookie.Value = JsonConvert.SerializeObject(data);
234235

235236
#if NETFRAMEWORK

Griddly.Mvc/GriddlySettings.cs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public abstract class GriddlySettings : IGriddlyFilterSettings
5353
public static bool ExportCurrencySymbol = true;
5454
public static bool DisableHistoryParameters = false;
5555

56+
public static Func<string, string> DecorateCookieName = null;
5657
public static Func<GriddlyButton, object> IconTemplate = null;
5758
public static Func<GriddlyResultPage, object> DefaultFooterTemplate = null;
5859
public static Func<GriddlyResultPage, object> DefaultHeaderTemplate = null;

0 commit comments

Comments
 (0)