Skip to content

Commit 3e62bee

Browse files
committed
2 parents dce4d56 + 13be9e9 commit 3e62bee

22 files changed

+186
-267
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.0.42.0")]
19-
[assembly: AssemblyFileVersion("1.0.42.0")]
18+
[assembly: AssemblyVersion("1.0.50.0")]
19+
[assembly: AssemblyFileVersion("1.0.50.0")]

Griddly.Mvc/DapperGriddlyResult.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ namespace Griddly.Mvc
1111
public class DapperGriddlyResult<T> : GriddlyResult<T>
1212
{
1313
Func<IDbConnection> _getConnection;
14+
Func<IDbTransaction> _getTransaction;
1415
string _sql;
1516
object _param;
16-
Func<IDbConnection, string, object, IEnumerable<T>> _map;
17-
Action<IDbConnection, IList<T>> _massage;
17+
Func<IDbConnection, IDbTransaction, string, object, IEnumerable<T>> _map;
18+
Action<IDbConnection, IDbTransaction, IList<T>> _massage;
1819

1920
long? _overallCount = null;
2021
bool _fixedSort;
2122

22-
public DapperGriddlyResult(Func<IDbConnection> getConnection, string sql, object param, Func<IDbConnection, string, object, IEnumerable<T>> map = null, Action<IDbConnection, IList<T>> massage = null, bool fixedSort = false)
23+
public DapperGriddlyResult(Func<IDbConnection> getConnection, string sql, object param, Func<IDbConnection, IDbTransaction, string, object, IEnumerable<T>> map = null, Action<IDbConnection, IDbTransaction, IList<T>> massage = null, bool fixedSort = false, Func<IDbTransaction> getTransaction = null)
2324
: base(null)
2425
{
2526
_getConnection = getConnection;
@@ -33,6 +34,7 @@ public DapperGriddlyResult(Func<IDbConnection> getConnection, string sql, object
3334

3435
_massage = massage;
3536
_fixedSort = fixedSort;
37+
_getTransaction = getTransaction;
3638
}
3739

3840
public override long GetCount()
@@ -44,8 +46,9 @@ public override long GetCount()
4446
try
4547
{
4648
IDbConnection cn = _getConnection();
49+
IDbTransaction tx = _getTransaction != null ? _getTransaction() : null;
4750

48-
_overallCount = cn.Query<long>(sql, _param).Single();
51+
_overallCount = cn.Query<long>(sql, _param, tx).Single();
4952

5053
}
5154
catch (Exception ex)
@@ -84,7 +87,7 @@ IList<T> ExecuteQuery(string sql, object param)
8487
{
8588
try
8689
{
87-
IEnumerable<T> result = _map(_getConnection(), sql, param);
90+
IEnumerable<T> result = _map(_getConnection(), _getTransaction != null ? _getTransaction() : null, sql, param);
8891
IHasOverallCount overallCount = result as IHasOverallCount;
8992

9093
if (overallCount != null)
@@ -93,7 +96,7 @@ IList<T> ExecuteQuery(string sql, object param)
9396
IList<T> results = result.ToList();
9497

9598
if (_massage != null)
96-
_massage(_getConnection(), results);
99+
_massage(_getConnection(), _getTransaction != null ? _getTransaction() : null, results);
97100

98101
return results;
99102
}
@@ -103,9 +106,9 @@ IList<T> ExecuteQuery(string sql, object param)
103106
}
104107
}
105108

106-
protected IEnumerable<T> DefaultMap(IDbConnection cn, string sql, object param)
109+
protected IEnumerable<T> DefaultMap(IDbConnection cn, IDbTransaction tx, string sql, object param)
107110
{
108-
IEnumerable<T> result = cn.Query<T>(sql, param);
111+
IEnumerable<T> result = cn.Query<T>(sql, param, tx);
109112

110113
if (typeof(IHasOverallCount).IsAssignableFrom(typeof(T)))
111114
{

Griddly.Mvc/Griddly.Mvc.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
<Compile Include="GriddlyButton.cs" />
9696
<Compile Include="GriddlyColumn.cs" />
9797
<Compile Include="GriddlyCsvResult.cs" />
98-
<Compile Include="GriddlyDefaultParametersAttribute.cs" />
9998
<Compile Include="GriddlyExcelResult.cs" />
10099
<Compile Include="GriddlyExtensions.cs" />
101100
<Compile Include="GriddlyFilter.cs" />

Griddly.Mvc/GriddlyButton.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ public class GriddlyButton
2323

2424
public List<GriddlyButton> Buttons { get; set; }
2525

26-
public GriddlyButton()
26+
public GriddlyButton(string additionalClassName = null)
2727
{
2828
Buttons = new List<GriddlyButton>();
2929

3030
Enabled = true;
3131
Action = GriddlyButtonAction.Navigate;
32-
ClassName = GriddlySettings.DefaultButtonClassName;
32+
33+
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
3334
}
3435

3536
public GriddlyButton Add(GriddlyButton item)

Griddly.Mvc/GriddlyCsvResult.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
using System;
1+
using CsvHelper;
2+
using CsvHelper.Configuration;
23
using System.Collections.Generic;
3-
using System.Text.RegularExpressions;
44
using System.Web.Mvc;
5-
using CsvHelper;
6-
using CsvHelper.Configuration;
7-
using OfficeOpenXml;
85

96
namespace Griddly.Mvc
107
{

Griddly.Mvc/GriddlyDefaultParametersAttribute.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

Griddly.Mvc/GriddlyExcelResult.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
1+
using OfficeOpenXml;
2+
using OfficeOpenXml.Style;
3+
using System;
24
using System.Collections.Generic;
3-
using System.Text.RegularExpressions;
45
using System.Web.Mvc;
5-
using OfficeOpenXml;
6-
using OfficeOpenXml.Style;
76

87
namespace Griddly.Mvc
98
{
@@ -43,7 +42,7 @@ public override void ExecuteResult(ControllerContext context)
4342
object renderedValue = _settings.Columns[x].RenderCellValue(row, true);
4443

4544
ExcelRange cell = ws.Cells[y + 2, x + 1];
46-
45+
4746
cell.Value = renderedValue;
4847

4948
if (renderedValue as DateTime? != null)

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ public static HtmlString AttributeIf(this HtmlHelper helper, string name, bool s
100100
return null;
101101
}
102102

103+
public static void SetGriddlyDefault<T>(this Controller controller, ref T parameter, string field, T value)
104+
{
105+
if (controller.ControllerContext.IsChildAction)
106+
parameter = value;
107+
108+
controller.ViewData["_griddlyDefault_" + field] = value;
109+
}
110+
111+
public static object GetGriddlyDefault(this WebViewPage page, string field)
112+
{
113+
return page.ViewData["_griddlyDefault_" + field];
114+
}
115+
103116
static IDictionary<string, object> ObjectToDictionary(object value)
104117
{
105118
if (value == null)
@@ -120,8 +133,10 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
120133
{
121134
Type t = value.Value.GetType();
122135

123-
if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
136+
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
124137
values[value.Key] = value.Value;
138+
else if (t.HasCastOperator<DateTime>())
139+
values[value.Key] = (DateTime)value.Value;
125140
}
126141
}
127142

@@ -139,8 +154,10 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
139154
{
140155
Type t = value.Value.GetType();
141156

142-
if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
157+
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
143158
values[value.Key] = value.Value;
159+
else if (t.HasCastOperator<DateTime>())
160+
values[value.Key] = (DateTime)value.Value;
144161
}
145162
}
146163
}

Griddly.Mvc/GriddlyFilter.cs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Data.Entity.Design.PluralizationServices;
45
using System.Globalization;
56
using System.Web.Mvc;
7+
using System.Linq;
68

79
namespace Griddly.Mvc
810
{
911
public abstract class GriddlyFilter
1012
{
11-
string _name;
13+
string _caption;
1214

13-
public string Name
15+
public string Caption
1416
{
1517
get
1618
{
17-
return _name;
19+
return _caption;
1820
}
1921
set
2022
{
2123
if (!string.IsNullOrWhiteSpace(value))
22-
NamePlural = PluralizationService.CreateService(CultureInfo.CurrentUICulture).Pluralize(value);
24+
CaptionPlural = PluralizationService.CreateService(CultureInfo.CurrentUICulture).Pluralize(value);
2325
else
24-
NamePlural = null;
26+
CaptionPlural = null;
2527

26-
_name = value;
28+
_caption = value;
2729
}
2830
}
2931

30-
public string NamePlural { get; set; }
32+
public string CaptionPlural { get; set; }
3133

3234
public string Field { get; set; }
33-
public object Default { get; set; }
3435
public virtual FilterDataType DataType { get; set; }
3536

3637
public string GetFormattedValue(object value)
@@ -79,7 +80,6 @@ public override FilterDataType DataType
7980
}
8081
}
8182
public string FieldEnd { get; set; }
82-
public object DefaultEnd { get; set; }
8383
}
8484

8585
public class GriddlyFilterList : GriddlyFilter
@@ -97,8 +97,51 @@ public GriddlyFilterList()
9797
public bool IsMultiple { get; set; }
9898
public bool IsNoneAll { get; set; }
9999
public bool IsNullable { get; set; }
100+
public bool DefaultSelectAll { get; set; }
100101

101102
public int DisplayItemCount { get; set; }
103+
104+
public void SetSelectedItems(object value)
105+
{
106+
if (IsMultiple && DefaultSelectAll && value == null)
107+
{
108+
// TODO: set default value to all selected
109+
foreach (SelectListItem item in SelectableItems)
110+
item.Selected = true;
111+
}
112+
else if (!IsMultiple || value != null)
113+
{
114+
if (value != null)
115+
{
116+
IEnumerable defaultValues = value as IEnumerable;
117+
118+
if (defaultValues == null || value is string)
119+
{
120+
string valueString = value.ToString();
121+
122+
foreach (SelectListItem item in SelectableItems)
123+
item.Selected = item.Value == valueString;
124+
}
125+
else
126+
{
127+
foreach (object valueObject in defaultValues)
128+
{
129+
string valueString = valueObject.ToString();
130+
131+
foreach (SelectListItem item in SelectableItems.Where(x => x.Value == valueString))
132+
item.Selected = true;
133+
}
134+
}
135+
}
136+
else
137+
{
138+
// TODO: set default value to all selected
139+
for (int i = 0; i < SelectableItems.Count; i++)
140+
Items[i].Selected = (i == 0);
141+
}
142+
}
143+
144+
}
102145
}
103146

104147
public enum FilterDataType

0 commit comments

Comments
 (0)