Skip to content

Commit

Permalink
Allow decorating filter cookie name
Browse files Browse the repository at this point in the history
  • Loading branch information
programcsharp committed Aug 9, 2023
1 parent 83dd48a commit 675a57d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Griddly.Mvc/GriddlyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ namespace Griddly.Mvc
{
public class GriddlyContext
{
public string Name { get; set; }
string _name;
string _cookieName;

public string Name
{
get => _name;
set
{
_name = value;

_cookieName = "gf_" + Name;

if (GriddlySettings.DecorateCookieName != null)
_cookieName = GriddlySettings.DecorateCookieName(_cookieName);
}
}

public bool IsDefaultSkipped { get; set; }
public bool IsDeepLink { get; set; }

public GriddlyFilterCookieData CookieData { get; set; }

public string CookieName => "gf_" + Name;
public string CookieName => _cookieName;

public Dictionary<string, object> Defaults { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
Expand Down
1 change: 1 addition & 0 deletions Griddly.Mvc/GriddlyParameterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public static void AddCookieDataIfNeeded(GriddlyContext context, HttpContext htt
if (context.SortFields?.Length > 0)
data.SortFields = context.SortFields;

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

#if NETFRAMEWORK
Expand Down
1 change: 1 addition & 0 deletions Griddly.Mvc/GriddlySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class GriddlySettings : IGriddlyFilterSettings
public static bool ExportCurrencySymbol = true;
public static bool DisableHistoryParameters = false;

public static Func<string, string> DecorateCookieName = null;
public static Func<GriddlyButton, object> IconTemplate = null;
public static Func<GriddlyResultPage, object> DefaultFooterTemplate = null;
public static Func<GriddlyResultPage, object> DefaultHeaderTemplate = null;
Expand Down

0 comments on commit 675a57d

Please sign in to comment.