-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@page "/{Year:int}/{Month:int}/overview/incomes" | ||
|
||
<Title Icon="calendar" Main="@($"Incomes in {MonthModel}")" Sub="List of each single income in selected month"> | ||
<ButtonContent> | ||
<IncomeCreateButton OnClick="CreateModal.Show" /> | ||
</ButtonContent> | ||
</Title> | ||
<ExceptionPanel /> | ||
|
||
<IncomeCreate @ref="CreateModal" /> | ||
<Confirm @ref="DeleteConfirm" Message="@DeleteMessage" OnConfirmed="@OnDeleteConfirmed" /> | ||
|
||
<div class="overview"> | ||
<Loading Context="@Loading" IsOverlay="true"> | ||
<ul class="nav nav-pills float-left"> | ||
<li> | ||
<a class="nav-link active" href="@Navigator.UrlOverviewIncomes(MonthModel)">Incomes</a> | ||
</li> | ||
<li> | ||
<a class="nav-link" href="@Navigator.UrlOverview(MonthModel)">Expenses</a> | ||
</li> | ||
</ul> | ||
|
||
@if (Items != null) | ||
{ | ||
if (Items.Count > 0) | ||
{ | ||
<SortButton TType="@IncomeOverviewSortType" @bind-Current="@SortDescriptor" Changed="@OnSortChanged" /> | ||
<div class="clear"></div> | ||
|
||
<div class="cards"> | ||
<CascadingValue Value="@this"> | ||
@foreach (var item in Items) | ||
{ | ||
<div class="outcome-card"> | ||
<div class="data"> | ||
<h2 class="amount">@CurrencyFormatter.Format(item.Amount)</h2> | ||
<p class="when">@item.When.ToShortDateString()</p> | ||
<p class="description">@item.Description</p> | ||
</div> | ||
<div class="controls"> | ||
<IconButton Icon="trash-alt" ToolTip="Delete" Click="@(() => OnDeleteClick(item))" /> | ||
</div> | ||
<div class="clear"></div> | ||
</div> | ||
} | ||
</CascadingValue> | ||
</div> | ||
|
||
<Paging Context="@PagingContext" /> | ||
} | ||
else | ||
{ | ||
<Alert Title="No data." Message="Let's add some incomes." Mode="@AlertMode.Warning" /> | ||
} | ||
} | ||
</Loading> | ||
</div> |
170 changes: 170 additions & 0 deletions
170
src/Money.Blazor.Host/Pages/OverviewMonthIncome.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Money.Commands; | ||
using Money.Components; | ||
using Money.Events; | ||
using Money.Models; | ||
using Money.Models.Loading; | ||
using Money.Models.Queries; | ||
using Money.Models.Sorting; | ||
using Money.Services; | ||
using Neptuo.Commands; | ||
using Neptuo.Events; | ||
using Neptuo.Events.Handlers; | ||
using Neptuo.Queries; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Pages | ||
{ | ||
public partial class OverviewMonthIncome : IDisposable, | ||
IEventHandler<IncomeCreated>, | ||
IEventHandler<IncomeDeleted>, | ||
IEventHandler<PulledToRefresh> | ||
{ | ||
public CurrencyFormatter CurrencyFormatter { get; private set; } | ||
|
||
[Inject] | ||
public ICommandDispatcher Commands { get; set; } | ||
|
||
[Inject] | ||
public IEventHandlerCollection EventHandlers { get; set; } | ||
|
||
[Inject] | ||
public IQueryDispatcher Queries { get; set; } | ||
|
||
[Inject] | ||
public Interop Interop { get; set; } | ||
|
||
[Inject] | ||
public Navigator Navigator { get; set; } | ||
|
||
[Parameter] | ||
public int Year { get; set; } | ||
|
||
[Parameter] | ||
public int Month { get; set; } | ||
|
||
protected MonthModel MonthModel { get; set; } | ||
|
||
protected List<IncomeOverviewModel> Items { get; set; } | ||
protected IncomeOverviewModel SelectedItem { get; set; } | ||
|
||
protected IncomeCreate CreateModal { get; set; } | ||
|
||
protected LoadingContext Loading { get; } = new LoadingContext(); | ||
protected SortDescriptor<IncomeOverviewSortType> SortDescriptor { get; set; } = new SortDescriptor<IncomeOverviewSortType>(IncomeOverviewSortType.ByWhen, SortDirection.Descending); | ||
protected PagingContext PagingContext { get; set; } | ||
|
||
protected IncomeOverviewModel Selected { get; set; } | ||
protected string DeleteMessage { get; set; } | ||
protected Confirm DeleteConfirm { get; set; } | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
PagingContext = new PagingContext(LoadDataAsync, Loading); | ||
|
||
BindEvents(); | ||
|
||
MonthModel = new MonthModel(Year, Month); | ||
|
||
CurrencyFormatter = new CurrencyFormatter(await Queries.QueryAsync(new ListAllCurrency())); | ||
Reload(); | ||
} | ||
|
||
protected async void Reload() | ||
{ | ||
await PagingContext.LoadAsync(0); | ||
StateHasChanged(); | ||
} | ||
|
||
protected async Task<PagingLoadStatus> LoadDataAsync() | ||
{ | ||
await Interop.ScrollToTopAsync(); | ||
|
||
List<IncomeOverviewModel> models = await Queries.QueryAsync(new ListMonthIncome(MonthModel, SortDescriptor, PagingContext.CurrentPageIndex)); | ||
if (models.Count == 0) | ||
return PagingLoadStatus.EmptyPage; | ||
|
||
Items = models; | ||
return Items.Count == 10 ? PagingLoadStatus.HasNextPage : PagingLoadStatus.LastPage; | ||
} | ||
|
||
protected async void OnSortChanged() | ||
{ | ||
await PagingContext.LoadAsync(0); | ||
StateHasChanged(); | ||
} | ||
|
||
protected void OnActionClick(IncomeOverviewModel model, ModalDialog modal) | ||
{ | ||
SelectedItem = model; | ||
modal.Show(); | ||
StateHasChanged(); | ||
} | ||
|
||
protected void OnDeleteClick(IncomeOverviewModel model) | ||
{ | ||
Selected = model; | ||
DeleteMessage = $"Do you really want to delete income '{model.Description}'?"; | ||
DeleteConfirm.Show(); | ||
StateHasChanged(); | ||
} | ||
|
||
protected async void OnDeleteConfirmed() | ||
{ | ||
await Commands.HandleAsync(new DeleteIncome(Selected.Key)); | ||
StateHasChanged(); | ||
} | ||
|
||
protected IncomeOverviewModel FindModel(IEvent payload) | ||
=> Items.FirstOrDefault(o => o.Key.Equals(payload.AggregateKey)); | ||
|
||
public void Dispose() | ||
=> UnBindEvents(); | ||
|
||
#region Events | ||
|
||
private void BindEvents() | ||
{ | ||
EventHandlers | ||
.Add<IncomeCreated>(this) | ||
.Add<IncomeDeleted>(this) | ||
.Add<PulledToRefresh>(this); | ||
} | ||
|
||
private void UnBindEvents() | ||
{ | ||
EventHandlers | ||
.Remove<IncomeCreated>(this) | ||
.Remove<IncomeDeleted>(this) | ||
.Remove<PulledToRefresh>(this); | ||
} | ||
|
||
Task IEventHandler<IncomeCreated>.HandleAsync(IncomeCreated payload) | ||
{ | ||
if (MonthModel == payload.When) | ||
Reload(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
Task IEventHandler<IncomeDeleted>.HandleAsync(IncomeDeleted payload) | ||
{ | ||
Reload(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
Task IEventHandler<PulledToRefresh>.HandleAsync(PulledToRefresh payload) | ||
{ | ||
payload.IsHandled = true; | ||
_ = LoadDataAsync(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters