Skip to content

Commit

Permalink
FritzAndFriends#163 not yet complete WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
grleachman committed Apr 17, 2020
1 parent 2829132 commit 6bcb6e7
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@
</Fixture>

@code {
void FirstTest()
{
var cut = GetComponentUnderTest();
var tableHeaders = cut.FindAll("th").ToList();
tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements");

try {
tableHeaders[0].TextContent.ShouldBe("Id");
} catch (Exception ex) {
Console.WriteLine("HTML rendered: " + cut.Markup);
throw;
}
void FirstTest()
{
var cut = GetComponentUnderTest();
System.Diagnostics.Debug.WriteLine(cut.Markup);
var tableHeaders = cut.FindAll("th").ToList();
tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements");

tableHeaders[1].TextContent.ShouldBe("Name");
tableHeaders[2].TextContent.ShouldBe("Price");
tableHeaders[3].TextContent.ShouldBe("LastUpdate");
try
{
tableHeaders[0].TextContent.ShouldBe("Id");
}

IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
catch (Exception ex)
{
totalRowCount = Widget.SimpleWidgetList.Length;
return Widget.SimpleWidgetList.AsQueryable();
Console.WriteLine("HTML rendered: " + cut.Markup);
throw;
}

tableHeaders[1].TextContent.ShouldBe("Name");
tableHeaders[2].TextContent.ShouldBe("Price");
tableHeaders[3].TextContent.ShouldBe("LastUpdate");
}

IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
{
totalRowCount = Widget.SimpleWidgetList.Length;
return Widget.SimpleWidgetList.AsQueryable();
}
}
30 changes: 15 additions & 15 deletions src/BlazorWebFormsComponents.Test/GridView/EmptyDataText.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

@code {

void FirstTest()
{
var cut = GetComponentUnderTest();
var tableHeaders = cut.FindAll("th").ToList();
tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements");
cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(1, "Did not render 1 TR elements");
cut.FindAll("td").Count().ShouldBe(1, "Did not render 0 TD elements");
cut.Find("td").TextContent.Replace("\t", string.Empty).Replace("\n", string.Empty).ShouldBe("TestText");
}
void FirstTest()
{
var cut = GetComponentUnderTest();
var tableHeaders = cut.FindAll("th").ToList();
tableHeaders.Count.ShouldBe(4, "Did not render 4 TH elements");
cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(1, "Did not render 1 TR elements");
cut.FindAll("td").Count().ShouldBe(1, "Did not render 0 TD elements");
cut.Find("td").TextContent.Replace("\t", string.Empty).Replace("\n", string.Empty).ShouldBe("TestText");
}

IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
{
totalRowCount = 0;
var widgetList = new List<Widget>();
return widgetList.AsQueryable();
}
IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
{
totalRowCount = 0;
var widgetList = new List<Widget>();
return widgetList.AsQueryable();
}
}
35 changes: 19 additions & 16 deletions src/BlazorWebFormsComponents.Test/GridView/TemplateFields.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@

@code {

void FirstTest()
{
var cut = GetComponentUnderTest();
var tableHeaders = cut.FindAll("th");
tableHeaders[0].TextContent.ShouldBe("Name");
tableHeaders[1].TextContent.ShouldBe("Price");
tableHeaders.Count.ShouldBe(2, "Did not render 2 TH elements");
cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(3, "Did not render 3 TR elements");
cut.FindAll("td").Count(e => e.InnerHtml.Contains("label")).ShouldBe(3, "Did not render 3 labels");
cut.FindAll("td").Count(e => e.InnerHtml.Contains("button")).ShouldBe(3, "Did not render 3 buttons");
}
void FirstTest()
{
var cut = GetComponentUnderTest();

IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
{
totalRowCount = Widget.SimpleWidgetList.Length;
return Widget.SimpleWidgetList.AsQueryable();
}
System.Diagnostics.Debug.WriteLine(cut.Markup);
var tableHeaders = cut.FindAll("th");
tableHeaders[0].TextContent.ShouldBe("Name");
tableHeaders[1].TextContent.ShouldBe("Price");
tableHeaders.Count.ShouldBe(2, "Did not render 2 TH elements");
cut.FindAll("tr").Count(e => e.InnerHtml.Contains("td")).ShouldBe(3, "Did not render 3 TR elements");
cut.FindAll("td").Count(e => e.InnerHtml.Contains("label")).ShouldBe(3, "Did not render 3 labels");
cut.FindAll("td").Count(e => e.InnerHtml.Contains("button")).ShouldBe(3, "Did not render 3 buttons");
}

IQueryable<Widget>
GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
{
totalRowCount = Widget.SimpleWidgetList.Length;
return Widget.SimpleWidgetList.AsQueryable();
}
}
16 changes: 1 addition & 15 deletions src/BlazorWebFormsComponents/BaseColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@

namespace BlazorWebFormsComponents
{
public abstract class BaseColumn : BaseWebFormsComponent, IColumn
public abstract class BaseColumn : BaseWebFormsComponent
{
///<inheritdoc/>
[CascadingParameter(Name = "ColumnCollection")]
public IColumnCollection ParentColumnsCollection { get; set; }

///<inheritdoc/>
[Parameter] public string HeaderText { get; set; }

public void Dispose()
{
ParentColumnsCollection.RemoveColumn(this);
}

///<inheritdoc/>
protected override void OnInitialized()
{
ParentColumnsCollection.AddColumn(this);
}
}
}
28 changes: 0 additions & 28 deletions src/BlazorWebFormsComponents/BaseRow.cs

This file was deleted.

58 changes: 21 additions & 37 deletions src/BlazorWebFormsComponents/GridView.razor
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
@typeparam ItemType
@inherits BaseModelBindingComponent<ItemType>
@using Interfaces
@if (ColumnList.Any())
{
<table class="@CssClass">
@inherits ListView<ItemType>
@typeparam ItemType
<ListView runat="server"
ItemType="ItemType"
Context="Item"
Items="@Items">
<ItemTemplate><tr></tr></ItemTemplate>
<LayoutTemplate Context="itemPlaceHolder">
<table class="table" id="gridview">
<thead>
<tr>
@foreach (IColumn column in ColumnList)
{
<th>@column.HeaderText</th>
}
</tr>
</thead>
<tbody>
@if (Items != null && Items.Any())
@foreach (var h in HeaderRow())
{
@foreach (ItemType item in Items)
{
<CascadingValue Value="this" Name="RowCollection">
<GridViewRow DataItem="item" Columns="ColumnList" />
</CascadingValue>
}
}
else
{
<tr>
<td colspan=@ColumnList.Count>
@EmptyDataText
</td>
</tr>
}
</tbody>
</table>
}

<CascadingValue Value="this" Name="ColumnCollection">
@Columns
</CascadingValue>
<th>@h</th>
}
</thead>
<tbody>
@itemPlaceHolder
</tbody>
</table>
</LayoutTemplate>
</ListView>
@code{
}
67 changes: 16 additions & 51 deletions src/BlazorWebFormsComponents/GridView.razor.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
using BlazorWebFormsComponents.Interfaces;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Linq;

