Browse Source

Dashboard WIP Commit 1

pull/7/head
Benjamin Arhen 2 years ago
parent
commit
588011480f
  1. 4
      .editorconfig
  2. 5
      Biskilog Accounting.sln
  3. 9
      Client/Biskilog Accounting.Client.csproj
  4. 16
      Client/Elements/Sidebar.razor
  5. 25
      Client/Elements/Sidebar.razor.cs
  6. 105
      Client/Models/NavItem.cs
  7. 28
      Client/Pages/Dashboard/Dashboard.razor
  8. 19
      Client/Pages/Dashboard/Dashboard.razor.cs
  9. 25
      Client/Pages/Dashboard/Elements/WelcomeCard.razor
  10. 40
      Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs
  11. 6
      Client/Program.cs
  12. 1
      Server/Biskilog Accounting.Server.csproj
  13. 1
      Shared/Biskilog Accounting.Shared.csproj
  14. 16
      Shared/Interfaces/ICalculator.cs
  15. 39
      Shared/ServiceRepo/CalculatorService.cs
  16. 4
      Shared/ServiceRepo/TokenService.cs

4
.editorconfig

@ -0,0 +1,4 @@
[*.cs]
# IDE0021: Use block body for constructor
csharp_style_expression_bodied_constructors = when_on_single_line

5
Biskilog Accounting.sln

@ -9,6 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biskilog Accounting.Client"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biskilog Accounting.Shared", "Shared\Biskilog Accounting.Shared.csproj", "{48490CB4-D5CE-46FE-9A7A-FBC91980D262}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biskilog Accounting.Shared", "Shared\Biskilog Accounting.Shared.csproj", "{48490CB4-D5CE-46FE-9A7A-FBC91980D262}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{84405340-FCB0-46CB-B730-10E47D9F54C2}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

9
Client/Biskilog Accounting.Client.csproj

@ -8,8 +8,13 @@
<AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName> <AssemblyName>$(AssemblyName.Replace(' ', '_'))</AssemblyName>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
@ -23,8 +28,4 @@
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" /> <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Pages\Dashboard\Elements\" />
</ItemGroup>
</Project> </Project>

16
Client/Elements/Sidebar.razor

@ -1,5 +1,5 @@
@using Biskilog_Accounting.Client.Models; @using Biskilog_Accounting.Client.Models;
<aside id="layout-menu" class="layout-menu menu-vertical menu bg-menu-theme"> <aside id="layout-menu" class="@m_class menu-vertical menu bg-menu-theme">
<div class="app-brand"> <div class="app-brand">
<a href="index.html" class="app-brand-link"> <a href="index.html" class="app-brand-link">
<span class="app-brand-logo"> <span class="app-brand-logo">
@ -8,7 +8,7 @@
<span class="app-brand-text menu-text fw-bolder ms-2">BISKILOG</span> <span class="app-brand-text menu-text fw-bolder ms-2">BISKILOG</span>
</a> </a>
<a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto d-block d-xl-none"> <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto d-block" @onclick="Collapse">
<i class="bx bx-chevron-left bx-sm align-middle"></i> <i class="bx bx-chevron-left bx-sm align-middle"></i>
</a> </a>
</div> </div>
@ -26,15 +26,3 @@
</ul> </ul>
</aside> </aside>
@code {
private double m_activeId = 1;
private void HandleMenuClick(double a_selectedId)
{
m_activeId = a_selectedId;
StateHasChanged();
}
}

25
Client/Elements/Sidebar.razor.cs

@ -0,0 +1,25 @@
namespace Biskilog_Accounting.Client.Elements
{
public partial class Sidebar
{
private double m_activeId = 1;
private string m_class { get; set; } = "layout-menu";
private void HandleMenuClick(double a_selectedId)
{
m_activeId = a_selectedId;
StateHasChanged();
}
private void Collapse()
{
if (m_class == "layout-menu")
{
m_class = "layout-menu-collapsed";
}
else
{
m_class = "layout-menu";
}
}
}
}

105
Client/Models/NavItem.cs

