-
Notifications
You must be signed in to change notification settings - Fork 2
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
54 changed files
with
3,281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- | ||
Configuring this here is temporary. Later we'll move the app config | ||
into Program.cs, and it won't be necessary to specify AppAssembly. | ||
--> | ||
<Router AppAssembly=typeof(Program).Assembly /> |
27 changes: 27 additions & 0 deletions
27
src/BlazorConverters.Client/BlazorConverters.Client.csproj
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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<LangVersion>7.3</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="wwwroot\css\bootstrap\bootstrap.min.css.map" /> | ||
<None Include="wwwroot\css\open-iconic\FONT-LICENSE" /> | ||
<None Include="wwwroot\css\open-iconic\font\fonts\open-iconic.svg" /> | ||
<None Include="wwwroot\css\open-iconic\ICON-LICENSE" /> | ||
<None Include="wwwroot\css\open-iconic\README.md" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.7.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.7.0" PrivateAssets="all" /> | ||
<PackageReference Include="UnitsNet" Version="4.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BlazorConverters.Shared\BlazorConverters.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/BlazorConverters.Client/Pages/Converters/Angle/Angle.cshtml
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,8 @@ | ||
@page "/angle" | ||
<div class="container-fluid"> | ||
<PageHeader Title="Angle" Link="/angle"></PageHeader> | ||
<GenericConverter CurrentUnitCategory="@Category"></GenericConverter> | ||
</div> | ||
@functions { | ||
UnitCategory Category = UnitCategory.Angle; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/BlazorConverters.Client/Pages/Converters/Area/Area.cshtml
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,8 @@ | ||
@page "/area" | ||
<div class="container-fluid"> | ||
<PageHeader Title="Area" Link="/area"></PageHeader> | ||
<GenericConverter CurrentUnitCategory="@Category"></GenericConverter> | ||
</div> | ||
@functions { | ||
UnitCategory Category = UnitCategory.Area; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/BlazorConverters.Client/Pages/Converters/Currency/Currency.cshtml
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,48 @@ | ||
@inherits CurrencyModel | ||
@page "/" | ||
@page "/currency" | ||
|
||
|
||
<div class="container-fluid"> | ||
<PageHeader Title="Currency" Link="/currency"></PageHeader> | ||
<div class="row mt-4"> | ||
<div class="col-md-7"> | ||
<div class="card"> | ||
<div class="card-header bg-dark text-white"> | ||
Source Currency | ||
</div> | ||
<div class="card-body bg-light"> | ||
<CurrencyDisplay Symbol="@SourceCurrency.Symbol" | ||
Value="@SourceCurrencyInput" | ||
DecimalPlaces="0"></CurrencyDisplay> | ||
<CurrencyOptions Value="@SelectedSourceCurrency" | ||
Currencies="@Currencies" | ||
CurrencyChanged="@OnSourceCurrencyChanged"></CurrencyOptions> | ||
</div> | ||
</div> | ||
<div class="card mt-2"> | ||
<div class="card-header bg-dark text-white"> | ||
Target Currency | ||
</div> | ||
<div class="card-body bg-light"> | ||
<CurrencyDisplay Symbol="@TargetCurrency.Symbol" | ||
Value="@TargetCurrencyInput" | ||
DecimalPlaces="2"></CurrencyDisplay> | ||
<CurrencyOptions Value="@SelectedTargetCurrency" | ||
Currencies="@Currencies" | ||
CurrencyChanged="@OnTargetCurrencyChanged"></CurrencyOptions> | ||
</div> | ||
</div> | ||
|
||
<div class="row mt-5"> | ||
<div class="col-md-12"> | ||
<small>1 @SelectedSourceCurrency = @(Rate == 0 || Rate == 1 ? Rate.ToString() : Rate.ToString("N4")) @SelectedTargetCurrency</small> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-md-5"> | ||
<Keyboard OnKeyInput="OnKeyInput"></Keyboard> | ||
</div> | ||
</div> | ||
</div> | ||
<span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span> |
77 changes: 77 additions & 0 deletions
77
src/BlazorConverters.Client/Pages/Converters/Currency/Currency.cshtml.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,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using BlazorCalculator.Services; | ||
using BlazorConverters.Data; | ||
using Microsoft.AspNetCore.Blazor; | ||
using Microsoft.AspNetCore.Blazor.Components; | ||
|
||
namespace BlazorConverters.Client.Pages | ||
{ | ||
public class CurrencyModel : BlazorComponent | ||
{ | ||
[Inject] CurrencyService CurrencyService { get; set; } | ||
|
||
protected IEnumerable<Currency> Currencies { get; set; } = null; | ||
protected Currency SourceCurrency { get; set; } = null; | ||
protected double SourceCurrencyInput { get; set; } = 1; | ||
protected string SelectedSourceCurrency { get; set; } | ||
protected Currency TargetCurrency { get; set; } = null; | ||
protected double TargetCurrencyInput { get; set; } = 1; | ||
protected string SelectedTargetCurrency { get; set; } | ||
protected double Rate { get; set; } | ||
protected override async Task OnInitAsync() | ||
{ | ||
Currencies = CurrencyService.GetCurrencies(); | ||
SourceCurrency = Currencies.First(); | ||
SelectedSourceCurrency = SourceCurrency.Code; | ||
TargetCurrency = Currencies.First(); | ||
SelectedTargetCurrency = TargetCurrency.Code; | ||
await CalculateRate(); | ||
} | ||
|
||
private async Task CalculateRate() | ||
{ | ||
Rate = await CurrencyService.CalculateConversionRate(SelectedSourceCurrency, SelectedTargetCurrency); | ||
TargetCurrencyInput = Rate * SourceCurrencyInput; | ||
} | ||
|
||
protected async Task OnSourceCurrencyChanged(UIChangeEventArgs e) | ||
{ | ||
SelectedSourceCurrency = e.Value.ToString(); | ||
SourceCurrency = Currencies.First(c => c.Code == SelectedSourceCurrency); | ||
await CalculateRate(); | ||
StateHasChanged(); | ||
} | ||
|
||
protected async Task OnTargetCurrencyChanged(UIChangeEventArgs e) | ||
{ | ||
SelectedTargetCurrency = e.Value.ToString(); | ||
TargetCurrency = Currencies.First(c => c.Code == SelectedTargetCurrency); | ||
await CalculateRate(); | ||
StateHasChanged(); | ||
} | ||
|
||
protected async Task OnKeyInput(string key) | ||
{ | ||
var currString = SourceCurrencyInput.ToString(); | ||
switch (key.ToLower()) | ||
{ | ||
case "ce": | ||
currString = "0"; | ||
break; | ||
case "backspace": | ||
currString = currString.Substring(0, currString.Length - 1); | ||
break; | ||
default: | ||
currString = (currString.Length == 1 && currString == "0") | ||
? key : $"{currString}{key}"; | ||
break; | ||
} | ||
SourceCurrencyInput = double.Parse(currString); | ||
await CalculateRate(); | ||
StateHasChanged(); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/BlazorConverters.Client/Pages/Converters/Currency/CurrencyDisplay.cshtml
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,14 @@ | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div> | ||
<span class="h5 font-weight-lighter">@Symbol</span> | ||
<NumberDisplay DisplayLevel="4" DisplayValue="@Value" DecimalPlaces="@DecimalPlaces"></NumberDisplay> | ||
</div> | ||
</div> | ||
</div> | ||
@functions | ||
{ | ||
[Parameter] protected string Symbol { get; set; } | ||
[Parameter] protected double Value { get; set; } | ||
[Parameter] protected int DecimalPlaces { get; set; } | ||
} |
24 changes: 24 additions & 0 deletions
24
src/BlazorConverters.Client/Pages/Converters/Currency/CurrencyOptions.cshtml
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,24 @@ | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="form-group"> | ||
<select class="form-control" id="sourceCurrency" value="@Value" | ||
onchange="@CurrencyChanged"> | ||
@foreach (var currency in Currencies) | ||
{ | ||
<option value="@currency.Code">@currency.Name</option> | ||
} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
@functions | ||
{ | ||
[Parameter] | ||
protected IEnumerable<Data.Currency> Currencies { get; set; } | ||
|
||
[Parameter] | ||
protected string Value { get; set; } | ||
|
||
[Parameter] | ||
protected Func<UIChangeEventArgs, Task> CurrencyChanged { get; set; } | ||
} |
Oops, something went wrong.