Skip to content

Commit 0bcd0b9

Browse files
authored
Merge pull request #10 from programcsharp/master
update
2 parents b1d060b + d68ca13 commit 0bcd0b9

20 files changed

+371
-180
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Runtime.InteropServices;
33

44
[assembly: AssemblyProduct("Griddly")]
5-
[assembly: AssemblyCopyright("Copyright © 2015 Chris Hynes and Data Research Group")]
5+
[assembly: AssemblyCopyright("Copyright © 2013-2017 Chris Hynes and Data Research Group")]
66

77
[assembly: ComVisible(false)]
88

@@ -15,6 +15,6 @@
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.5.22")]
19-
[assembly: AssemblyFileVersion("1.5.22")]
18+
[assembly: AssemblyVersion("1.8.0")]
19+
[assembly: AssemblyFileVersion("1.8.0")]
2020
//[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]

Griddly.Mvc/GriddlyButton.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public GriddlyButton(string additionalClassName = null)
3737
public string ConfirmMessage { get; set; }
3838
public bool AlignRight { get; set; }
3939

40+
/// <summary>
41+
/// A function name to use to show the confirm message. Takes two parameters, message and callback. Callback is a function to call to continue the button click if the confirm was accepted.
42+
/// </summary>
43+
public string ConfirmPromptFunction { get; set; }
44+
4045
/// <summary>
4146
/// The row ids to include in the button action (default uses grid default)
4247
/// </summary>

Griddly.Mvc/GriddlyFilter.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void SetSelectedItems(object value)
126126

127127
if (defaultValues == null || value is string)
128128
{
129-
string valueString = value.ToString();// GetValueString(value);
129+
string valueString = GetValueString(value);
130130

131131
foreach (SelectListItem item in SelectableItems)
132132
item.Selected = item.Value == valueString;
@@ -137,7 +137,7 @@ public void SetSelectedItems(object value)
137137
{
138138
if (valueObject != null)
139139
{
140-
string valueString = valueObject.ToString();// GetValueString(valueObject);
140+
string valueString = GetValueString(valueObject);
141141

142142
foreach (SelectListItem item in SelectableItems.Where(x => x.Value == valueString))
143143
item.Selected = true;
@@ -159,6 +159,15 @@ public void SetSelectedItems(object value)
159159
}
160160
}
161161

162+
string GetValueString(object value)
163+
{
164+
string result = value.ToString();
165+
166+
if (value is bool)
167+
result = result.ToLower();
168+
169+
return result;
170+
}
162171
//string GetValueString(object value)
163172
//{
164173
// Type valueType = Nullable.GetUnderlyingType(value.GetType()) ?? value.GetType();

Griddly.Mvc/GriddlyFilterExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ static List<SelectListItem> BuildBoolItems(string trueLabel, string falseLabel)
149149
{
150150
return new List<SelectListItem>()
151151
{
152-
new SelectListItem() { Value = "True", Text = trueLabel },
153-
new SelectListItem() { Value = "False", Text = falseLabel },
152+
new SelectListItem() { Value = "true", Text = trueLabel },
153+
new SelectListItem() { Value = "false", Text = falseLabel },
154154
};
155155
}
156156
}

Griddly.Mvc/GriddlyResult.cs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public SortField[] GetSortFields(NameValueCollection items)
3737
})
3838
.ToArray();
3939
}
40+
41+
public abstract IEnumerable GetAllNonGeneric(SortField[] sortFields);
42+
43+
public abstract IList GetPageNonGeneric(int pageNumber, int pageSize, SortField[] sortFields);
44+
45+
public abstract void PopulateSummaryValuesNonGeneric(GriddlySettings settings);
46+
47+
public abstract long GetCount();
48+
49+
public abstract IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields);
4050
}
4151

4252
public abstract class GriddlyResult<T> : GriddlyResult
@@ -143,20 +153,23 @@ public override void ExecuteResult(ControllerContext context)
143153
fileName = fileName.Replace(c, '_');
144154
}
145155

146-
var records = GetAll(sortFields);
147156
if (exportFormat == GriddlyExportFormat.Custom)
148157
{
149-
result = GriddlySettings.HandleCustomExport(records, items);
158+
result = GriddlySettings.HandleCustomExport(this, items);
150159
}
151-
else if (exportFormat == GriddlyExportFormat.Xlsx)
160+
else
152161
{
153-
result = new GriddlyExcelResult<T>(records, settings, fileName, items["exportName"]);
154-
}
155-
else // if (exportFormat == GriddlyExportFormat.Csv || exportFormat == GriddlyExportFormat.Tsv)
156-
{
157-
result = new GriddlyCsvResult<T>(records, settings, fileName, exportFormat.Value, items["exportName"]);
162+
var records = GetAll(sortFields);
163+
if (exportFormat == GriddlyExportFormat.Xlsx)
164+
{
165+
result = new GriddlyExcelResult<T>(records, settings, fileName, items["exportName"]);
166+
}
167+
else // if (exportFormat == GriddlyExportFormat.Csv || exportFormat == GriddlyExportFormat.Tsv)
168+
{
169+
result = new GriddlyCsvResult<T>(records, settings, fileName, exportFormat.Value, items["exportName"]);
170+
}
158171
}
159-
172+
160173
result.ExecuteResult(context);
161174
}
162175
}
@@ -167,7 +180,25 @@ public override void ExecuteResult(ControllerContext context)
167180