@ -46,53 +46,112 @@
Link = "", Link = "",
Title = "Dashboard" Title = "Dashboard"
}, },
new NavItem() new NavItem()
{
Id = 2,
Description = "Transactions",
Title = "Transactions",
Icon = "bxs-cart",
Children = new List<NavItem>
{ {
Id = 2, new NavItem()
Description = "Customers", {
Icon = "bx-users", Id = 2.1,
Link = "customers", Title = "Sales",
Title = "Customers" },
new NavItem()
{
Id = 2.2,
Title = "Cancelled Sales",
},
new NavItem()
{
Id = 2.3,
Title = "Statistics",
},
},
}, },
new NavItem() new NavItem()
{ {
Id = 3, Id = 3,
Description = "Employees",
Icon = "bx-users",
Link = "employees",
Title = "Employees"
},
new NavItem()
{
Id = 4,
Description = "Products", Description = "Products",
Icon = "bx-box", Icon = "bx-box",
Link = "",
Title = "Products", Title = "Products",
Children = new List<NavItem> Children = new List<NavItem>
{ {
new NavItem new NavItem
{ {
Id = 4.1, Id = 3.1,
Description = "Brands",
Title = "Brands",
Link = "",
},
new NavItem
{
Id = 3.2,
Description = "Category",
Title = "Category",
Link = "",
},
new NavItem
{
Id = 3.3,
Description = "Inventory", Description = "Inventory",
Title = "Inventory" Title = "Inventory",
Link = "",
}, },
new NavItem new NavItem
{ {
Id = 4.2, Id = 3.4,
Description = "Inventory", Description = "Inventory",
Title = "Bulk Price Changes" Title = "Bulk Price Changes",
Link = "",
}, },
new NavItem new NavItem
{ {
Id = 4.3, Id = 3.5,
Description = "Inventory", Description = "Inventory",
Title = "Products Statistics", Title = "Products Statistics",
Icon = "bx-detail" Link = "",
} }
} }
}, },
};
new NavItem()
{
Id = 4,
Description = "Customers",
Icon = "bxs-user",
Link = "customers",
Title = "Customers"
},
new NavItem()
{
Id = 5,
Description = "Employees",
Icon = "bxs-user-account",
Link = "employees",
Title = "Employees"
},
new NavItem()
{
Id = 6,
Description = "Warehouse Management",
Icon = "bxs-factory",
Title = "Warehouse Management",
Children = new List<NavItem> {
new NavItem(){
Id = 6.1,
Description = "Item Inventory for the warehouse",
Title = "Inventory",
Link = "",
},
},
},
};
var uniqueIds = new HashSet<double>(); var uniqueIds = new HashSet<double>();

28
Client/Pages/Dashboard/Dashboard.razor

@ -1,32 +1,10 @@
@page "/" @using Biskilog_Accounting.Client.Pages.Dashboard.Elements;
@page "/"
<div class="container-xxl flex-grow-1 container-p-y"> <div class="container-xxl flex-grow-1 container-p-y">
<div class="row"> <div class="row">
<div class="col-lg-8 mb-4 order-0"> <div class="col-lg-8 mb-4 order-0">
<div class="card"> <WelcomeCard CurrentTradeSales="@CurrentTradeSale" PreviousTradeSales="@PreviousTradeSale" Username="@username"/>
<div class="d-flex align-items-end row">
<div class="col-sm-7">
<div class="card-body">
<h5 class="card-title text-primary">Congratulations John! 🎉</h5>
<p class="mb-4">
You have done <span class="fw-bold">72%</span> more sales today. Check your new badge in
your profile.
</p>
<a href="javascript:;" class="btn btn-sm btn-outline-primary">View Badges</a>
</div>
</div>
<div class="col-sm-5 text-center text-sm-left">
<div class="card-body pb-0 px-0 px-md-4">
<img src="../assets/img/illustrations/man-with-laptop-light.png"
height="140"
alt="View Badge User"
data-app-dark-img="illustrations/man-with-laptop-dark.png"
data-app-light-img="illustrations/man-with-laptop-light.png" />
</div>
</div>
</div>
</div>
</div> </div>
<div class="col-lg-4 col-md-4 order-1"> <div class="col-lg-4 col-md-4 order-1">
<div class="row"> <div class="row">

19
Client/Pages/Dashboard/Dashboard.razor.cs

@ -0,0 +1,19 @@
using Biskilog_Accounting.Shared.Interfaces;
namespace Biskilog_Accounting.Client.Pages.Dashboard
{
public partial class Dashboard
{
private readonly ITokenService m_tokenService;
private double CurrentTradeSale = 7000;
private double PreviousTradeSale = 2000.80;
private string username { get; set; }
public Dashboard() { }
public Dashboard(ITokenService a_tokenService) => m_tokenService = a_tokenService;
protected override void OnInitialized()
{
username = "username";
base.OnInitialized();
}
}
}

25
Client/Pages/Dashboard/Elements/WelcomeCard.razor

@ -0,0 +1,25 @@
@using Biskilog_Accounting.Shared.Interfaces;
@inject ICalculator m_calculator;
<div class="card">
<div class="d-flex align-items-end row">
<div class="col-sm-7">
<div class="card-body">
<h5 class="card-title text-primary">@(CurrentTradeSales > PreviousTradeSales ? "Congratulations 🎉" : "Tough shift there") @Username!</h5>
<p class="mb-4">
@m_remarks
</p>
<a href="javascript:;" class="btn btn-sm btn-outline-primary">View Trade Summary</a>
</div>
</div>
<div class="col-sm-5 text-center text-sm-left">
<div class="card-body pb-0 px-0 px-md-4">
<img src="../assets/img/illustrations/man-with-laptop-light.png"
height="140"
alt="View Badge User"
data-app-dark-img="illustrations/man-with-laptop-dark.png"
data-app-light-img="illustrations/man-with-laptop-light.png" />
</div>
</div>
</div>
</div>

