DataTables.Mvc added.

Removed old model binding for DataTablesParams (Logs no uses the one from DataTables.Mvc)
pull/6/head
Mark McDowall 13 years ago
parent 2aedc48203
commit e6712e5aa2

@ -0,0 +1,17 @@
using DataTables.Mvc.Core.Helpers;
using DataTables.Mvc.Core.Models;
using System.Web.Mvc;
[assembly: WebActivator.PreApplicationStartMethod(typeof(NzbDrone.Web.App_Start.DataTablesModelBinderActivator), "Start")]
namespace NzbDrone.Web.App_Start
{
public static class DataTablesModelBinderActivator
{
public static void Start()
{
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParams)))
ModelBinders.Binders.Add(typeof(DataTablesParams), new DataTablesModelBinder());
}
}
}

@ -1,15 +0,0 @@
using System.Web.Mvc;
using System.Web.WebPages;
using NzbDrone.Web.Helpers;
using NzbDrone.Web.Models;
[assembly: WebActivator.PreApplicationStartMethod(typeof(NzbDrone.Web.App_Start.RegisterDatatablesModelBinder), "Start")]
namespace NzbDrone.Web.App_Start {
public static class RegisterDatatablesModelBinder {
public static void Start() {
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParams)))
ModelBinders.Binders.Add(typeof(DataTablesParams), new DataTablesModelBinder());
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Web.Mvc;
using DataTables.Mvc.Core.Models;
using NzbDrone.Common;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Web.Models;

@ -1,40 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NzbDrone.Web.Models;
namespace NzbDrone.Web.Helpers
{
/// <summary>
/// Model binder for datatables.js parameters a la http://geeksprogramando.blogspot.com/2011/02/jquery-datatables-plug-in-with-asp-mvc.html
/// </summary>
public class DataTablesModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
DataTablesParams obj = new DataTablesParams();
var request = controllerContext.HttpContext.Request.Params;
obj.iDisplayStart = Convert.ToInt32(request["iDisplayStart"]);
obj.iDisplayLength = Convert.ToInt32(request["iDisplayLength"]);
obj.iColumns = Convert.ToInt32(request["iColumns"]);
obj.sSearch = request["sSearch"];
obj.bEscapeRegex = Convert.ToBoolean(request["bEscapeRegex"]);
obj.iSortingCols = Convert.ToInt32(request["iSortingCols"]);
obj.sEcho = int.Parse(request["sEcho"]);
for (int i = 0; i < obj.iColumns; i++)
{
obj.bSortable.Add(Convert.ToBoolean(request["bSortable_" + i]));
obj.bSearchable.Add(Convert.ToBoolean(request["bSearchable_" + i]));
obj.sSearchColumns.Add(request["sSearch_" + i]);
obj.bEscapeRegexColumns.Add(Convert.ToBoolean(request["bEscapeRegex_" + i]));
obj.iSortCol.Add(Convert.ToInt32(request["iSortCol_" + i]));
obj.sSortDir.Add(request["sSortDir_" + i]);
}
return obj;
}
}
}

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace NzbDrone.Web.Models
{
public class DataTablesParams
{
public int iDisplayStart { get; set; }
public int iDisplayLength { get; set; }
public int iColumns { get; set; }
public string sSearch { get; set; }
public bool bEscapeRegex { get; set; }
public int iSortingCols { get; set; }
public int sEcho { get; set; }
public List<bool> bSortable { get; set; }
public List<bool> bSearchable { get; set; }
public List<string> sSearchColumns { get; set; }
public List<int> iSortCol { get; set; }
public List<string> sSortDir { get; set; }
public List<bool> bEscapeRegexColumns { get; set; }
public DataTablesParams()
{
bSortable = new List<bool>();
bSearchable = new List<bool>();
sSearchColumns = new List<string>();
iSortCol = new List<int>();
sSortDir = new List<string>();
bEscapeRegexColumns = new List<bool>();
}
}
}

@ -51,6 +51,9 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="DataTables.Mvc.Core">
<HintPath>..\packages\DataTables.Mvc.0.1.0.54\lib\DataTables.Mvc.Core.dll</HintPath>
</Reference>
<Reference Include="Dynamic">
<HintPath>..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll</HintPath>
</Reference>
@ -137,6 +140,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\DataTablesMvc.cs" />
<Compile Include="Helpers\Validation\RequiredIfAnyAttribute.cs" />
<Compile Include="Helpers\Validation\RequiredIfAttribute.cs" />
<Content Include="Content\DataTables-1.9.0\media\css\jquery.dataTables.css" />
@ -204,7 +208,6 @@
<Compile Include="App_Start\EntityFramework.SqlServerCompact.cs" />
<Compile Include="App_Start\Logging.cs" />
<Compile Include="App_Start\MiniProfiler.cs" />
<Compile Include="App_Start\RegisterDataTablesModelBinder.cs" />
<Compile Include="Filters\JsonErrorFilter.cs" />
<Compile Include="Controllers\CommandController.cs" />
<Compile Include="Controllers\DirectoryController.cs" />
@ -224,7 +227,6 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Helpers\DataTablesModelBinder.cs" />
<Compile Include="Helpers\HtmlIncludeExtentions.cs" />
<Compile Include="Helpers\LinkHelper.cs" />
<Compile Include="Helpers\ProfilerHelper.cs" />
@ -232,7 +234,6 @@
<Compile Include="Helpers\DescriptionExtension.cs" />
<Compile Include="Helpers\HtmlPrefixScopeExtensions.cs" />
<Compile Include="Helpers\IsCurrentActionHelper.cs" />
<Compile Include="Models\DataTablesParams.cs" />
<Compile Include="Models\JobModel.cs" />
<Compile Include="Models\LogModel.cs" />
<Compile Include="Models\PostUpgradeModel.cs" />

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DataTables.Mvc" version="0.1.0.54" />
<package id="DynamicQuery" version="1.0" />
<package id="EntityFramework" version="4.3.0" />
<package id="EntityFramework.SqlServerCompact" version="4.1.8482.2" />

@ -0,0 +1,17 @@
using DataTables.Mvc.Core.Helpers;
using DataTables.Mvc.Core.Models;
using System.Web.Mvc;
[assembly: WebActivator.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.DataTablesModelBinderActivator), "Start")]
namespace $rootnamespace$.App_Start
{
public static class DataTablesModelBinderActivator
{
public static void Start()
{
if (!ModelBinders.Binders.ContainsKey(typeof(DataTablesParams)))
ModelBinders.Binders.Add(typeof(DataTablesParams), new DataTablesModelBinder());
}
}
}

@ -0,0 +1,5 @@
param($installPath, $toolsPath, $package, $project)
$path = [System.IO.Path]
$appstart = $path::Combine($path::GetDirectoryName($project.FileName), "App_Start\DataTablesMvc.cs")
$DTE.ItemOperations.OpenFile($appstart)
Loading…
Cancel
Save