36 lines
1,023 B
C#
36 lines
1,023 B
C#
using Microsoft.AspNetCore.Mvc;
|
|
using PlanTempus.Application.Features.Menu.Services;
|
|
using PlanTempus.Application.Features.Menu;
|
|
using PlanTempus.Application.Features.Menu.Models;
|
|
|
|
namespace PlanTempus.Application.Features.Menu;
|
|
|
|
/// <summary>
|
|
/// ViewComponent for rendering the side menu based on user role.
|
|
/// </summary>
|
|
public class SideMenuViewComponent : ViewComponent
|
|
{
|
|
private readonly IMenuService _menuService;
|
|
|
|
public SideMenuViewComponent(IMenuService menuService)
|
|
{
|
|
_menuService = menuService;
|
|
}
|
|
|
|
public IViewComponentResult Invoke(UserRole? role = null)
|
|
{
|
|
// Default to Admin for demo (in real app, get from auth)
|
|
var userRole = role ?? UserRole.Admin;
|
|
|
|
var currentUrl = HttpContext.Request.Path.Value;
|
|
var groups = _menuService.GetMenuForRole(userRole, currentUrl);
|
|
|
|
var viewModel = new SideMenuViewModel
|
|
{
|
|
Groups = groups,
|
|
CurrentUserRole = userRole
|
|
};
|
|
|
|
return View(viewModel);
|
|
}
|
|
}
|