Skip to content

Added new features up to 1.0.74 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.73.1")]
[assembly: AssemblyFileVersion("1.0.73.1")]
[assembly: AssemblyVersion("1.0.74.0")]
[assembly: AssemblyFileVersion("1.0.74.0")]
27 changes: 17 additions & 10 deletions Griddly.Mvc/GriddlyButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ namespace Griddly.Mvc
{
public class GriddlyButton
{
public GriddlyButton(string additionalClassName = null)
{
Buttons = new List<GriddlyButton>();

Enabled = true;
Action = GriddlyButtonAction.Navigate;

ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
}

public string Argument { get; set; }
public Func<object, object> ArgumentTemplate { get; set; }

Expand All @@ -20,26 +30,23 @@ public class GriddlyButton
public string Target { get; set; }
public string ConfirmMessage { get; set; }
public bool AlignRight { get; set; }

/// <summary>
/// The row ids to include in the button action (default uses grid default)
/// </summary>
public string[] RowIds { get; set; }

/// <summary>
/// Append the selected row ids to the button href as comma separated query strings (only navigate and modal types supported)
/// </summary>
public bool AppendRowIdsToUrl { get; set; }

public IDictionary<string, object> HtmlAttributes { get; set; }

public GriddlyButtonAction Action { get; set; }

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

public GriddlyButton(string additionalClassName = null)
{
Buttons = new List<GriddlyButton>();

Enabled = true;
Action = GriddlyButtonAction.Navigate;

ClassName = ((GriddlySettings.DefaultButtonClassName ?? "") + " " + (additionalClassName ?? "")).Trim();
}

public GriddlyButton Add(GriddlyButton item)
{
Buttons.Add(item);
Expand Down
21 changes: 16 additions & 5 deletions Griddly.Mvc/GriddlySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public GriddlySettings Add(GriddlyButton button)
});
}*/

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)
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)
{
if (enableOnSelection == null)
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
Expand All @@ -163,10 +163,13 @@ public GriddlySettings Button(Func<object, object> argumentTemplate, string capt
RowIds = rowIds
};

if (htmlAttributes != null)
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

return Add(button);
}

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)
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)
{
if (enableOnSelection == null)
enableOnSelection = (action == GriddlyButtonAction.Ajax || action == GriddlyButtonAction.AjaxBulk || action == GriddlyButtonAction.Post);
Expand All @@ -182,6 +185,9 @@ public GriddlySettings Button(string argument, string caption, string icon = nul
RowIds = rowIds
};

if (htmlAttributes != null)
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

return Add(button);
}

Expand Down Expand Up @@ -409,16 +415,21 @@ public GriddlySettings<TRow> SelectColumn(Dictionary<string, Func<TRow, object>>
return this;
}

public GriddlySettings<TRow> Button<TModel>(Func<TModel, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, string[] rowIds = null)
public GriddlySettings<TRow> Button<TModel>(Func<TModel, object> argumentTemplate, string caption, string icon = null, GriddlyButtonAction action = GriddlyButtonAction.Navigate, string[] rowIds = null, object htmlAttributes = null)
{
Add(new GriddlyButton()
var button = new GriddlyButton()
{
ArgumentTemplate = (x) => argumentTemplate((TModel)x),
Text = caption,
Icon = icon,
Action = action,
RowIds = rowIds
});
};

if (htmlAttributes != null)
button.HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

Add(button);

return this;
}
Expand Down
27 changes: 26 additions & 1 deletion Griddly/Views/Home/TestGrid.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,33 @@
.Column(x => x.City, "City")
.Column(x => x.State, "State")
.Column(x => x.PostalCode, "Zip", template: x => Html.ActionLink("&" + x.PostalCode, "Profile"))

.Button("", "export", action: GriddlyButtonAction.Javascript, className: "export-xlsx")
.Add(new GriddlyButton() { Text = "Confirm", Argument = "http://google.com", Action = GriddlyButtonAction.PostCriteria, ConfirmMessage = "Please confirm" })
.Button("AlertSelectedIds", "Alert Selected", action: GriddlyButtonAction.Javascript, enableOnSelection: true)
.Add(new GriddlyButton() { IsSeparator = true })
.Add(new GriddlyButton() { IsSeparator = true })
.Button("AlertSelectedIds", "Alert Selected", action: GriddlyButtonAction.Javascript, enableOnSelection: true, htmlAttributes: new { data_test = "hello world" })
.Add(new GriddlyButton() { IsSeparator = true })
.Button("TestPost", "Post Selected", action: GriddlyButtonAction.AjaxBulk, enableOnSelection: true)
.Add(new GriddlyButton()
{
Text = "A dropdown in a group",
Buttons = new List<GriddlyButton>()
{
new GriddlyButton() { Text = "1" },
new GriddlyButton() { Text = "2" },
new GriddlyButton() { Text = "3" }
}
})
.Add(new GriddlyButton() { IsSeparator = true })
.Add(new GriddlyButton()
{
Text = "A dropdown alone",
Buttons = new List<GriddlyButton>()
{
new GriddlyButton() { Text = "1" },
new GriddlyButton() { Text = "2" },
new GriddlyButton() { Text = "3" }
}
})
)
35 changes: 21 additions & 14 deletions Griddly/Views/Shared/Griddly/BootstrapButton.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else
@RenderLink(Model, true, false)
@if (Model.IsSplitDropdown)
{
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<button type="button" class="btn btn-default dropdown-toggle @GriddlySettings.DefaultButtonClassName" data-toggle="dropdown">
<span class="caret"></span>
</button>
}
Expand Down Expand Up @@ -67,19 +67,26 @@ else
}

