Skip to content

Commit 83dc345

Browse files
committed
Merge pull request #15 from ithielnor/master
Added new features up to 1.0.74
2 parents e179583 + d9220d2 commit 83dc345

File tree

6 files changed

+134
-65
lines changed

6 files changed

+134
-65
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.73.1")]
19-
[assembly: AssemblyFileVersion("1.0.73.1")]
18+
[assembly: AssemblyVersion("1.0.74.0")]
19+
[assembly: AssemblyFileVersion("1.0.74.0")]

Griddly.Mvc/GriddlyButton.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ namespace Griddly.Mvc
66
{
77
public class GriddlyButton
88
{
9+
public GriddlyButton(string additionalClassName = null)
10+
{
11+
Buttons = new List<GriddlyButton>();
12+
13+
Enabled = true;
14+
Action = GriddlyButtonAction.Navigate;
15+
16+
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
17+
}
18+
919
public string Argument { get; set; }
1020
public Func<object, object> ArgumentTemplate { get; set; }
1121

@@ -20,26 +30,23 @@ public class GriddlyButton
2030
public string Target { get; set; }
2131
public string ConfirmMessage { get; set; }
2232
public bool AlignRight { get; set; }
33+
34+
/// <summary>
35+
/// The row ids to include in the button action (default uses grid default)
36+
/// </summary>
2337
public string[] RowIds { get; set; }
38+
2439
/// <summary>
2540
/// Append the selected row ids to the button href as comma separated query strings (only navigate and modal types supported)
2641
/// </summary>
2742
public bool AppendRowIdsToUrl { get; set; }
2843

44+
public IDictionary<string, object> HtmlAttributes { get; set; }
45+
2946
public GriddlyButtonAction Action { get; set; }
3047

3148
public List<GriddlyButton> Buttons { get; set; }
3249

33-
public GriddlyButton(string additionalClassName = null)
34-
{
35-
Buttons = new List<GriddlyButton>();
36-
37-
Enabled = true;
38-
Action = GriddlyButtonAction.Navigate;
39-
40-
ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
41-
}
42-
4350
public GriddlyButton Add(GriddlyButton item)
4451
{
4552
Buttons.Add(item);

Griddly.Mvc/GriddlySettings.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public GriddlySettings Add(GriddlyButton button)
147147
});
148148
}*/
149149

150-
public GriddlySettings Button(Func<object, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, bool? enableOnSelection = null, string className = null, string target = null, string[] rowIds = null)
150+
public GriddlySettings Button(Func<object, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, bool? enableOnSelection = null, string className = null, string target = null, string[] rowIds = null, object htmlAttributes = null)
151151
{
152152
if (enableOnSelection == null)
153153
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
@@ -163,10 +163,13 @@ public GriddlySettings Button(Func<object, object> argumentTemplate, string capt
163163
RowIds = rowIds
164164
};
165165

166+
if (htmlAttributes != null)
167+
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
168+
166169
return Add(button);
167170
}
168171

169-
public GriddlySettings Button(string argument, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, bool? enableOnSelection = null, string className = null, string target = null, string[] rowIds = null)
172+
public GriddlySettings Button(string argument, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, bool? enableOnSelection = null, string className = null, string target = null, string[] rowIds = null, object htmlAttributes = null)
170173
{
171174
if (enableOnSelection == null)
172175
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
@@ -182,6 +185,9 @@ public GriddlySettings Button(string argument, string caption, string icon = nul
182185
RowIds = rowIds
183186
};
184187

188+
if (htmlAttributes != null)
189+
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
190+
185191
return Add(button);
186192
}
187193

@@ -409,16 +415,21 @@ public GriddlySettings<TRow> SelectColumn(Dictionary<string, Func<TRow, object>>
409415
return this;
410416
}
411417

412-
public GriddlySettings<TRow> Button<TModel>(Func<TModel, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, string[] rowIds = null)
418+
public GriddlySettings<TRow> Button<TModel>(Func<TModel, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, string[] rowIds = null, object htmlAttributes = null)
413419
{
414-
Add(new GriddlyButton()
420+
var button = new GriddlyButton()
415421
{
416422
ArgumentTemplate = (x) => argumentTemplate((TModel)x),
417423
Text = caption,
418424
Icon = icon,
419425
Action = action,
420426
RowIds = rowIds
421-
});
427+
};
428+
429+
if (htmlAttributes != null)
430+
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
431+
432+
Add(button);
422433