40
Client/Pages/Dashboard/Elements/WelcomeCard.razor.cs

@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Components;
namespace Biskilog_Accounting.Client.Pages.Dashboard.Elements
{
public partial class WelcomeCard
{
[Parameter]
public string Username { get; set; } = string.Empty;
[Parameter]
public double CurrentTradeSales { get; set; } = 0;
[Parameter]
public double PreviousTradeSales { get; set; } = 0;
private string m_remarks { get; set; } = "";
protected override void OnInitialized()
{
CalculateStatistic();
base.OnInitialized();
}
private void CalculateStatistic()
{
if (CurrentTradeSales > PreviousTradeSales)
{
double change = (CurrentTradeSales / (CurrentTradeSales + PreviousTradeSales)) * 100;
string changePercent = change.ToString("0.00") + "%";
m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, {changePercent} more than the previous trade sales";
}
else if (PreviousTradeSales > CurrentTradeSales) {
double change = (CurrentTradeSales / (CurrentTradeSales + PreviousTradeSales)) * -100;
string changePercent = change.ToString("0.00") + "%";
m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, {changePercent} less than the previous trade sales";
} else {
m_remarks = $"You made a total of {m_calculator.FormatMoneyWithCurrency(CurrentTradeSales)} in the current trade, same as the previous trade sales";
}
}
}
}

6
Client/Program.cs

@ -1,4 +1,7 @@
using Biskilog_Accounting.Client; using Biskilog_Accounting.Client;
using Biskilog_Accounting.ServiceRepo;
using Biskilog_Accounting.Shared.Interfaces;
using Biskilog_Accounting.Shared.ServiceRepo;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
@ -11,4 +14,7 @@ builder.Services.AddHttpClient("Biskilog_Accounting.ServerAPI", client => client
// Supply HttpClient instances that include access tokens when making requests to the server project // Supply HttpClient instances that include access tokens when making requests to the server project
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("Biskilog_Accounting.ServerAPI")); builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("Biskilog_Accounting.ServerAPI"));
builder.Services.AddScoped<ICalculator, CalculatorService>();
builder.Services.AddScoped<ITokenService, TokenService>();
await builder.Build().RunAsync(); await builder.Build().RunAsync();

1
Server/Biskilog Accounting.Server.csproj

@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.5" />
<PackageReference Include="BCrypt.Net" Version="0.1.0" /> <PackageReference Include="BCrypt.Net" Version="0.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.5" />

1
Shared/Biskilog Accounting.Shared.csproj

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
<PackageReference Include="EntityFramework" Version="6.4.4" /> <PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />

16
Shared/Interfaces/ICalculator.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Biskilog_Accounting.Shared.Interfaces
{
public interface ICalculator
{
double CalculatePercentage();
string FormatMoneyWithCurrency(double a_amount);
NumberFormatInfo GetCurrencyCode();
}
}

39
Shared/ServiceRepo/CalculatorService.cs

@ -0,0 +1,39 @@
using Biskilog_Accounting.Shared.Interfaces;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Biskilog_Accounting.Shared.ServiceRepo
{
public class CalculatorService : ICalculator
{
public double CalculatePercentage()
{
throw new NotImplementedException();
}
public string FormatMoneyWithCurrency(double a_amount)
{
return string.Format(GetCurrencyCode(), "{0:C2}", a_amount);
}
public NumberFormatInfo GetCurrencyCode()
{
//TODO have a better implementation
// Specify the locale for Ghana
string locale = "en-GH";
// Get the NumberFormatInfo for the specified locale
NumberFormatInfo numberFormatInfo = new CultureInfo(locale).NumberFormat;
// Set the currency symbol to Ghanaian cedi
numberFormatInfo.CurrencySymbol = "GH₵";
return numberFormatInfo;
}
}
}

4
Shared/ServiceRepo/TokenService.cs

@ -12,9 +12,11 @@ namespace Biskilog_Accounting.ServiceRepo
public class TokenService : ITokenService public class TokenService : ITokenService
{ {
private IConfiguration m_configuration { get; } private IConfiguration m_configuration { get; }
public TokenService(IConfiguration a_configuration) private readonly Blazored.SessionStorage.ISessionStorageService m_sessionStorage;
public TokenService(IConfiguration a_configuration, Blazored.SessionStorage.ISessionStorageService sessionStorage)
{ {
m_configuration = a_configuration; m_configuration = a_configuration;
m_sessionStorage = sessionStorage;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save