168181
public abstract void PopulateSummaryValues(GriddlySettings<T> settings);
169182

170-
public abstract long GetCount();
183+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
184+
{
185+
throw new NotImplementedException();
186+
}
187+
188+
public override IEnumerable GetAllNonGeneric(SortField[] sortFields)
189+
{
190+
return GetAll(sortFields);
191+
}
192+
193+
public override IList GetPageNonGeneric(int pageNumber, int pageSize, SortField[] sortFields)
194+
{
195+
return (IList)(GetPage(pageNumber, pageSize, sortFields).ToList());
196+
}
197+
198+
public override void PopulateSummaryValuesNonGeneric(GriddlySettings settings)
199+
{
200+
PopulateSummaryValues((GriddlySettings<T>)settings);
201+
}
171202
}
172203

173204
public enum GriddlyExportFormat

Griddly.Mvc/GriddlySettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public abstract class GriddlySettings
3333
/// Defines an event handler for custom export requests.
3434
///
3535
/// First argument is the record set. Second argument is the posted form values.
36-
/// </summary>s
37-
public static Func<IEnumerable, NameValueCollection, ActionResult> HandleCustomExport = null;
36+
/// </summary>
37+
public static Func<GriddlyResult, NameValueCollection, ActionResult> HandleCustomExport = null;
3838
public static Action<GriddlySettings, HtmlHelper> BeforeRender = null;
3939
public static Action<GriddlySettings, ControllerContext> OnGriddlyResultExecuting = null;
4040

Griddly.Mvc/Results/DapperResult.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ public override void PopulateSummaryValues(GriddlySettings<T> settings)
7979
}
8080
}
8181

82+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
83+
{
84+
if (propertyName.Contains("."))
85+
throw new ArgumentException($"Property name may not contain a period. \"{propertyName}\"", "propertyName");
86+
87+
string sql = $"SELECT {propertyName} as _val FROM ({_sql}) [_proj] {(_fixedSort ? "" : $"ORDER BY {BuildSortClause(sortFields) ?? "CURRENT_TIMESTAMP"}")}";
88+
89+
try
90+
{
91+
IDbConnection cn = _getConnection();
92+
IDbTransaction tx = _getTransaction != null ? _getTransaction() : null;
93+
94+
return cn.Query<P>(sql, _param, tx);
95+
}
96+
catch (Exception ex)
97+
{
98+
throw new DapperGriddlyException($"Error selecting property: {propertyName}.", sql, _param, ex);
99+
}
100+
}
101+
82102
public override long GetCount()
83103
{
84104
if (_overallCount == null)
@@ -109,12 +129,10 @@ protected string BuildSortClause(SortField[] sortFields)
109129

110130
protected virtual X ExecuteSingle<X>(string sql)
111131
{
112-
113-
IDbConnection cn = _getConnection();
114-
IDbTransaction tx = _getTransaction != null ? _getTransaction() : null;
132+
IDbConnection cn = _getConnection();
133+
IDbTransaction tx = _getTransaction != null ? _getTransaction() : null;
115134

116-
return cn.Query<X>(sql, _param, tx).Single();
117-
135+
return cn.Query<X>(sql, _param, tx).Single();
118136
}
119137

120138
// TODO: return IEnumerable so we don't have to .ToList()

Griddly.Mvc/Results/MapQueryableResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public override void PopulateSummaryValues(GriddlySettings<TOut> settings)
4040
_result.PopulateSummaryValue(c);
4141
}
4242

43+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
44+
{
45+
return _result.GetAllForProperty<P>(propertyName, sortFields);
46+
}
47+
4348
public override long GetCount()
4449
{
4550
return _result.GetCount();

Griddly.Mvc/Results/QueryableResult.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ internal void PopulateSummaryValue(GriddlyColumn c)
9393
}
9494
}
9595

96+
public override IEnumerable<P> GetAllForProperty<P>(string propertyName, SortField[] sortFields)
97+
{
98+
return ApplySortFields(_result, sortFields)
99+
.Select<P>(propertyName, null);
100+
}
101+
96102
public override long GetCount()
97103
{
98104
return _result.Count();

Griddly/Controllers/HomeController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
using Griddly.Mvc.Results;
55
using System;
66
using System.Collections.Generic;
7+
using System.Collections.Specialized;
78
using System.Linq;
89
using System.Web.Mvc;
910

1011
namespace Griddly.Controllers
1112
{
1213
public class HomeController : Controller
1314
{
15+
public static ActionResult HandleCustomExport(GriddlyResult result, NameValueCollection form)
16+
{
17+
return new JsonResult()
18+
{
19+
Data = result.GetAllForProperty<long?>("Id", null),
20+
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
21+
};
22+
}
23+
1424
public ActionResult Index()
1525
{
1626
return View();

Griddly/Scripts/editly.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Editly script
33
* http://griddly.com
4-
* Copyright 2013-2015 Chris Hynes and Data Research Group, Inc.
4+
* Copyright 2013-2017 Chris Hynes and Data Research Group, Inc.
55
* Licensed under MIT (https://github.com/programcsharp/griddly/blob/master/LICENSE)
66
*
77
* WARNING: Don't edit this file -- it'll be overwitten when you upgrade.

0 commit comments

Comments
 (0)