Skip to content

Commit

Permalink
#218 - Integrate loading in Categories and Currencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Mar 8, 2019
1 parent 0353dc9 commit 0727706
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 61 deletions.
52 changes: 27 additions & 25 deletions src/Money.UI.Blazor/Pages/Categories.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,37 @@
<CategoryName bind-IsVisible="@IsCreateVisible" />
<Confirm Context="@Delete" />

@if (Models.Count == 0)
{
<Alert Title="No data." Message="Try adding some categories." Mode="@AlertMode.Warning" />
}
else
{
@foreach (var item in Models)
<Loading Context="@Loading">
@if (Models.Count == 0)
{
<div class="alert" style="background-color: @item.Color.ToHashCode()">
@if (item.Icon != null)
{
<span>@item.Icon</span>
}
<strong>
@item.Name
</strong>
<span class="gray">
@item.Description
</span>
<Alert Title="No data." Message="Try adding some categories." Mode="@AlertMode.Warning" />
}
else
{
@foreach (var item in Models)
{
<div class="alert" style="background-color: @item.Color.ToHashCode()">
@if (item.Icon != null)
{
<span>@item.Icon</span>
}
<strong>
@item.Name
</strong>
<span class="gray">
@item.Description
</span>

<div class="nav navbar-nav navbar-right">
<IconButton Icon="pencil" ToolTip="Rename" Click="@(() => OnActionClick(item, ref IsNameEditVisible))" />
<IconButton Icon="picture" ToolTip="Icon" Click="@(() => OnActionClick(item, ref IsIconEditVisible))" />
<IconButton Icon="tint" ToolTip="Color" Click="@(() => OnActionClick(item, ref IsColorEditVisible))" />
<IconButton Icon="remove" ToolTip="Delete" Click="@(() => OnDeleteClick(item))" />
<div class="nav navbar-nav navbar-right">
<IconButton Icon="pencil" ToolTip="Rename" Click="@(() => OnActionClick(item, ref IsNameEditVisible))" />
<IconButton Icon="picture" ToolTip="Icon" Click="@(() => OnActionClick(item, ref IsIconEditVisible))" />
<IconButton Icon="tint" ToolTip="Color" Click="@(() => OnActionClick(item, ref IsColorEditVisible))" />
<IconButton Icon="remove" ToolTip="Delete" Click="@(() => OnDeleteClick(item))" />
</div>
</div>
</div>
}
}
}
</Loading>

<CategoryName CategoryKey="@Selected?.Key" Name="@Selected?.Name" Description="@Selected?.Description" bind-IsVisible="@IsNameEditVisible" />
<CategoryIcon CategoryKey="@Selected?.Key" Icon="@Selected?.Icon" bind-IsVisible="@IsIconEditVisible" />
Expand Down
6 changes: 5 additions & 1 deletion src/Money.UI.Blazor/Pages/Categories.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Money.Events;
using Money.Models;
using Money.Models.Confirmation;
using Money.Models.Loading;
using Money.Models.Queries;
using Neptuo.Commands;
using Neptuo.Events;
Expand Down Expand Up @@ -42,13 +43,16 @@ public class CategoriesBase : BlazorComponent,
protected List<CategoryModel> Models { get; private set; } = new List<CategoryModel>();
protected CategoryModel Selected { get; set; }
protected DeleteContext<CategoryModel> Delete { get; } = new DeleteContext<CategoryModel>();
protected LoadingContext Loading { get; } = new LoadingContext();

protected override async Task OnInitAsync()
{
BindEvents();
Delete.Confirmed += async model => await Commands.HandleAsync(new DeleteCategory(model.Key));
Delete.MessageFormatter = model => $"Do you really want to delete category '{model.Name}'?";
await LoadDataAsync();

using (Loading.Start())
await LoadDataAsync();
}

protected async void Reload()
Expand Down
70 changes: 36 additions & 34 deletions src/Money.UI.Blazor/Pages/Currencies.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,52 @@
<CurrencyEdit bind-IsVisible="@IsCreateVisible" />
<Confirm Context="@Delete" />

