Skip to content

Commit abf901a

Browse files
committed
Cleaned up right and left button group rendering
1 parent e179583 commit abf901a

File tree

1 file changed

+52
-33
lines changed

1 file changed

+52
-33
lines changed

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)