423434
return this;
424435
}

Griddly/Views/Home/TestGrid.cshtml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,33 @@
1919
.Column(x => x.City, "City")
2020
.Column(x => x.State, "State")
2121
.Column(x => x.PostalCode, "Zip", template: x => Html.ActionLink("&" + x.PostalCode, "Profile"))
22+
2223
.Button("", "export", action: GriddlyButtonAction.Javascript, className: "export-xlsx")
2324
.Add(new GriddlyButton() { Text = "Confirm", Argument = "http://google.com", Action = GriddlyButtonAction.PostCriteria, ConfirmMessage = "Please confirm" })
24-
.Button("AlertSelectedIds", "Alert Selected", action: GriddlyButtonAction.Javascript, enableOnSelection: true)
25+
.Add(new GriddlyButton() { IsSeparator = true })
26+
.Add(new GriddlyButton() { IsSeparator = true })
27+
.Button("AlertSelectedIds", "Alert Selected", action: GriddlyButtonAction.Javascript, enableOnSelection: true, htmlAttributes: new { data_test = "hello world" })
28+
.Add(new GriddlyButton() { IsSeparator = true })
2529
.Button("TestPost", "Post Selected", action: GriddlyButtonAction.AjaxBulk, enableOnSelection: true)
30+
.Add(new GriddlyButton()
31+
{
32+
Text = "A dropdown in a group",
33+
Buttons = new List<GriddlyButton>()
34+
{
35+
new GriddlyButton() { Text = "1" },
36+
new GriddlyButton() { Text = "2" },
37+
new GriddlyButton() { Text = "3" }
38+
}
39+
})
40+
.Add(new GriddlyButton() { IsSeparator = true })
41+
.Add(new GriddlyButton()
42+
{
43+
Text = "A dropdown alone",
44+
Buttons = new List<GriddlyButton>()
45+
{
46+
new GriddlyButton() { Text = "1" },
47+
new GriddlyButton() { Text = "2" },
48+
new GriddlyButton() { Text = "3" }
49+
}
50+
})
2651
)

Griddly/Views/Shared/Griddly/BootstrapButton.cshtml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ else
3030
@RenderLink(Model, true, false)
3131
@if (Model.IsSplitDropdown)
3232
{
33-
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
33+
<button type="button" class="btn btn-default dropdown-toggle @GriddlySettings.DefaultButtonClassName" data-toggle="dropdown">
3434
<span class="caret"></span>
3535
</button>
3636
}
@@ -67,19 +67,26 @@ else
6767
}
6868