@if (Models.Count == 0)
{
<Alert Title="No data." Message="Try adding some currencies." Mode="@AlertMode.Warning" />
}
else
{
@foreach (var item in Models)
<Loading Context="@Loading">
@if (Models.Count == 0)
{
<div class="panel panel-default">
<div class="panel-heading">
<strong>
@item.Symbol
</strong>
</div>
<div class="panel-body">
<p>This currency has unique code @item.UniqueCode.</p>
@if (item.IsDefault)
{
<p>This is a default currency used for displaying outcomes.</p>
}

<div class="nav navbar-nav navbar-right">
@if (!item.IsDefault)
<Alert Title="No data." Message="Try adding some currencies." Mode="@AlertMode.Warning" />
}
else
{
@foreach (var item in Models)
{
<div class="panel panel-default">
<div class="panel-heading">
<strong>
@item.Symbol
</strong>
</div>
<div class="panel-body">
<p>This currency has unique code @item.UniqueCode.</p>
@if (item.IsDefault)
{
<IconButton Icon="home" ToolTip="Set as default" Click="@(async () => { await OnChangeDefaultClickAsync(item); StateHasChanged(); })" />
<p>This is a default currency used for displaying outcomes.</p>
}

@if (Models.Count > 1)
{
<IconButton Icon="transfer" ToolTip="Add exchange rate" Click="@(() => OnActionClick(item, ref IsListExchangeRateVisible))" />
}
<div class="nav navbar-nav navbar-right">
@if (!item.IsDefault)
{
<IconButton Icon="home" ToolTip="Set as default" Click="@(async () => { await OnChangeDefaultClickAsync(item); StateHasChanged(); })" />
}

<IconButton Icon="pencil" ToolTip="Rename" Click="@(() => OnActionClick(item, ref IsEditVisible))" />
@if (Models.Count > 1)
{
<IconButton Icon="transfer" ToolTip="Add exchange rate" Click="@(() => OnActionClick(item, ref IsListExchangeRateVisible))" />
}

@if (Models.Count > 1 && !item.IsDefault)
{
<IconButton Icon="remove" ToolTip="Delete" Click="@(() => OnDeleteClick(item))" />
}
<IconButton Icon="pencil" ToolTip="Rename" Click="@(() => OnActionClick(item, ref IsEditVisible))" />

@if (Models.Count > 1 && !item.IsDefault)
{
<IconButton Icon="remove" ToolTip="Delete" Click="@(() => OnDeleteClick(item))" />
}
</div>
</div>
</div>
</div>

}
}
}
</Loading>

<CurrencyEdit UniqueCode="@Selected?.UniqueCode" Symbol="@Selected?.Symbol" bind-IsVisible="@IsEditVisible" />

Expand Down
6 changes: 5 additions & 1 deletion src/Money.UI.Blazor/Pages/Currencies.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Money.Events;
using Money.Models;
using Money.Models.Confirmation;
using Money.Models.Loading;
using Money.Models.Queries;
using Neptuo.Commands;
using Neptuo.Events;
Expand Down Expand Up @@ -59,13 +60,16 @@ protected bool IsCreateExchangeRateVisible
public List<CurrencyModel> Models { get; private set; } = new List<CurrencyModel>();
public CurrencyModel Selected { get; protected set; }
protected DeleteContext<CurrencyModel> Delete { get; } = new DeleteContext<CurrencyModel>();
protected LoadingContext Loading { get; } = new LoadingContext();

protected override async Task OnInitAsync()
{
BindEvents();
Delete.Confirmed += async model => await Commands.HandleAsync(new DeleteCurrency(model.UniqueCode));
Delete.MessageFormatter = model => $"Do you really want to delete currency '{model.Symbol}'?";
await LoadDataAsync();

using (Loading.Start())
await LoadDataAsync();
}

protected async void OnEvent()
Expand Down

0 comments on commit 0727706

Please sign in to comment.