Skip to content

Commit d911304

Browse files
committed
Fix some edge cases
1 parent 9baf3c5 commit d911304

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ public static void SetGriddlyDefault<T>(this ControllerBase controller, ref T?[]
210210
}
211211
}
212212

213+
public static object GetGriddlyDefault(this WebViewPage page, string field)
214+
{
215+
object value = null;
216+
217+
if ((page.ViewData[_contextKey] as GriddlyContext)?.Defaults.TryGetValue(field, out value) != true)
218+
value = null;
219+
220+
return value;
221+
}
222+
213223
public static object GetGriddlyParameter(this WebViewPage page, string field)
214224
{
215225
object value = null;
@@ -220,6 +230,11 @@ public static object GetGriddlyParameter(this WebViewPage page, string field)
220230
return value;
221231
}
222232

233+
public static int GetGriddlyParameterCount(this WebViewPage page)
234+
{
235+
return (page.ViewData[_contextKey] as GriddlyContext)?.Parameters.Count ?? 0;
236+
}
237+
223238
public static Dictionary<string, object> GetGriddlyDefaults(this WebViewPage page)
224239
{
225240
Dictionary<string, object> defaults = new Dictionary<string, object>();

Griddly.Mvc/GriddlyParameterAttribute.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
2626
string[] parentKeys = request.QueryString.AllKeys;
2727

2828
// if a param came in on querystring, skip the defaults. cookie already does its own skip.
29-
if (filterContext.ActionParameters.Any(x => x.Value != null && parentKeys.Contains(x.Key)))
29+
if (!context.IsDefaultSkipped && filterContext.ActionParameters.Any(x => x.Value != null && parentKeys.Contains(x.Key)))
3030
context.IsDefaultSkipped = true;
3131

3232
foreach (var param in filterContext.ActionParameters.ToList())
3333
{
3434
if (param.Value != null)
3535
{
36+
bool isParamSet = context.CookieData?.Values?.ContainsKey(param.Key) == true || parentKeys.Contains(param.Key) || filterContext.RouteData.Values.ContainsKey(param.Key);
37+
3638
// if we're skipping defaults but this didn't come from cookie or querystring, it must've come from a
3739
// parameter default in code... nuke it.
38-
if (context.IsDefaultSkipped && !(context.CookieData?.Values?.ContainsKey(param.Key) == true || parentKeys.Contains(param.Key)))
40+
if (context.IsDefaultSkipped && !isParamSet)
3941
filterContext.ActionParameters[param.Key] = null;
4042
else
4143
{
42-
context.Defaults[param.Key] = param.Value;
44+
if (!context.IsDefaultSkipped || !isParamSet)
45+
context.Defaults[param.Key] = param.Value;
46+
4347
context.Parameters[param.Key] = param.Value;
4448
}
4549
}

Griddly/Views/Shared/Griddly/Griddly.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
return this.GetGriddlyParameter(x.Field) != null || (filterRange != null && this.GetGriddlyParameter(filterRange.FieldEnd) != null);
108108
});
109109

110-
bool isDefaultFilter = defaultFilters.Any() == isFiltered
110+
bool isDefaultFilter = defaultFilters.Count == this.GetGriddlyParameterCount()
111111
&& defaultFilters.All(x =>
112112
{
113113
var param = this.GetGriddlyParameter(x.Key);

0 commit comments

Comments
 (0)