Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
Updated Sample to Blazor WebAssembly 3.2.0 Preview 2
Added RowClickAction (thanks @bowser4848)
Added SelectionType and SelectedItems
  • Loading branch information
IvanJosipovic authored Mar 13, 2020
2 parents 7102ac1 + b62fbb4 commit 7a21f58
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
run: ./dotnet-sonarscanner begin /o:ivanjosipovic /k:IvanJosipovic_BlazorTable /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=${{ secrets.SONARQUBE_TOKEN }}

- name: Dotnet Build
run: dotnet build --configuration Release
run: dotnet build -c Release

- name: Dotnet Publish
working-directory: src/BlazorTable.Sample.Wasm
run: dotnet publish --configuration Release
run: dotnet publish -c Release

- name: SonarQube End
run: ./dotnet-sonarscanner end /d:sonar.login=${{ secrets.SONARQUBE_TOKEN }}
Expand All @@ -42,7 +42,7 @@ jobs:
id: netlify
uses: ivanjosipovic/actions/cli@master
with:
args: deploy --json -d src/BlazorTable.Sample.Wasm/bin/Release/netstandard2.1/publish/BlazorTable.Sample.Wasm/dist/
args: deploy --json -d src/BlazorTable.Sample.Wasm/bin/Release/netstandard2.1/publish/wwwroot
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ jobs:
working-directory: src/BlazorTable
run: dotnet pack -c Release -p:Version=${{ steps.version.outputs.new_tag }}

- name: Dotnet Nuget Push
- name: Dotnet Nuget Push
if: "!contains(github.event.head_commit.message, '#skip')"
working-directory: src/BlazorTable/bin/Release
run: dotnet nuget push BlazorTable.*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
continue-on-error: true

- name: Dotnet Publish
working-directory: src/BlazorTable.Sample.Wasm
run: dotnet publish --configuration Release
run: dotnet publish -c Release

- name: Deploy to Production
uses: netlify/actions/cli@master
with:
args: deploy --prod --json -d src/BlazorTable.Sample.Wasm/bin/Release/netstandard2.1/publish/BlazorTable.Sample.Wasm/dist/
args: deploy --prod --json -d src/BlazorTable.Sample.Wasm/bin/Release/netstandard2.1/publish/wwwroot
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}

- name: Create Release
if: "!contains(github.event.head_commit.message, '#skip')"
uses: actions/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorTable.Sample.Shared\BlazorTable.Sample.Shared.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"BlazorTable.Sample.Server": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "/CustomSelect",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable.Sample.Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/Row" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Row
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="/EditMode" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Edit Mode
Expand Down
80 changes: 80 additions & 0 deletions src/BlazorTable.Sample.Shared/Pages/Row.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@page "/Row"

@using BlazorTable

<h1>Row</h1>

Selection Type:
<select class="form-control form-control-sm" @onchange="@((x) => selectionType = (SelectionType)Enum.Parse(typeof(SelectionType), x.Value.ToString()))">
@foreach (var option in Enum.GetValues(typeof(SelectionType)))
{
<option value="@option">@option</option>
}
</select>

Last Clicked: @selected?.full_name
<br />
Selected: @(selectedItems.Any() ? selectedItems.Select(x => x.full_name).Aggregate((c, n) => $"{c},{n}") : "None")

<Table TableItem="PersonData" Items="data" PageSize="15" SelectionType="selectionType" RowClickAction="RowClick" SelectedItems="selectedItems">
<Column TableItem="PersonData" Title="Id" Field="@(x => x.id)" Sortable="true" Filterable="true" Width="10%" DefaultSortColumn="true" />
<Column TableItem="PersonData" Title="Full Name" Field="@(x => x.full_name)" Sortable="true" Filterable="true" Width="20%" />
<Column TableItem="PersonData" Title="Email" Field="@(x => x.email)" Sortable="true" Filterable="true" Width="20%">
<Template>
<a href="mailto:@context.email">@context.email</a>
</Template>
</Column>
<Column TableItem="PersonData" Title="Paid" Field="@(x => x.paid)" Sortable="true" Filterable="true" Width="10%" />
<Column TableItem="PersonData" Title="Price" Field="@(x => x.price)" Sortable="true" Filterable="true" Width="10%" Format="C" Align="Align.Right" />
<Column TableItem="PersonData" Title="Created Date" Field="@(x => x.created_date)" Sortable="true" Filterable="true" Width="10%">
<Template>
@(context.created_date.HasValue ? context.created_date.Value.ToShortDateString() : string.Empty)
</Template>
</Column>
<Column TableItem="PersonData" Title="Enum" Field="@(x => x.cc_type)" Sortable="true" Filterable="true" Width="10%" />
<Pager ShowPageNumber="true" ShowTotalCount="true" />
</Table>

