Skip to content

Commit b4f5581

Browse files
committed
Merge pull request #2 from ithielnor/expose-sorts
Expose sorts
2 parents 72babb7 + fbfb0b8 commit b4f5581

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
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.40.0")]
19-
[assembly: AssemblyFileVersion("1.0.40.0")]
18+
[assembly: AssemblyVersion("1.0.41.0")]
19+
[assembly: AssemblyFileVersion("1.0.41.0")]

Build/publish-nuget.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# http://www.jeremyskinner.co.uk/2011/01/12/automating-nuget-package-creation-with-msbuild-and-powershell/
22

3-
msbuild
3+
$scriptpath = split-path -parent $MyInvocation.MyCommand.Path
4+
5+
msbuild $scriptpath/build.proj
46

57
Function Get-DropBox() {
68
$hostFile = Join-Path (Split-Path (Get-ItemProperty HKCU:\Software\Dropbox).InstallPath) "host.db"
@@ -10,12 +12,11 @@ Function Get-DropBox() {
1012

1113
$dropbox = Get-DropBox
1214
$keyfile = "$dropbox\Personal\nuget-key.txt"
13-
$scriptpath = split-path -parent $MyInvocation.MyCommand.Path
1415
$nugetpath = resolve-path "$scriptpath/../.nuget/nuget.exe"
1516
$packagespath = resolve-path "$scriptpath/packages"
1617

1718
if(-not (test-path $keyfile)) {
18-
throw "Could not find the NuGet access key at $keyfile. If you're not Chris, you shouldn't be running this script!"
19+
throw "Could not find the NuGet access key at $keyfile. If you're not the project owner, you shouldn't be running this script!"
1920
}
2021
else {
2122
pushd $packagespath

Griddly.Mvc/GriddlyResult.cs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,38 @@
55
using System.Linq;
66
using System.Linq.Expressions;
77
using System.Reflection;
8+
using System.Web;
89
using System.Web.Helpers;
910
using System.Web.Mvc;
1011

1112
namespace Griddly.Mvc
1213
{
1314
public abstract class GriddlyResult : ActionResult
1415
{
16+
public SortField[] GetSortFields(NameValueCollection items)
17+
{
18+
return items.AllKeys
19+
.Where(x => x.StartsWith("sortFields["))
20+
.Select(x =>
21+
{
22+
int pos = x.IndexOf(']', "sortFields[".Length);
23+
24+
return new
25+
{
26+
Index = int.Parse(x.Substring("sortFields[".Length, pos - "sortFields[".Length)),
27+
Field = x.Substring(pos + 2, x.Length - pos - 2 - 1),
28+
Direction = (SortDirection)Enum.Parse(typeof(SortDirection), items[x])
29+
};
1530

31+
})
32+
.OrderBy(x => x.Index)
33+
.Select(x => new SortField()
34+
{
35+
Field = x.Field,
36+
Direction = x.Direction
37+
})
38+
.ToArray();
39+
}
1640
}
1741

1842
public class GriddlyResult<T> : GriddlyResult
@@ -41,41 +65,26 @@ public override void ExecuteResult(ControllerContext context)
4165

4266
if (!int.TryParse(items["pageNumber"], out pageNumber))
4367
pageNumber = 0;
68+
4469
if (!int.TryParse(items["pageSize"], out pageSize))
4570
pageSize = 20;
71+
4672
if (Enum.TryParse(items["exportFormat"], true, out exportFormatValue))
4773
exportFormat = exportFormatValue;
4874
else
4975
exportFormat = null;
5076

51-
sortFields = items.AllKeys
52-
.Where(x => x.StartsWith("sortFields["))
53-
.Select(x =>
54-
{
55-
int pos = x.IndexOf(']', "sortFields[".Length);
56-
57-
return new
58-
{
59-
Index = int.Parse(x.Substring("sortFields[".Length, pos - "sortFields[".Length)),
60-
Field = x.Substring(pos + 2, x.Length - pos - 2 - 1),
61-
Direction = (SortDirection)Enum.Parse(typeof(SortDirection), items[x])
62-
};
63-
64-
})
65-
.OrderBy(x => x.Index)
66-
.Select(x => new SortField()
67-
{
68-
Field = x.Field,
69-
Direction = x.Direction
70-
})
71-
.ToArray();
77+
sortFields = GetSortFields(items);
7278

7379
GriddlySettings settings = null;
7480

7581
if (context.IsChildAction)
7682
{
7783
settings = GriddlySettingsResult.GetSettings(context, ViewName);
7884

85+
if (GriddlySettings.OnGriddlyResultExecuting != null)
86+
GriddlySettings.OnGriddlyResultExecuting(settings);
87+
7988
// TODO: should we always pull sort fields?
8089
if (!sortFields.Any())
8190
sortFields = settings.GetDefaultSort();

Griddly.Mvc/GriddlySettings.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public abstract class GriddlySettings
2525
public static Func<GriddlyResultPage, object> DefaultFooterTemplate = null;
2626
public static Func<string, IEnumerable, ActionResult> HandleCustomReport = null;
2727
public static Action<GriddlySettings> BeforeRender = null;
28+
public static Action<GriddlySettings> OnGriddlyResultExecuting = null;
2829

2930
public GriddlySettings()
3031
{
@@ -131,33 +132,39 @@ public GriddlySettings Button(Func<object, object> argumentTemplate, string capt
131132
if (enableOnSelection == null)
132133
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
133134

134-
return Add(new GriddlyButton()
135+
var button = new GriddlyButton()
135136
{
136137
ArgumentTemplate = argumentTemplate,
137138
Text = caption,
138139
Icon = icon,
139140
Action = action,
140141
EnableOnSelection = enableOnSelection.Value,
141-
ClassName = className,
142142
Target = target
143-
});
143+
};
144+
145+
button.ClassName = ((button.ClassName ?? "") + " " + (className ?? "")).Trim();
146+
147+
return Add(button);
144148
}
145149

146150
public GriddlySettings Button(string argument, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, bool? enableOnSelection = null, string className = null, string target = null)
147151
{
148152
if (enableOnSelection == null)
149153
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
150154

151-
return Add(new GriddlyButton()
155+
var button = new GriddlyButton()
152156
{
153157
Argument = argument,
154158
Text = caption,
155159
Icon = icon,
156160
Action = action,
157161
EnableOnSelection = enableOnSelection.Value,
158-
ClassName = className,
159162
Target = target
160-
});
163+
};
164+
165+
button.ClassName = ((button.ClassName ?? "") + " " + (className ?? "")).Trim();
166+
167+
return Add(button);
161168
}
162169

163170
public GriddlySettings ButtonSeparator()

0 commit comments

Comments
 (0)