Benjamin Arhen
2 years ago
9 changed files with 14656 additions and 13622 deletions
@ -0,0 +1,29 @@ |
|||||
|
@using Biskilog_Accounting.Client.Models; |
||||
|
@if (Item.Children.Count == 0) |
||||
|
{ |
||||
|
<li class="menu-item @(Item.Id == ActiveId ? "active":"")" @onclick="(() => ItemClick(Item.Id))"> |
||||
|
<a href="@Item.Link" class="menu-link"> |
||||
|
<i class="menu-icon tf-icons bx @Item.Icon"></i> |
||||
|
<div data-i18n="Analytics">@Item.Title</div> |
||||
|
</a> |
||||
|
</li> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<li class="menu-item @m_expand @(Item.Children.Any(a => a.Id == ActiveId) ? "active":"")" @onclick="Toggle"> |
||||
|
<a href="javascript:void(0);" class="menu-link menu-toggle"> |
||||
|
<i class="menu-icon tf-icons bx @Item.Icon"></i> |
||||
|
<div data-i18n="Form Elements">@Item.Title</div> |
||||
|
</a> |
||||
|
<ul class="menu-sub"> |
||||
|
@foreach (NavItem navItem in Item.Children) |
||||
|
{ |
||||
|
<li class="menu-item @(navItem.Id == ActiveId ? "active":"")" @onclick:stopPropagation="true" @onclick="(() => ItemClick(navItem.Id))"> |
||||
|
<a href="@navItem.Link" class="menu-link"> |
||||
|
<div data-i18n="Basic Inputs">@navItem.Title</div> |
||||
|
</a> |
||||
|
</li> |
||||
|
} |
||||
|
</ul> |
||||
|
</li> |
||||
|
} |
@ -0,0 +1,45 @@ |
|||||
|
using Biskilog_Accounting.Client.Models; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Biskilog_Accounting.Client.Elements |
||||
|
{ |
||||
|
public partial class MenuItem |
||||
|
{ |
||||
|
[Parameter] |
||||
|
public NavItem Item { get; set; } |
||||
|
[Parameter] |
||||
|
public double ActiveId { get; set; } |
||||
|
[Parameter] |
||||
|
public EventCallback<double> ActiveChanged { get; set; } |
||||
|
private string m_expand { get; set; } = string.Empty; |
||||
|
|
||||
|
protected override void OnParametersSet() |
||||
|
{ |
||||
|
//Collapse expanded parents if none of its child is active
|
||||
|
if (!Item.Children.Any(i => i.Id == ActiveId)) |
||||
|
{ |
||||
|
m_expand = string.Empty; |
||||
|
} |
||||
|
base.OnParametersSet(); |
||||
|
} |
||||
|
private void Toggle() |
||||
|
{ |
||||
|
if (String.IsNullOrEmpty(m_expand)) |
||||
|
{ |
||||
|
m_expand = "menu-item-animating open"; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
m_expand = ""; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void ItemClick(double a_id) |
||||
|
{ |
||||
|
ActiveId = a_id; |
||||
|
ActiveChanged.InvokeAsync(a_id); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,111 @@ |
|||||
|
namespace Biskilog_Accounting.Client.Models |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Structure of the sidebar navigation menu items
|
||||
|
/// </summary>
|
||||
|
public class NavItem |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The unique id of the menu item
|
||||
|
/// </summary>
|
||||
|
public double Id { get; set; } |
||||
|
/// <summary>
|
||||
|
/// The title of the menu item to display
|
||||
|
/// </summary>
|
||||
|
public string Title { get; set; } = string.Empty; |
||||
|
/// <summary>
|
||||
|
/// The description of the menu item or description of the content of the page
|
||||
|
/// </summary>
|
||||
|
public string Description { get; set; } = string.Empty; |
||||
|
/// <summary>
|
||||
|
/// The link to open the specified page tied to the menu item
|
||||
|
/// </summary>
|
||||
|
public string Link { get; set; } = string.Empty; |
||||
|
/// <summary>
|
||||
|
/// The icon of the menu item
|
||||
|
/// </summary>
|
||||
|
public string Icon { get; set; } = string.Empty; |
||||
|
/// <summary>
|
||||
|
/// Children or sub menu item
|
||||
|
/// </summary>
|
||||
|
public List<NavItem> Children { get; set; } = new List<NavItem>(); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// Contains the list of menu Items
|
||||
|
/// </summary>
|
||||
|
public static class Menu |
||||
|
{ |
||||
|
public static IEnumerable<NavItem> MenuList() |
||||
|
{ |
||||
|
var menuItems = new List<NavItem>{ |
||||
|
new NavItem() |
||||
|
{ |
||||
|
Id = 1, |
||||
|
Description = "Analytics page", |
||||
|
Icon = "bx-home-circle", |
||||
|
Link = "", |
||||
|
Title = "Dashboard" |
||||
|
}, |
||||
|
new NavItem() |
||||
|
{ |
||||
|
Id = 2, |
||||
|
Description = "Customers", |
||||
|
Icon = "bx-users", |
||||
|
Link = "customers", |
||||
|
Title = "Customers" |
||||
|
}, |
||||
|
new NavItem() |
||||
|
{ |
||||
|
Id = 3, |
||||
|
Description = "Employees", |
||||
|
Icon = "bx-users", |
||||
|
Link = "employees", |
||||
|
Title = "Employees" |
||||
|
}, |
||||
|
new NavItem() |
||||
|
{ |
||||
|
Id = 4, |
||||
|
Description = "Products", |
||||
|
Icon = "bx-box", |
||||
|
Link = "", |
||||
|
Title = "Products", |
||||
|
Children = new List<NavItem> |
||||
|
{ |
||||
|
new NavItem |
||||
|
{ |
||||
|
Id = 4.1, |
||||
|
Description = "Inventory", |
||||
|
Title = "Inventory" |
||||
|
}, |
||||
|
new NavItem |
||||
|
{ |
||||
|
Id = 4.2, |
||||
|
Description = "Inventory", |
||||
|
Title = "Bulk Price Changes" |
||||
|
}, |
||||
|
new NavItem |
||||
|
{ |
||||
|
Id = 4.3, |
||||
|
Description = "Inventory", |
||||
|
Title = "Products Statistics", |
||||
|
Icon = "bx-detail" |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
var uniqueIds = new HashSet<double>(); |
||||
|
|
||||
|
//Validates list to check if there are no duplicate Ids
|
||||
|
foreach (var menuItem in menuItems) |
||||
|
{ |
||||
|
if (!uniqueIds.Add(menuItem.Id)) |
||||
|
{ |
||||
|
throw new Exception($"Duplicate Id found: {menuItem.Id}"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return menuItems; |
||||
|
} |
||||
|
} |
||||
|
} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue