Skip to content

Commit

Permalink
#444 - Collapsible templates selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Nov 26, 2022
1 parent 3348afa commit 058b4d8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
81 changes: 44 additions & 37 deletions src/Money.Blazor.Host/Components/OutcomeCreate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,55 @@
<ChildContent>
@if (Templates != null)
{
<style>
.card.card-hover {
height: calc(100% - 15px);
}
</style>
<div class="form-row">
@foreach (var model in Templates)
{
<div class="col-6 col-sm-6 col-md-4">
<div class="card card-hover cursor-pointer" @onclick="(() => ApplyTemplate(model))">
<div class="card-body">
<div>
<strong>
@CurrencyFormatter.Format(model.Amount, CurrencyFormatter.FormatZero.Placehoder)
</strong>
</div>
<button class="btn btn-light btn-block text-left mb-3" @onclick="(() => AreTemplatesOpened = !AreTemplatesOpened)">
<Icon Identifier="redo" />
Templates
</button>
@if (AreTemplatesOpened)
{
<style>
.card.card-hover {
height: calc(100% - 15px);
}
</style>
<div class="form-row">
@foreach (var model in Templates)
{
<div class="col-6 col-sm-6 col-md-4">
<div class="card card-hover cursor-pointer" @onclick="(() => ApplyTemplate(model))">
<div class="card-body">
<div>
<strong>
@CurrencyFormatter.Format(model.Amount, CurrencyFormatter.FormatZero.Placehoder)
</strong>
</div>

@if (!model.CategoryKey.IsEmpty)
{
<p class="m-0 @FindCategoryColor(model.CategoryKey)?.SelectAccent("back-dark", "back-light")">
<span class="badge" style="background-color: @FindCategoryColor(model.CategoryKey)?.ToHashCode()">@FindCategoryName(model.CategoryKey)</span>
</p>
}
@if (!model.CategoryKey.IsEmpty)
{
<p class="m-0 @FindCategoryColor(model.CategoryKey)?.SelectAccent("back-dark", "back-light")">
<span class="badge" style="background-color: @FindCategoryColor(model.CategoryKey)?.ToHashCode()">@FindCategoryName(model.CategoryKey)</span>
</p>
}

@if (!String.IsNullOrEmpty(model.Description))
{
<p class="text-truncate">
<small>
@model.Description
@if (!String.IsNullOrEmpty(model.Description))
{
<p class="text-truncate">
<small>
@model.Description

@if (model.IsFixed)
{
<em class="text-muted ml-1">Fixed</em>
}
</small>
</p>
}
@if (model.IsFixed)
{
<em class="text-muted ml-1">Fixed</em>
}
</small>
</p>
}
</div>
</div>
</div>
</div>
}
</div>
}
</div>
}
}
<Validation ErrorMessages="@ErrorMessages" />
<div class="form-group">
Expand Down
6 changes: 5 additions & 1 deletion src/Money.Blazor.Host/Components/OutcomeCreate.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public partial class OutcomeCreate : System.IDisposable
[Parameter]
public bool IsFixed { get; set; }

protected bool AreTemplatesOpened { get; set; }

private bool isAttachedToComponentContainer;

protected override void OnInitialized()
Expand Down Expand Up @@ -192,14 +194,16 @@ protected void ApplyTemplate(ExpenseTemplateModel model)
{
Amount = model.Amount.Value;
Currency = model.Amount.Currency;
IsFixed = model.IsFixed;
}

if (!String.IsNullOrEmpty(model.Description))
Description = model.Description;

if (!model.CategoryKey.IsEmpty)
CategoryKey = model.CategoryKey;

IsFixed = model.IsFixed;
AreTemplatesOpened = false;
}

protected string FindCategoryName(IKey categoryKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ExpenseTemplateEntity(ExpenseTemplateCreated payload)
if (!payload.CategoryKey.IsEmpty)
CategoryId = payload.CategoryKey.AsGuidKey().Guid;

IsFixed = true;
IsFixed = payload.IsFixed;
}

public ExpenseTemplateModel ToModel(int version) => version == 1
Expand Down

0 comments on commit 058b4d8

Please sign in to comment.