Skip to content

Commit c97e11b

Browse files
committed
Added portfolio PortfolioEntryDetail.razor page
Edited launchSettings.json Extended CurrencyUtils.cs
1 parent 7471611 commit c97e11b

File tree

4 files changed

+165
-7
lines changed

4 files changed

+165
-7
lines changed

Utils/CurrencyUtils.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,30 @@ public static string GetCurrencyLabel(Currency currency)
2424

2525
public static string Format(decimal value, Currency currency)
2626
{
27-
var valueStr = String.Format("{0:.00}", value);
27+
var valueStr = String.Format("{0:.00}", Math.Abs(value));
28+
var output = "";
2829
switch (currency)
2930
{
3031
case Currency.Czk:
31-
return $"{valueStr},- Kč";
32+
output = $"{valueStr},- Kč";
33+
break;
3234
case Currency.Eur:
33-
return $"{valueStr} €";
35+
output = $"€{valueStr}";
36+
break;
3437
case Currency.Usd:
35-
return $"${valueStr}";
38+
output = $"${valueStr}";
39+
break;
40+
default:
41+
output = "UNDEFINED_CURRENCY";
42+
break;
3643
}
3744

38-
return "UNDEFINED";
45+
if (value < 0)
46+
{
47+
output = "-" + output;
48+
}
49+
50+
return output;
3951
}
4052
}
4153
}

WebFrontend/Pages/Index.razor

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
@using Model
33
@using Services
44
@using Utils
5+
@inject Microsoft.AspNetCore.Components.NavigationManager NavigationManager
6+
57
<style>
68
.demo-mat-card {
79
margin-bottom: 2em;
@@ -52,7 +54,7 @@
5254
</MatBody2>
5355
</MatCardContent>
5456
</MatCard>
55-
<MatTable Items="@portfolioEntryRows" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999">
57+
<MatTable Items="@portfolioEntryRows" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999" SelectionChanged="SelectionChangedEvent">
5658
<MatTableHeader>
5759
<th>Coin</th>
5860
<th>Price</th>
@@ -113,4 +115,15 @@
113115
//_existingPortfolios = PortfolioService.GetPortfolios();
114116
}
115117

118+
public void SelectionChangedEvent(object row)
119+
{
120+
if (row == null)
121+
{
122+
}
123+
else
124+
{
125+
NavigationManager.NavigateTo($"entrydetail");
126+
}
127+
}
128+
116129
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
@page "/entrydetail"
2+
@using Model
3+
@using Services
4+
@using Utils
5+
@inject Microsoft.AspNetCore.Components.NavigationManager NavigationManager
6+
@inject IMatDialogService MatDialogService
7+
8+
<style>
9+
.demo-mat-card {
10+
margin-bottom: 2em;
11+
}
12+
13+
.demo-mat-card-content {
14+
padding: 1rem;
15+
}
16+
17+
.clear-margin {
18+
margin: 0px;
19+
}
20+
21+
.clear-margin-vertical {
22+
margin-top: 0px;
23+
margin-bottom: 0px;
24+
}
25+
.app-fab--absolute {
26+
position: fixed;
27+
bottom: 1rem;
28+
right: 1rem;
29+
}
30+
31+
</style>
32+
<div class="mat-layout-grid mat-layout-grid-align-center">
33+
<div class="mat-layout-grid-inner center">
34+
35+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-2"></div>
36+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-8">
37+
<MatCard class="demo-mat-card">
38+
<MatCardContent>
39+
<div class="demo-mat-card-content">
40+
<MatHeadline6 class="clear-margin">
41+
<MatChipSet Style="align-items: center">
42+
<MatH5 Class="clear-margin-vertical">@portfolioEntryName</MatH5>
43+
<MatChip Style="vertical-align: center" Label="@(activePortfolioEntry.Symbol.ToUpper())"/>
44+
<MatH6 Class="clear-margin-vertical" Style="text-align: end;float: end;">1 BTC = $30 000</MatH6>
45+
</MatChipSet>
46+
</MatHeadline6>
47+
</div>
48+
49+
<MatBody2 class="demo-mat-card-content clear-margin">
50+
<div class="mat-layout-grid">
51+
<div class="mat-layout-grid-inner" style="align-items: center">
52+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
53+
<MatH4 Class="clear-margin">@(CurrencyUtils.Format(entrySummary.MarketValue, activePortfolio.Currency))</MatH4>
54+
</div>
55+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: end">
56+
@(entrySummary.RelativeChange * 100m) %
57+
</div>
58+
</div>
59+
</div>
60+
</MatBody2>
61+
</MatCardContent>
62+
</MatCard>
63+
<MatTable Items="@tableRowsItems" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999">
64+
<MatTableHeader>
65+
<th>Date</th>
66+
<th>Size</th>
67+
<th>Market Value</th>
68+
<th>Change</th>
69+
<th>Cost</th>
70+
<th>Fee</th>
71+
<th>Actions</th>
72+
</MatTableHeader>
73+
<MatTableRow>
74+
<td>
75+
<div style="min-width: 9rem">@(String.Format("{0:d.M.yyyy HH:mm:ss}", context.Item1.Date))</div>
76+
</td>
77+
<td>
78+
<div style="min-width: 9rem">@context.Item1.Size @activePortfolioEntry.Symbol.ToUpper()</div>
79+
</td>
80+
<td>@CurrencyUtils.Format(context.Item2.MarketValue, activePortfolio.Currency)</td>
81+
<td style='color: @(context.Item2.RelativeChange >= 0 ? "#17a104" : "#FF0000")'>
82+
<div style="min-width: 9rem">@CurrencyUtils.Format(context.Item2.AbsoluteChange, activePortfolio.Currency) (@(context.Item2.RelativeChange * 100)%)</div>
83+
</td>
84+
<td>@CurrencyUtils.Format(context.Item2.Cost, activePortfolio.Currency)</td>
85+
<td>@CurrencyUtils.Format(context.Item1.Fee, activePortfolio.Currency)</td>
86+
<td>
87+
<MatIconButton Icon="edit" OnClick="EditMarketOrder"></MatIconButton>
88+
<MatIconButton Icon="delete" OnClick="DeletePortfolio"></MatIconButton>
89+
</td>
90+
</MatTableRow>
91+
</MatTable>
92+
</div>
93+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-2"></div>
94+
</div>
95+
</div>
96+
<MatFAB Class="app-fab--absolute" Icon="@MatIconNames.Add" Label="Add a new order"></MatFAB>
97+
98+
99+
@code
100+
{
101+
protected Portfolio activePortfolio = new Portfolio("Main Portfolio", "My main portfolio to be used", Currency.Usd);
102+
protected PortfolioEntry activePortfolioEntry = new("btc");
103+
protected string portfolioEntryName = "Bitcoin";
104+
protected ISummaryService.Summary entrySummary = new(523m, 0.719m, 1268.89m, 745.58m);
105+
106+
protected List<Tuple<MarketOrder, ISummaryService.Summary>> tableRowsItems = new()
107+
{
108+
new Tuple<MarketOrder, ISummaryService.Summary>(new(18300m, 0.1m, 0.003266m, DateTime.Now.AddMonths(-6), false), new(120m, 2m, 183.00m, 60m)),
109+
new Tuple<MarketOrder, ISummaryService.Summary>(new(21200, 0.3m, 0.002866m, DateTime.Now.AddDays(91), false), new(101m, 2m, 123.00m, 45m)),
110+
new Tuple<MarketOrder, ISummaryService.Summary>(new(18300m, 0.1m, 0.003266m, DateTime.Now.AddMonths(-6), false), new(180m - 30m, 2.3m, 113.00m, 23m)),
111+
new Tuple<MarketOrder, ISummaryService.Summary>(new(18300m, 0.1m, 0.003266m, DateTime.Now.AddMonths(-6), false), new(-60m, -0.6m, 40.00m, 100m)),
112+
};
113+
114+
protected record PortfolioEntryRow(string symbol, decimal currentPrice, decimal relativeChange, decimal percentage);
115+
116+
protected override async Task OnInitializedAsync()
117+
{
118+
//_existingPortfolios = PortfolioService.GetPortfolios();
119+
}
120+
121+
public void EditMarketOrder(MouseEventArgs e)
122+
{
123+
NavigationManager.NavigateTo($"editorder");
124+
}
125+
126+
async void DeletePortfolio(MouseEventArgs e)
127+
{
128+
var result = await MatDialogService.ConfirmAsync("Do you really wish to delete this market order?");
129+
if (result)
130+
{
131+
}
132+
}
133+
}

WebFrontend/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ServerSideBlazor": {
1919
"commandName": "Project",
2020
"dotnetRunMessages": "true",
21-
"launchBrowser": true,
21+
"launchBrowser": false,
2222
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2323
"environmentVariables": {
2424
"ASPNETCORE_ENVIRONMENT": "Development"

0 commit comments

Comments
 (0)