Skip to content

Split out filter bar so it can be used separately #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.4.5")]
[assembly: AssemblyFileVersion("2.4.5")]
//[assembly: AssemblyInformationalVersion("2.0-alpha6")]
[assembly: AssemblyVersion("2.5.0")]
[assembly: AssemblyFileVersion("2.5.0")]
//[assembly: AssemblyInformationalVersion("2.5-filters")]
1 change: 1 addition & 0 deletions Griddly.Mvc/Griddly.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="GriddlyFilterExtensions.cs" />
<Compile Include="GriddlyHtmlFilter.cs" />
<Compile Include="GriddlyExport.cs" />
<Compile Include="GriddlyFilterBarSettings.cs" />
<Compile Include="InternalExtensions.cs" />
<Compile Include="GriddlyButton.cs" />
<Compile Include="GriddlyColumn.cs" />
Expand Down
10 changes: 10 additions & 0 deletions Griddly.Mvc/GriddlyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public static MvcHtmlString Griddly(this HtmlHelper htmlHelper, GriddlyResultPag
}
}

public static MvcHtmlString GriddlyFilterBar(this HtmlHelper htmlHelper, GriddlyFilterBarSettings settings)
{
return htmlHelper.Partial("~/Views/Shared/Griddly/GriddlyFilterBar.cshtml", settings);
}

public static GriddlyColumn<TRow> GriddlyColumnFor<TRow>(this HtmlHelper<IEnumerable<TRow>> htmlHelper, Func<TRow, object> template)
{
return htmlHelper.GriddlyColumnFor<TRow>(template, null);
Expand Down Expand Up @@ -198,6 +203,11 @@ public static object GetGriddlyDefault(this WebViewPage page, string field)
return page.ViewData["_griddlyDefault_" + field];
}

public static void ForceGriddlyDefault(this Controller controller, string field, object value)
{
controller.ViewData["_griddlyDefault_" + field] = value;
}

public static Dictionary<string, object> GetGriddlyDefaults(this WebViewPage page)
{
Dictionary<string, object> defaults = new Dictionary<string, object>();
Expand Down
61 changes: 61 additions & 0 deletions Griddly.Mvc/GriddlyFilterBarSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
using System.Web.Routing;

namespace Griddly.Mvc
{
public class GriddlyFilterBarSettings
{
public GriddlyFilterBarSettings()
{
Filters = new List<GriddlyFilter>();
}

public List<GriddlyFilter> Filters { get; set; }

public GriddlyFilterBarSettings FilterBox(string field, string caption, FilterDataType dataType = FilterDataType.Decimal, string htmlClass = null, string captionPlural = null)
{
return Add(GriddlyFilterExtensions.FilterBox(null, dataType, field, caption, htmlClass, captionPlural));
}

public GriddlyFilterBarSettings FilterRange(string field, string fieldEnd, string caption, FilterDataType dataType = FilterDataType.Decimal, string htmlClass = null, string captionPlural = null)
{
return Add(GriddlyFilterExtensions.FilterRange(null, dataType, field, fieldEnd, caption, htmlClass, captionPlural));
}

public GriddlyFilterBarSettings FilterList(string field, string caption, IEnumerable<SelectListItem> items, bool isMultiple = true, bool defaultSelectAll = false, string nullItemText = null, bool isNoneAll = true, string htmlClass = null, string captionPlural = null, bool displayIncludeCaption = false)
{
return Add(GriddlyFilterExtensions.FilterList(null, items, isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption, htmlClass, captionPlural, displayIncludeCaption));
}

public GriddlyFilterBarSettings FilterEnum<T>(string field, string caption, bool isMultiple = true, bool defaultSelectAll = false, string nullItemText = null, bool isNoneAll = true, string htmlClass = null, string captionPlural = null, bool displayIncludeCaption = false)
where T : struct
{
return Add(GriddlyFilterExtensions.FilterEnum<T>(null, isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption, htmlClass, captionPlural, displayIncludeCaption));
}

public GriddlyFilterBarSettings FilterEnum<T>(string field, string caption, IEnumerable<T> items, bool isMultiple = true, bool defaultSelectAll = false, string nullItemText = null, bool isNoneAll = true, string htmlClass = null, string captionPlural = null, bool displayIncludeCaption = false)
where T : struct
{
return Add(GriddlyFilterExtensions.FilterEnum<T>(null, items, isMultiple, defaultSelectAll, nullItemText, isNoneAll, field, caption, htmlClass, captionPlural, displayIncludeCaption));
}

public GriddlyFilterBarSettings FilterBool(string field, string caption, string trueLabel = "Yes", string falseLabel = "No", string nullItemText = null, bool isMultiple = false, bool defaultSelectAll = false, bool isNoneAll = false, string htmlClass = null, string captionPlural = null, bool displayIncludeCaption = true)
{
return Add(GriddlyFilterExtensions.FilterBool(null, trueLabel, falseLabel, nullItemText, isMultiple, defaultSelectAll, isNoneAll, field, caption, htmlClass, captionPlural, displayIncludeCaption));
}

public GriddlyFilterBarSettings Add(GriddlyFilter filter)
{
Filters.Add(filter);

return this;
}
}
}
6 changes: 6 additions & 0 deletions Griddly/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public ActionResult HistoryTest()
return View();
}

public ActionResult FilterBar()
{
this.ForceGriddlyDefault("test", "hello world!");

return View();
}

public ActionResult Editly()
{
Expand Down
3 changes: 3 additions & 0 deletions Griddly/Griddly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
<Content Include="Views\Home\HistoryTest.cshtml" />
<Content Include="Views\Shared\Griddly\GriddlyFilterValues.cshtml" />
<Content Include="Views\Home\FilterBoxGrid - Copy.cshtml" />
<Content Include="Views\Shared\Griddly\GriddlyFilters.cshtml" />
<Content Include="Views\Home\FilterBar.cshtml" />
<Content Include="Views\Shared\Griddly\GriddlyFilterBar.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Griddly.Mvc\Griddly.Mvc.csproj">
Expand Down
Loading