6969
<a data-role="griddly-button" class="@(!isMenuItem ? "btn btn-default" : null) @(isDropdown && !button.IsSplitDropdown ? "dropdown-toggle" : null) @(!button.Enabled || button.EnableOnSelection == true ? "disabled" : null) @button.ClassName @(!string.IsNullOrWhiteSpace(Model.Icon) ? "btn-with-icon" : null)"
70-
@*onclick="@(button.Action == GriddlyButtonAction.Javascript ? button.Argument : null)"*@
71-
title="@button.Title"
72-
@Html.AttributeIf("target", button.Action == GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
73-
@Html.AttributeIf("href", href != null, href)
74-
@Html.AttributeIf("data-toggle", button.Action != GriddlyButtonAction.Navigate && button.Action != GriddlyButtonAction.Javascript, button.Action.ToString().ToLower())
75-
@Html.AttributeIf("data-toggle", isDropdown && !button.IsSplitDropdown, "dropdown")
76-
@Html.AttributeIf("data-onclick", button.Action == GriddlyButtonAction.Javascript && button.Argument != null, button.Argument)
77-
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
78-
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
79-
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
80-
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
81-
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
82-
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")>
70+
@*onclick="@(button.Action == GriddlyButtonAction.Javascript ? button.Argument : null)"*@
71+
title="@button.Title"
72+
@Html.AttributeIf("target", button.Action == GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
73+
@Html.AttributeIf("href", href != null, href)
74+
@Html.AttributeIf("data-toggle", button.Action != GriddlyButtonAction.Navigate && button.Action != GriddlyButtonAction.Javascript, button.Action.ToString().ToLower())
75+
@Html.AttributeIf("data-toggle", isDropdown && !button.IsSplitDropdown, "dropdown")
76+
@Html.AttributeIf("data-onclick", button.Action == GriddlyButtonAction.Javascript && button.Argument != null, button.Argument)
77+
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
78+
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
79+
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
80+
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
81+
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
82+
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")
83+
@if (button.HtmlAttributes != null)
84+
{
85+
foreach (var attr in button.HtmlAttributes)
86+
{
87+
<text>@attr.Key="@attr.Value"</text>
88+
}
89+
}>
8390

8491
@if (!string.IsNullOrWhiteSpace(Model.Icon) && GriddlySettings.IconTemplate != null)
8592
{

Griddly/Views/Shared/Griddly/ButtonStrip.cshtml

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,81 @@
1111

1212
@model IList<GriddlyButton>
1313

14+
@functions{
15+
IEnumerable<IEnumerable<GriddlyButton>> GetGroups(IEnumerable<GriddlyButton> buttons)
16+
{
17+
List<IEnumerable<GriddlyButton>> groups = new List<IEnumerable<GriddlyButton>>();
18+
19+
List<GriddlyButton> currentList = null;
20+
foreach (var b in buttons)
21+
{
22+
if (currentList == null)
23+
{
24+
currentList = new List<GriddlyButton>();
25+
groups.Add(currentList);
26+
}
27+
28+
if (b.IsSeparator)
29+
{
30+
currentList = null;
31+
}
32+
else
33+
{
34+
currentList.Add(b);
35+
}
36+
}
37+
38+
groups.RemoveAll(x => x.Count() == 0);
39+
40+
return groups;
41+
}
42+
}
43+
1444
@{
15-
var leftButtons = Model.Where(x => !x.AlignRight && ViewBag.AlignRight != true);
16-
var rightButtons = Model.Where(x => x.AlignRight || ViewBag.AlignRight == true);
45+
var leftGroups = GetGroups(Model.Where(x => !x.AlignRight && ViewBag.AlignRight != true));
46+
var rightGroups = GetGroups(Model.Where(x => x.AlignRight || ViewBag.AlignRight == true));
1747
}
1848

1949
@if (Model.Any())
2050
{
21-
if (rightButtons.Any())
51+
if (rightGroups.Any())
2252
{
2353
<div class="btn-toolbar @ViewBag.ClassName pull-right">
24-
@if (rightButtons.Count() > 1)
54+
@foreach (var group in rightGroups)
2555
{
26-
@:<div class="btn-group">
27-
}
28-
@foreach (GriddlyButton button in rightButtons)
56+
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
57+
{
58+
@:<div class="btn-group">
59+
}
60+
foreach (GriddlyButton button in group)
2961
{
3062
button.AlignRight = true;
31-
32-
if (button.IsSeparator)
33-
{
34-
@:</div>
35-
@:<div class="btn-group">
36-
}
37-
else
38-
{
39-
@Html.Partial(GriddlySettings.ButtonTemplate, button);
40-
}
63+
@Html.Partial(GriddlySettings.ButtonTemplate, button);
64+
}
65+
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
66+
{
67+
@:</div>
4168
}
42-
@if (rightButtons.Count() > 1)
43-
{
44-
@:</div>
4569
}
4670
</div>
4771
}
48-
if (leftButtons.Any())
72+
if (leftGroups.Any())
4973
{
5074
<div class="btn-toolbar @ViewBag.ClassName">
51-
@if (leftButtons.Count() > 1)
75+
@foreach (var group in leftGroups)
5276
{
53-
@:<div class="btn-group">
54-
}
55-
@foreach (GriddlyButton button in leftButtons)
56-
{
57-
if (button.IsSeparator)
77+
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
5878
{
59-
@:</div>
6079
@:<div class="btn-group">
6180
}
62-
else
81+
foreach (GriddlyButton button in group)
6382
{
6483
@Html.Partial(GriddlySettings.ButtonTemplate, button);
6584
}
66-
}
67-
@if (leftButtons.Count() > 1)
68-
{
69-
@:</div>
85+
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
86+
{
87+
@:</div>
88+
}
7089
}
7190
</div>
7291
}

0 commit comments

Comments
 (0)