namespace BlazorWebFormsComponents
{
/// <summary>
/// Blazor version of WebForms GridView control
/// </summary>
/// <typeparam name="ItemType"></typeparam>
public partial class GridView<ItemType> : BaseModelBindingComponent<ItemType>, IRowCollection, IColumnCollection
{
public partial class GridView<ItemType> : ListView<ItemType>
{

/// <summary>
/// Specify if the GridView component will autogenerate its columns
/// </summary>
[Parameter] public bool AutogenerateColumns { get; set; } = true;

[Parameter] public RenderFragment Columns { get; set; }

public List<BoundField> BoundFields { get; set; } = new List<BoundField>();

public IEnumerable<string> HeaderRow()
{
foreach (var x in BoundFields)
{
yield return x.HeaderText;
}
}

/// <summary>
/// Text to show when there are no items to show
/// </summary>
Expand All @@ -32,26 +44,8 @@ public partial class GridView<ItemType> : BaseModelBindingComponent<ItemType>, I
[Parameter] public string CssClass { get; set; }

///<inheritdoc/>
public List<IColumn> ColumnList { get; set; } = new List<IColumn>();

/// <summary>
/// The Rows of the GridView
/// </summary>
public List<IRow> Rows { get => RowList; set => RowList = value; }

///<inheritdoc/>
public List<IRow> RowList { get; set; } = new List<IRow>();

#region Templates
/// <summary>
/// The columns template of the GridView
/// </summary>
[Parameter] public RenderFragment Columns { get; set; }

/// <summary>
/// The ChildContent of the GridView
/// </summary>
[Parameter] public RenderFragment ChildContent { get; set; }
#endregion
protected override void OnInitialized()
{
Expand All @@ -61,34 +55,5 @@ protected override void OnInitialized()
GridViewColumnGenerator.GenerateColumns(this);
}
}

///<inheritdoc/>
public void AddColumn(IColumn column)
{
ColumnList.Add(column);
StateHasChanged();
}

///<inheritdoc/>
public void RemoveColumn(IColumn column)
{
ColumnList.Remove(column);
StateHasChanged();
}

///<inheritdoc/>
public void RemoveRow(IRow row)
{
Rows.Remove(row);
StateHasChanged();
}

///<inheritdoc/>
public void AddRow(IRow row)
{
Rows.Add(row);
StateHasChanged();
}

}
}
13 changes: 7 additions & 6 deletions src/BlazorWebFormsComponents/GridViewColumnGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace BlazorWebFormsComponents
/// <summary>
/// The GridView Column Generator
/// </summary>
public static class GridViewColumnGenerator
{
public static class GridViewColumnGenerator
{
/// <summary>
/// Generate columns for a given GridView based on the properties of given Type
/// </summary>
Expand All @@ -19,12 +19,13 @@ public static void GenerateColumns<ItemType>(GridView<ItemType> gridView)
var propertiesInfo = type.GetProperties(BindingFlags.Instance | BindingFlags.Public).OrderBy(x => x.MetadataToken);
foreach (var propertyInfo in propertiesInfo)
{
var newColumn = new BoundField {
var newColumn = new BoundField
{
DataField = propertyInfo.Name,
ParentColumnsCollection = gridView,
HeaderText = propertyInfo.Name
HeaderText = propertyInfo.Name,
};
gridView.ColumnList.Add(newColumn);
gridView.BoundFields.Add(newColumn);

}
}
}
Expand Down
Loading

0 comments on commit 6bcb6e7

Please sign in to comment.