@code
{
[Inject]
private HttpClient Http { get; set; }

private PersonData[] data;

private SelectionType selectionType;

private PersonData selected;

private List<PersonData> selectedItems = new List<PersonData>();

protected override async Task OnInitializedAsync()
{
data = await Http.GetJsonAsync<PersonData[]>("sample-data/MOCK_DATA.json");
}

public class PersonData
{
public int? id { get; set; }
public string full_name { get; set; }
public string email { get; set; }
public bool? paid { get; set; }
public decimal? price { get; set; }
public CreditCard? cc_type { get; set; }
public DateTime? created_date { get; set; }
}

public enum CreditCard
{
none = 0,
[Description("MasterCard")]
MasterCard = 1,
Visa = 2
}

public void RowClick(PersonData data)
{
selected = data;
StateHasChanged();
}
}
9 changes: 4 additions & 5 deletions src/BlazorTable.Sample.Wasm/BlazorTable.Sample.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<BlazorLinkOnBuild Condition="'$(Configuration)'=='Debug'">false</BlazorLinkOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.2.0-preview1.20073.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview1.20073.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview2.20160.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview2.20160.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview2.20160.5" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/BlazorTable.Sample.Wasm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BlazorTable.Sample.Shared;
using Microsoft.AspNetCore.Blazor.Hosting;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace BlazorTable.Sample.Wasm
{
Expand All @@ -11,6 +12,8 @@ public static async Task Main(string[] args)
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");

builder.Services.AddBaseAddressHttpClient();

await builder.Build().RunAsync();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable.Sample.Wasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:51075/"
"applicationUrl": "http://localhost:51076/"
}
}
}
9 changes: 9 additions & 0 deletions src/BlazorTable/Components/SelectionType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BlazorTable
{
public enum SelectionType
{
None,
Single,
Multiple
}
}
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

foreach (TableItem item in FilteredItems)
{
<tr @key="item" class="@RowClass(item)">
<tr @key="item" class="@RowClass(item) @(SelectedItems.Contains(item) ? "table-active" : "")" @onclick="(() => OnRowClickHandler(item))">

@{int locali = i;}
@if (_detailTemplate != null)
Expand Down
66 changes: 66 additions & 0 deletions src/BlazorTable/Components/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,71 @@ public void SetDetailTemplate(DetailTemplate<TableItem> detailTemplate)

private RenderFragment<TableItem> _detailTemplate;

private SelectionType _selectionType;

/// <summary>
/// Select Type: None, Single or Multiple
/// </summary>
[Parameter]
public SelectionType SelectionType
{
get { return _selectionType; }
set
{
_selectionType = value;
if (_selectionType == SelectionType.None)
{
SelectedItems.Clear();
} else if (_selectionType == SelectionType.Single && SelectedItems.Count > 1)
{
SelectedItems.RemoveRange(1, SelectedItems.Count - 1);
}
StateHasChanged();
}
}

/// <summary>
/// Contains Selected Items
/// </summary>
[Parameter]
public List<TableItem> SelectedItems { get; set; } = new List<TableItem>();

/// <summary>
/// Action performed when the row is clicked.
/// </summary>
[Parameter]
public Action<TableItem> RowClickAction { get; set; }

/// <summary>
/// Handles the onclick action for table rows.
/// This allows the RowClickAction to be optional.
/// </summary>
private void OnRowClickHandler(TableItem tableItem)
{
try
{
RowClickAction?.Invoke(tableItem);
}
catch (Exception ex)
{
Logger.LogError(ex, "RowClickAction threw an exception: {0}", ex);
}

switch (SelectionType)
{
case SelectionType.None:
return;
case SelectionType.Single:
SelectedItems.Clear();
SelectedItems.Add(tableItem);
break;
case SelectionType.Multiple:
if (SelectedItems.Contains(tableItem))
SelectedItems.Remove(tableItem);
else
SelectedItems.Add(tableItem);
break;
}
}
}
}
5 changes: 5 additions & 0 deletions src/BlazorTable/Interfaces/ITable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,10 @@ public interface ITable
/// </summary>
/// <param name="template"></param>
void SetLoadingDataTemplate(LoadingDataTemplate template);

/// <summary>
/// Select Type: None, Single or Multiple
/// </summary>
public SelectionType SelectionType { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/BlazorTable/Interfaces/ITableGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public interface ITable<TableItem> : ITable
/// </summary>
IEnumerable<TableItem> FilteredItems { get; }

/// <summary>
/// Action performed when the row is clicked
/// </summary>
Action<TableItem> RowClickAction { get; set; }

/// <summary>
/// Collection of selected items
/// </summary>
List<TableItem> SelectedItems { get; }

/// <summary>
/// Set the SetDetailTemplate for the table
/// </summary>
Expand Down

0 comments on commit 7a21f58

Please sign in to comment.