Skip to content

Commit

Permalink
Resize filter
Browse files Browse the repository at this point in the history
  • Loading branch information
liguori committed Dec 18, 2023
1 parent 2bf3e63 commit ea9d309
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 108 deletions.
8 changes: 4 additions & 4 deletions src/Savings.SPA/Pages/Projection.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ else
<RadzenDatePicker @bind-Value="FilterDateTo" DateFormat="dd/MM/yyyy" Change="@(args => Change(args, nameof(FilterDateTo)))" />
</div>
<div class="col-md-1 col-2">
<label>Hide past</label><br>
<RadzenSwitch @bind-Value="@HidePastItems" Change="HidePastItems_Changed" />
<label>Past</label><br>
<RadzenSwitch @bind-Value="@ShowPastItems" Change="PastItems_Changed" />
</div>
<div class="col-md-1 col-3">
<label>Hide zero</label><br>
<RadzenSwitch @bind-Value="@HideZero" Change="HideZero_Changed" />
<label>Zero</label><br>
<RadzenSwitch @bind-Value="@ShowZero" Change="Zero_Changed" />
</div>
<div class="col-md-8 col-2">
<br />
Expand Down
208 changes: 104 additions & 104 deletions src/Savings.SPA/Pages/Projection.razor.cs
Original file line number Diff line number Diff line change
@@ -1,122 +1,122 @@
using Microsoft.AspNetCore.Components;
using Savings.Model;
using Savings.SPA.Services;
using System;
using System.Threading.Tasks;
using Radzen;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;

namespace Savings.SPA.Pages
{
public partial class Projection : ComponentBase
{
[Inject]
public ISavingsApi savingsAPI { get; set; }

private MaterializedMoneyItem[] materializedMoneyItems;

[Inject]
public DialogService dialogService { get; set; }

public bool HidePastItems { get; set; } = true;

public bool HideZero { get; set; } = true;

public DateTime? FilterDateTo { get; set; }

public Configuration CurrentConfiguration { get; set; }

protected override async Task OnInitializedAsync()
{
FilterDateTo = DateTime.Now.Date.AddYears(1);
await InitializeList();
CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault();
}


async void HidePastItems_Changed()
using Microsoft.AspNetCore.Components;
using Savings.Model;
using Savings.SPA.Services;
using System;
using System.Threading.Tasks;
using Radzen;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;

namespace Savings.SPA.Pages
{
public partial class Projection : ComponentBase
{
[Inject]
public ISavingsApi savingsAPI { get; set; }

private MaterializedMoneyItem[] materializedMoneyItems;

[Inject]
public DialogService dialogService { get; set; }

public bool ShowPastItems { get; set; } = false;

public bool ShowZero { get; set; } = false;

public DateTime? FilterDateTo { get; set; }

public Configuration CurrentConfiguration { get; set; }

protected override async Task OnInitializedAsync()
{
FilterDateTo = DateTime.Now.Date.AddYears(1);
await InitializeList();
CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault();
}


async void PastItems_Changed()
{
await InitializeList();
StateHasChanged();
}

async void Zero_Changed()
{
await InitializeList();
StateHasChanged();
}

async void HideZero_Changed()
async void Change(DateTime? value, string name)
{
await InitializeList();
StateHasChanged();
}

async void Change(DateTime? value, string name)
{
await InitializeList();
StateHasChanged();
}


async Task InitializeList()
{
}


async Task InitializeList()
{
materializedMoneyItems = await savingsAPI.GetSavings(null, FilterDateTo);

if (HidePastItems)
if (!ShowPastItems)
{
var lastBeforeToday = materializedMoneyItems.LastOrDefault(x => x.Date <= DateTime.Now.Date);
if (lastBeforeToday != null)
{
materializedMoneyItems = materializedMoneyItems[Array.IndexOf(materializedMoneyItems, lastBeforeToday)..];
}
}
if(HideZero)
}
if(!ShowZero)
{
materializedMoneyItems = materializedMoneyItems.Where(x => x.Amount != 0).ToArray();
}
}

async Task AdjustRecurrency(MaterializedMoneyItem item)
{
if (item.EndPeriod) return;
var res = await dialogService.OpenAsync<RecurrencyAdjustment>($"Recurrency Adjustment",
new Dictionary<string, object>() { { "materializedItem", item } },
new DialogOptions() { Width = "600px", Height = "300px" });
await InitializeList();
StateHasChanged();
}

async Task AdjustFixedItem(MaterializedMoneyItem item)
{
if (item.EndPeriod) return;
if (!item.FixedMoneyItemID.HasValue) return;
var itemToEdit = await savingsAPI.GetixedMoneyItem(item.FixedMoneyItemID.Value);
bool? res = await dialogService.OpenAsync<FixedItemEdit>($"Edit item",
new Dictionary<string, object>() { { "fixedItemToEdit", itemToEdit }, { "isNew", false } },
new DialogOptions() { Width = "600px" });
if (res.HasValue && res.Value)
{
await InitializeList();
StateHasChanged();
}
}

async Task SaveMaterializedHistory(DateTime date)
{
var res = await dialogService.Confirm($"Do you want to save the projection to the history until {date:dd/MM/yyyy}?", "Save the history", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" });
if (res.HasValue && res.Value)
{
await savingsAPI.PostSavingsToHistory(date);
await InitializeList();
}
}

async Task AddNew()
{
bool? res = await dialogService.OpenAsync<FixedItemEdit>($"Add new",
new Dictionary<string, object>() { { "fixedItemToEdit", new Savings.Model.FixedMoneyItem() }, { "isNew", true } },
new DialogOptions() { Width = "700px" });
if (res.HasValue && res.Value)
{
await InitializeList();
StateHasChanged();
}
}
}
}
}
}

async Task AdjustRecurrency(MaterializedMoneyItem item)
{
if (item.EndPeriod) return;
var res = await dialogService.OpenAsync<RecurrencyAdjustment>($"Recurrency Adjustment",
new Dictionary<string, object>() { { "materializedItem", item } },
new DialogOptions() { Width = "600px", Height = "300px" });
await InitializeList();
StateHasChanged();
}

async Task AdjustFixedItem(MaterializedMoneyItem item)
{
if (item.EndPeriod) return;
if (!item.FixedMoneyItemID.HasValue) return;
var itemToEdit = await savingsAPI.GetixedMoneyItem(item.FixedMoneyItemID.Value);
bool? res = await dialogService.OpenAsync<FixedItemEdit>($"Edit item",
new Dictionary<string, object>() { { "fixedItemToEdit", itemToEdit }, { "isNew", false } },
new DialogOptions() { Width = "600px" });
if (res.HasValue && res.Value)
{
await InitializeList();
StateHasChanged();
}
}

async Task SaveMaterializedHistory(DateTime date)
{
var res = await dialogService.Confirm($"Do you want to save the projection to the history until {date:dd/MM/yyyy}?", "Save the history", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" });
if (res.HasValue && res.Value)
{
await savingsAPI.PostSavingsToHistory(date);
await InitializeList();
}
}

async Task AddNew()
{
bool? res = await dialogService.OpenAsync<FixedItemEdit>($"Add new",
new Dictionary<string, object>() { { "fixedItemToEdit", new Savings.Model.FixedMoneyItem() }, { "isNew", true } },
new DialogOptions() { Width = "700px" });
if (res.HasValue && res.Value)
{
await InitializeList();
StateHasChanged();
}
}
}
}

0 comments on commit ea9d309

Please sign in to comment.