Skip to content

Commit 8520b29

Browse files
committed
2 parents b3d1c76 + 75b14bc commit 8520b29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3704
-3046
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.43.0")]
19-
[assembly: AssemblyFileVersion("1.0.43.0")]
18+
[assembly: AssemblyVersion("1.0.65.0")]
19+
[assembly: AssemblyFileVersion("1.0.65.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 & 7 deletions
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" />
@@ -116,12 +115,6 @@
116115
</ItemGroup>
117116
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
118117
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
119-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
120-
<PropertyGroup>
121-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
122-
</PropertyGroup>
123-
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
124-
</Target>
125118
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
126119
Other similar extension points exist, see Microsoft.Common.targets.
127120
<Target Name="BeforeBuild">

Griddly.Mvc/GriddlyButton.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class GriddlyButton
1414
public bool IsSeparator { get; set; }
1515
public bool IsSplitDropdown { get; set; }
1616
public string Text { get; set; }
17+
public string Title { get; set; }
1718
public string Icon { get; set; }
1819
public string ClassName { get; set; }
1920
public string Target { get; set; }
@@ -23,13 +24,14 @@ public class GriddlyButton
2324

2425
public List<GriddlyButton> Buttons { get; set; }
2526

26-
public GriddlyButton()
27+
public GriddlyButton(string additionalClassName = null)
2728
{
2829
Buttons = new List<GriddlyButton>();
2930

3031
Enabled = true;
3132
Action = GriddlyButtonAction.Navigate;
32-
ClassName = GriddlySettings.DefaultButtonClassName;
33+
34+
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
3335
}
3436

3537
public GriddlyButton Add(GriddlyButton item)

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using System.Web;
56
using System.Web.Helpers;
@@ -21,7 +22,7 @@ public abstract class GriddlyColumn
2122

2223
public abstract HtmlString RenderCell(object row, bool encode = true);
2324
public abstract object RenderCellValue(object row, bool stripHtml = false);
24-
public abstract string RenderClassName(object row);
25+
public abstract string RenderClassName(object row, GriddlyResultPage page);
2526

2627
protected virtual HtmlString RenderValue(object value, bool encode = true)
2728
{
@@ -57,15 +58,17 @@ public class GriddlyColumn<TRow> : GriddlyColumn
5758

5859
static readonly Regex _htmlMatch = new Regex(@"<[^>]*>", RegexOptions.Compiled);
5960

60-
public override string RenderClassName(object row)
61+
public override string RenderClassName(object row, GriddlyResultPage page)
6162
{
6263
HashSet<string> classes = new HashSet<string>();
6364

6465
if (!string.IsNullOrWhiteSpace(ClassName))
6566
classes.UnionWith(ClassName.Split(' '));
6667

67-
if (DefaultSort != null)
68-
classes.Add("sorted_" + (DefaultSort == SortDirection.Descending ? "d" : "a"));
68+
SortField field = !string.IsNullOrWhiteSpace(SortField) && page.SortFields != null ? page.SortFields.FirstOrDefault(x => x.Field == SortField) : null;
69+
70+
if (field != null)
71+
classes.Add("sorted_" + (field.Direction == SortDirection.Descending ? "d" : "a"));
6972

7073
if (ClassNameExpression != null)
7174
{
@@ -135,7 +138,8 @@ public override object RenderCellValue(object row, bool stripHtml = false)
135138
else if (value is Enum)
136139
value = Extensions.ToStringDescription((Enum)value);
137140
else if (value != null && value.GetType().HasCastOperator<DateTime>())
138-
value = (DateTime)value;
141+
// value = (DateTime)value; -- BAD: can't unbox a value type as a different type
142+
value = Convert.ChangeType(value, typeof(DateTime));
139143

140144
if (stripHtml && value is string)
141145
value = HttpUtility.HtmlDecode(_htmlMatch.Replace(value.ToString(), "").Trim().Replace(" ", " "));

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: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@ 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 void SetGriddlyDefault<T>(this Controller controller, ref T[] parameter, string field, IEnumerable<T> value)
112+
{
113+
if (controller.ControllerContext.IsChildAction)
114+
parameter = value.ToArray();
115+
116+
controller.ViewData["_griddlyDefault_" + field] = value;
117+
}
118+
119+
public static void SetGriddlyDefault<T>(this Controller controller, ref T?[] parameter, string field, IEnumerable<T> value)
120+
where T: struct
121+
{
122+
if (controller.ControllerContext.IsChildAction)
123+
parameter = value.Cast<T?>().ToArray();
124+
125+
controller.ViewData["_griddlyDefault_" + field] = value;
126+
}
127+
128+
public static object GetGriddlyDefault(this WebViewPage page, string field)
129+
{
130+
return page.ViewData["_griddlyDefault_" + field];
131+
}
132+
103133
static IDictionary<string, object> ObjectToDictionary(object value)
104134
{
105135
if (value == null)
@@ -120,8 +150,12 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
120150
{
121151
Type t = value.Value.GetType();
122152

123-
if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
153+
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
124154
values[value.Key] = value.Value;
155+
else if (t.HasCastOperator<DateTime>())
156+
// values[value.Key] = (DateTime)value.Value; -- BAD: can't unbox a value type as a different type
157+
values[value.Key] = Convert.ChangeType(value.Value, typeof(DateTime));
158+
125159
}
126160
}
127161

@@ -139,8 +173,11 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
139173
{
140174
Type t = value.Value.GetType();
141175

142-
if (t.IsPrimitive || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
176+
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
143177
values[value.Key] = value.Value;
178+
else if (t.HasCastOperator<DateTime>())
179+
// values[value.Key] = (DateTime)value.Value; -- BAD: can't unbox a value type as a different type
180+
values[value.Key] = Convert.ChangeType(value.Value, typeof(DateTime));
144181
}
145182
}
146183
}

0 commit comments

Comments
 (0)