Skip to content

Version 1.0.82 #24

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
Dec 19, 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
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
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.81.0")]
[assembly: AssemblyFileVersion("1.0.81.0")]
[assembly: AssemblyVersion("1.0.82.0")]
[assembly: AssemblyFileVersion("1.0.82.0")]
11 changes: 11 additions & 0 deletions Griddly.Mvc/GriddlyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public static object GetGriddlyDefault(this WebViewPage page, string field)
return page.ViewData["_griddlyDefault_" + field];
}

public static Dictionary<string, object> GetGriddlyDefaults(this WebViewPage page)
{
Dictionary<string, object> defaults = new Dictionary<string, object>();
foreach (var key in page.ViewData.Keys.Where(k => k.StartsWith("_griddlyDefault_")))
{
defaults[key.Substring("_griddlyDefault_".Length)] = page.ViewData[key];
}

return defaults;
}

static IDictionary<string, object> ObjectToDictionary(object value)
{
if (value == null)
Expand Down
70 changes: 58 additions & 12 deletions Griddly/Scripts/griddly.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
var rowClickModal = this.$element.data("griddly-rowclickmodal");
var filterMode = this.$element.data("griddly-filtermode");
var allowedFilterModes = this.$element.data("griddly-allowedfiltermodes");
var filterDefaults = this.$element.data("griddly-filter-defaults");

this.options.url = url;
this.options.defaultRowIds = defaultRowIds;
Expand All @@ -103,7 +104,7 @@
this.options.pageSize = parseInt(pageSize);
this.options.pageCount = this.options.count * this.options.pageSize;
this.options.rowClickModal = rowClickModal;

if (!this.options.selectedRows) {
this.options.selectedRows = {};
}
Expand All @@ -118,6 +119,7 @@

this.options.filterMode = filterMode;
this.options.allowedFilterModes = allowedFilterModes != null ? allowedFilterModes : null;
this.options.filterDefaults = filterDefaults;

// TODO: should we do this later on so we handle dynamically added buttons?
this.$element.find("[data-append-rowids-to-url]").each(function ()
Expand Down Expand Up @@ -693,17 +695,36 @@
}
},

toggleFilterMode: function()
getFilterMode: function()
{
if (this.options.allowedFilterModes.length > 1)
return this.options.filterMode;
},

setFilterMode: function(mode)
{
if (this.options.allowedFilterModes.indexOf(mode) > -1)
{
this.options.filterMode = this.options.filterMode == "Inline" ? "Form" : "Inline";
this.options.filterMode = mode;

var request1 = this.buildRequest();

this.$element.find("tr.griddly-filters:not(tr.griddly-filters-" + this.options.filterMode.toLowerCase() + ")").hide();
this.$element.find("tr.griddly-filters-" + this.options.filterMode.toLowerCase()).show();

// TODO: only refresh if filter values changed
this.refresh(true);
var request2 = this.buildRequest();

if (JSON.stringify(request1) !== JSON.stringify(request2))
{
this.refresh(true);
}
}
},

toggleFilterMode: function()
{
if (this.options.allowedFilterModes.length > 1)
{
this.setFilterMode(this.options.filterMode == "Inline" ? "Form" : "Inline");
}
},

Expand All @@ -719,6 +740,29 @@
return serializeObject(allFilters);
},

setFilterValue: function(field, value)
{
var input = $(field);

if (value)
{
var datatype = input.data("griddly-filter-data-type");

switch (datatype)
{
case "Date":
var date = new Date(value);
value = date.toLocaleDateString();
break;
case "Currency":
value = value.toFixed(2);
break;
}
}

input.val(value).change();
},

setFilterValues: function(filters, isPatch)
{
this.options.autoRefreshOnFilter = false;
Expand All @@ -727,15 +771,17 @@
{
var allFilters = $(".griddly-filters input, .griddly-filters select", this.$element).add(this.$inlineFilters);

allFilters.each(function ()
allFilters.each($.proxy(function (i, e)
{
$(this).val(filters[this.name]).change();
});
this.setFilterValue(e, filters[e.name]);
}, this));
}
else
{
for (var key in filters)
$("[name='" + key + "']").val(filters[key]).change();
{
this.setFilterValue("[name='" + key + "']", filters[key]);
}
}

this.options.autoRefreshOnFilter = true;
Expand All @@ -744,11 +790,11 @@