<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)"
@*onclick="@(button.Action == GriddlyButtonAction.Javascript ? button.Argument : null)"*@
title="@button.Title"
@Html.AttributeIf("target", button.Action == GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
@Html.AttributeIf("href", href != null, href)
@Html.AttributeIf("data-toggle", button.Action != GriddlyButtonAction.Navigate && button.Action != GriddlyButtonAction.Javascript, button.Action.ToString().ToLower())
@Html.AttributeIf("data-toggle", isDropdown && !button.IsSplitDropdown, "dropdown")
@Html.AttributeIf("data-onclick", button.Action == GriddlyButtonAction.Javascript && button.Argument != null, button.Argument)
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")>
@*onclick="@(button.Action == GriddlyButtonAction.Javascript ? button.Argument : null)"*@
title="@button.Title"
@Html.AttributeIf("target", button.Action == GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
@Html.AttributeIf("href", href != null, href)
@Html.AttributeIf("data-toggle", button.Action != GriddlyButtonAction.Navigate && button.Action != GriddlyButtonAction.Javascript, button.Action.ToString().ToLower())
@Html.AttributeIf("data-toggle", isDropdown && !button.IsSplitDropdown, "dropdown")
@Html.AttributeIf("data-onclick", button.Action == GriddlyButtonAction.Javascript && button.Argument != null, button.Argument)
@Html.AttributeIf("data-url", button.Action == GriddlyButtonAction.Ajax || button.Action == GriddlyButtonAction.AjaxBulk || button.Action == GriddlyButtonAction.Post || button.Action == GriddlyButtonAction.PostCriteria, button.Argument)
@Html.AttributeIf("data-target", button.Action != GriddlyButtonAction.Navigate && !string.IsNullOrWhiteSpace(button.Target), button.Target)
@Html.AttributeIf("data-enable-on-selection", button.EnableOnSelection, button.EnableOnSelection.ToString().ToLower())
@Html.AttributeIf("data-confirm-message", button.ConfirmMessage != null, button.ConfirmMessage)
@Html.AttributeIf("data-rowids", button.RowIds != null, button.RowIds != null ? Html.AttributeEncode(Json.Encode(button.RowIds.Select(x => x.ToLower()).ToArray())) : null)
@Html.AttributeIf("data-append-rowids-to-url", (button.Action == GriddlyButtonAction.Modal || button.Action == GriddlyButtonAction.Navigate) && button.AppendRowIdsToUrl, "")
@if (button.HtmlAttributes != null)
{
foreach (var attr in button.HtmlAttributes)
{
<text>@attr.Key="@attr.Value"</text>
}
}>

@if (!string.IsNullOrWhiteSpace(Model.Icon) && GriddlySettings.IconTemplate != null)
{
Expand Down
85 changes: 52 additions & 33 deletions Griddly/Views/Shared/Griddly/ButtonStrip.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,81 @@

@model IList<GriddlyButton>

@functions{
IEnumerable<IEnumerable<GriddlyButton>> GetGroups(IEnumerable<GriddlyButton> buttons)
{
List<IEnumerable<GriddlyButton>> groups = new List<IEnumerable<GriddlyButton>>();

List<GriddlyButton> currentList = null;
foreach (var b in buttons)
{
if (currentList == null)
{
currentList = new List<GriddlyButton>();
groups.Add(currentList);
}

if (b.IsSeparator)
{
currentList = null;
}
else
{
currentList.Add(b);
}
}

groups.RemoveAll(x => x.Count() == 0);

return groups;
}
}

@{
var leftButtons = Model.Where(x => !x.AlignRight && ViewBag.AlignRight != true);
var rightButtons = Model.Where(x => x.AlignRight || ViewBag.AlignRight == true);
var leftGroups = GetGroups(Model.Where(x => !x.AlignRight && ViewBag.AlignRight != true));
var rightGroups = GetGroups(Model.Where(x => x.AlignRight || ViewBag.AlignRight == true));
}

@if (Model.Any())
{
if (rightButtons.Any())
if (rightGroups.Any())
{
<div class="btn-toolbar @ViewBag.ClassName pull-right">
@if (rightButtons.Count() > 1)
@foreach (var group in rightGroups)
{
@:<div class="btn-group">
}
@foreach (GriddlyButton button in rightButtons)
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
{
@:<div class="btn-group">
}
foreach (GriddlyButton button in group)
{
button.AlignRight = true;

if (button.IsSeparator)
{
@:</div>
@:<div class="btn-group">
}
else
{
@Html.Partial(GriddlySettings.ButtonTemplate, button);
}
@Html.Partial(GriddlySettings.ButtonTemplate, button);
}
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
{
@:</div>
}
@if (rightButtons.Count() > 1)
{
@:</div>
}
</div>
}
if (leftButtons.Any())
if (leftGroups.Any())
{
<div class="btn-toolbar @ViewBag.ClassName">
@if (leftButtons.Count() > 1)
@foreach (var group in leftGroups)
{
@:<div class="btn-group">
}
@foreach (GriddlyButton button in leftButtons)
{
if (button.IsSeparator)
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
{
@:</div>
@:<div class="btn-group">
}
else
foreach (GriddlyButton button in group)
{
@Html.Partial(GriddlySettings.ButtonTemplate, button);
}
}
@if (leftButtons.Count() > 1)
{
@:</div>
if (group.Count() > 1 || group.First().Buttons.Count() == 0)
{
@:</div>
}
}
</div>
}
Expand Down