-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1063ba4
commit b6522e3
Showing
28 changed files
with
458 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Griddly.Mvc | ||
{ | ||
public class GriddlyContext | ||
{ | ||
public string Name { get; set; } | ||
public string ParentPath { get; set; } | ||
public bool IsDefaultSkipped { get; set; } | ||
|
||
public GriddlyFilterCookieData CookieData { get; set; } | ||
|
||
public string CookieName => "gf_" + Name; | ||
|
||
public Dictionary<string, object> Defaults { get; set; } = new Dictionary<string, object>(); | ||
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>(); | ||
} | ||
|
||
public class GriddlyFilterCookieData | ||
{ | ||
public Dictionary<string, string[]> Values { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
|
||
namespace Griddly.Mvc | ||
{ | ||
public class GriddlyCookieFilterValueProvider : IValueProvider | ||
{ | ||
GriddlyFilterCookieData _data; | ||
|
||
public GriddlyCookieFilterValueProvider(GriddlyFilterCookieData data) | ||
{ | ||
_data = data; | ||
} | ||
|
||
public bool ContainsPrefix(string prefix) | ||
{ | ||
return _data.Values?.ContainsKey(prefix) == true; | ||
} | ||
|
||
public ValueProviderResult GetValue(string key) | ||
{ | ||
string[] value = null; | ||
|
||
if (_data.Values?.TryGetValue(key, out value) != true) | ||
value = null; | ||
|
||
string attemptedValue = null; | ||
|
||
if (value != null) | ||
attemptedValue = string.Join(",", value); | ||
|
||
return new ValueProviderResult(value, attemptedValue, CultureInfo.CurrentCulture); | ||
} | ||
} | ||
|
||
public class GriddlyCookieFilterValueProviderFactory : ValueProviderFactory | ||
{ | ||
public override IValueProvider GetValueProvider(ControllerContext controllerContext) | ||
{ | ||
if (controllerContext.IsChildAction && controllerContext.HttpContext.Request.QueryString.Count == 0) | ||
{ | ||
var context = controllerContext.Controller.GetOrCreateGriddlyContext(); | ||
var cookie = controllerContext.HttpContext.Request.Cookies[context.CookieName]; | ||
|
||
if (cookie != null && !string.IsNullOrWhiteSpace(cookie.Value)) | ||
{ | ||
try | ||
{ | ||
var data = JsonConvert.DeserializeObject<GriddlyFilterCookieData>(cookie.Value); | ||
|
||
context.CookieData = data; | ||
context.IsDefaultSkipped = true; | ||
|
||
return new GriddlyCookieFilterValueProvider(data); | ||
} | ||
catch | ||
{ | ||
// TODO: log it? | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.