resetFilterValues: function ()
{
// TODO: get defaults?

this.$element.find("form .transient").remove();
this.$element.find("form")[0].reset();

this.setFilterValues(this.options.filterDefaults);

this.$element.trigger("resetfilters.griddly", this.$element);

this.refresh(true);
Expand Down
17 changes: 9 additions & 8 deletions Griddly/Views/Shared/Griddly/Griddly.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@
SortField[] defaultSort = settings.DefaultSort;

@:<div class="griddly @settings.ClassName" data-role="griddly"
@: @Html.AttributeNullable("data-griddly-url", !simple ? Url.Current() : null)
@: data-griddly-count="@Model.Total"
@: @Html.AttributeNullable("data-griddly-filtermode", settings.InitialFilterMode != FilterMode.None ? settings.InitialFilterMode.ToString() : null)
@: @Html.AttributeNullable("data-griddly-allowedfiltermodes", settings.AllowedFilterModes != FilterMode.None ? Json.Encode(Enum.GetValues(typeof(FilterMode)).Cast<FilterMode>().Where(x => settings.AllowedFilterModes.Value.HasFlag(x) && x != FilterMode.Both && x != FilterMode.None).Select(x => x.ToString())) : null)
@: data-griddly-pagesize="@(settings.PageSize ?? Model.PageSize)"
@: @Html.AttributeNullable("data-griddly-rowclickmodal", settings.RowClickModal)
@: data-griddly-defaultrowids="@Json.Encode(settings.DefaultRowIds != null ? settings.DefaultRowIds.Select(x => x.ToLower()).ToArray() : new[] { "value" })"
@: @Html.AttributeIf("data-griddly-defaultsort", defaultSort != null && defaultSort.Any(), Html.AttributeEncode(Json.Encode(defaultSort.Select(x => new { Field = x.Field, Direction = x.Direction.ToString() }))))>
@: @Html.AttributeNullable("data-griddly-url", !simple ? Url.Current() : null)
@: data-griddly-count="@Model.Total"
@: @Html.AttributeNullable("data-griddly-filtermode", settings.InitialFilterMode != FilterMode.None ? settings.InitialFilterMode.ToString() : null)
@: @Html.AttributeNullable("data-griddly-allowedfiltermodes", settings.AllowedFilterModes != FilterMode.None ? Json.Encode(Enum.GetValues(typeof(FilterMode)).Cast<FilterMode>().Where(x => settings.AllowedFilterModes.Value.HasFlag(x) && x != FilterMode.Both && x != FilterMode.None).Select(x => x.ToString())) : null)
@: data-griddly-pagesize="@(settings.PageSize ?? Model.PageSize)"
@: @Html.AttributeNullable("data-griddly-rowclickmodal", settings.RowClickModal)
@: data-griddly-defaultrowids="@Json.Encode(settings.DefaultRowIds != null ? settings.DefaultRowIds.Select(x => x.ToLower()).ToArray() : new[] { "value" })"
@: data-griddly-filter-defaults="@Newtonsoft.Json.JsonConvert.SerializeObject(this.GetGriddlyDefaults())"
@: @Html.AttributeIf("data-griddly-defaultsort", defaultSort != null && defaultSort.Any(), Html.AttributeEncode(Json.Encode(defaultSort.Select(x => new { Field = x.Field, Direction = x.Direction.ToString() }))))>
if (settings.Buttons.Any())
{
<div class="buttons">
Expand Down
14 changes: 9 additions & 5 deletions Griddly/Views/Shared/Griddly/GriddlyFilterForm.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*@

@model GriddlySettings

@foreach (GriddlyFilter filter in Model.Filters)
{
GriddlyFilterBox filterBox = filter as GriddlyFilterBox;
Expand All @@ -37,7 +37,8 @@
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
}
<input class="form-control" id="[email protected]" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)" />
<input class="form-control" id="[email protected]" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)"
data-griddly-filter-data-type="@filter.DataType" />
@if (filter.DataType == FilterDataType.Currency || filter.DataType == FilterDataType.Date)
{
@*@if (filter.DataType == FilterDataType.Percent)
Expand All @@ -63,7 +64,8 @@
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
}
<input class="form-control" id="[email protected]" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)" />
<input class="form-control" id="[email protected]" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)"
data-griddly-filter-data-type="@filter.DataType" />
@if (filter.DataType == FilterDataType.Currency || filter.DataType == FilterDataType.Date)
{
@*@if (filter.DataType == FilterDataType.Percent)
Expand All @@ -87,7 +89,8 @@
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
}
<input class="form-control" id="griddly-filter-@(filter.Field)-to" name="@filterRange.FieldEnd" type="text" value="@filter.GetEditValue(defaultValueEnd)" />
<input class="form-control" id="griddly-filter-@(filter.Field)-to" name="@filterRange.FieldEnd" type="text" value="@filter.GetEditValue(defaultValueEnd)"
data-griddly-filter-data-type="@filter.DataType" />
@if (filter.DataType == FilterDataType.Currency || filter.DataType == FilterDataType.Date)
{
@*@if (filter.DataType == FilterDataType.Percent)
Expand All @@ -103,7 +106,8 @@
filterList.SetSelectedItems(defaultValue);

<div class="col-sm-3">
<select class="form-control col-sm-3" id="[email protected]" name="@filter.Field" @(filterList.IsMultiple ? "multiple" : null)>
<select class="form-control col-sm-3" id="[email protected]" name="@filter.Field" @(filterList.IsMultiple ? "multiple" : null)
data-griddly-filter-data-type="@filter.DataType">
@foreach (SelectListItem item in filterList.Items)
{
<option value="@item.Value" @(item.Selected ? "selected" : null)>@item.Text</option>
Expand Down
9 changes: 6 additions & 3 deletions Griddly/Views/Shared/Griddly/GriddlyFilterInline.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
{
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
<input class="form-control" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)" />
<input class="form-control" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)"
data-griddly-filter-data-type="@filter.DataType" />
@*@if (filter.DataType == FilterDataType.Percent)
{
<span class="input-group-addon">%</span>
Expand All @@ -132,7 +133,8 @@
{
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
<input class="form-control" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)" />
<input class="form-control" name="@filter.Field" type="text" value="@filter.GetEditValue(defaultValue)"
data-griddly-filter-data-type="@filter.DataType" />
@*@if (filter.DataType == FilterDataType.Percent)
{
<span class="input-group-addon">%</span>
Expand All @@ -151,7 +153,8 @@
{
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
}
<input class="form-control" name="@filterRange.FieldEnd" type="text" value="@filter.GetEditValue(defaultValueEnd)" />
<input class="form-control" name="@filterRange.FieldEnd" type="text" value="@filter.GetEditValue(defaultValueEnd)"
data-griddly-filter-data-type="@filter.DataType" />
@*@if (filter.DataType == FilterDataType.Percent)
{
<span class="input-group-addon">%</span>
Expand Down