diff --git a/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/HomeAnagrafiche.razor b/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/HomeAnagrafiche.razor index d870782..ab06bc9 100644 --- a/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/HomeAnagrafiche.razor +++ b/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/HomeAnagrafiche.razor @@ -1,15 +1,18 @@ @page "/anagrafiche" + @using Microsoft.EntityFrameworkCore @using TecniStamp.Components.Widget -@using TecniStamp.Domain +@using TecniStamp.Model.Common @using TecniStamp.Utils + +
@foreach (var item in TileList) { - + }
@@ -17,23 +20,41 @@ @code { - public List TileList { get; set; } = new(); + public List TileList { get; set; } = new(); + public List BreadcrumbList { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var roleId = await MembershipUtils.GetRoleId(_auth); - var parentSection = await _managerService.SezioneService.RicercaPer(x => x.Nome == "Anagrafiche"); - var subSection = (await _managerService.SezioneService.RicercaQueryable(x => x.ParentId == parentSection.Id)) - .Select(x => x.Id); - var permissionList = (await _managerService.PermissionService.RicercaQueryable( - x => x.RuoloId == roleId && subSection.Contains(x.Feature.Sezione.Id), - includi: x => x.Include(y => y.Feature).ThenInclude(z => z.Sezione), - ordinamento: x => x.OrderBy(y => y.Feature.Sezione.Ordinamento))); + var parentSection = await _managerService.SezioneService + .RicercaPer(x => x.Nome == "Anagrafiche"); + + var subSectionIds = await (await _managerService.SezioneService + .RicercaQueryable(x => x.ParentId == parentSection.Id)) + .Select(x => x.Id) + .ToListAsync(); + + var permissionList = await (await _managerService.PermissionService + .RicercaQueryable( + x => x.RuoloId == roleId && + subSectionIds.Contains(x.Feature.Sezione.Id), + includi: x => x + .Include(y => y.Feature) + .ThenInclude(z => z.Sezione) + )) + .ToListAsync(); + TileList = permissionList - .Select(x => x.Feature.Sezione).Distinct().ToList(); + .Select(x => x.Feature.Sezione) + .DistinctBy(x => x.Id) + .OrderBy(x => x.Ordinamento) + .Select(x => new TileViewModel(x)) + .ToList(); + + BreadcrumbList = BreadcrumbUtils.BuildBreadcrumb(parentSection); } } \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/Ruoli.razor b/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/Ruoli.razor new file mode 100644 index 0000000..5e136b3 --- /dev/null +++ b/TecniStamp/TecniStamp/Components/Pages/Anagrafiche/Ruoli.razor @@ -0,0 +1,7 @@ +@page "/anagrafiche/ruoli" + +@code { + + + +} diff --git a/TecniStamp/TecniStamp/Components/Pages/Home.razor b/TecniStamp/TecniStamp/Components/Pages/Home.razor index 5f389c4..16fe27c 100644 --- a/TecniStamp/TecniStamp/Components/Pages/Home.razor +++ b/TecniStamp/TecniStamp/Components/Pages/Home.razor @@ -4,40 +4,51 @@ @using Microsoft.AspNetCore.Authorization @using Microsoft.EntityFrameworkCore @using TecniStamp.Components.Widget -@using TecniStamp.Domain +@using TecniStamp.Model.Common @using TecniStamp.Utils -
-
- -
-
+
@foreach (var item in TileList) { - + }
@code { - public List TileList { get; set; } = new(); + public List TileList { get; set; } = new(); + public List BreadcrumbList { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var roleId = await MembershipUtils.GetRoleId(_auth); - TileList = (await _managerService.PermissionService.RicercaQueryable( - x => x.RuoloId == roleId && - (x.Feature.Sezione.ParentId == null || x.Feature.Sezione.Parent.ParentId == null), - includi:x => x.Include(y => y.Feature).ThenInclude(z => z.Sezione), - ordinamento:x => x.OrderBy(y => y.Feature.Sezione.Ordinamento))) - .Select(x => x.Feature.Sezione.Parent ?? x.Feature.Sezione).Distinct().ToList(); + + var sezioniList = await (await _managerService.PermissionService + .RicercaQueryable( + x => x.RuoloId == roleId && + (x.Feature.Sezione.ParentId == null || + x.Feature.Sezione.Parent.ParentId == null), + includi: x => x + .Include(y => y.Feature) + .ThenInclude(z => z.Sezione) + .ThenInclude(s => s.Parent) + )) + .ToListAsync(); + + TileList = sezioniList + .Select(x => x.Feature.Sezione.Parent ?? x.Feature.Sezione) + .DistinctBy(x => x.Id) + .OrderBy(x => x.Ordinamento) + .Select(x => new TileViewModel(x)) + .ToList(); + + BreadcrumbList = BreadcrumbUtils.BuildBreadcrumb(null); } } \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Components/Widget/Breadcrumb.razor b/TecniStamp/TecniStamp/Components/Widget/Breadcrumb.razor new file mode 100644 index 0000000..fed5bee --- /dev/null +++ b/TecniStamp/TecniStamp/Components/Widget/Breadcrumb.razor @@ -0,0 +1,26 @@ +@using TecniStamp.Model.Common +
+
+ +
+
+@code { + [Parameter, EditorRequired] + public IReadOnlyList Items { get; set; } = []; +} \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Components/Widget/HomeTile.razor b/TecniStamp/TecniStamp/Components/Widget/HomeTile.razor index 6f60eee..4182d5a 100644 --- a/TecniStamp/TecniStamp/Components/Widget/HomeTile.razor +++ b/TecniStamp/TecniStamp/Components/Widget/HomeTile.razor @@ -1,20 +1,18 @@ -
+@using TecniStamp.Model.Common +
@code { - [Parameter] public string Url { get; set; } - [Parameter] public bool Blank { get; set; } = false; - [Parameter] public string Icon { get; set; } - [Parameter] public string Text { get; set; } + [Parameter] public TileViewModel Model { get; set; } = new(); } \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Model/Common/BreadcrumbViewModel.cs b/TecniStamp/TecniStamp/Model/Common/BreadcrumbViewModel.cs new file mode 100644 index 0000000..34c84e6 --- /dev/null +++ b/TecniStamp/TecniStamp/Model/Common/BreadcrumbViewModel.cs @@ -0,0 +1,8 @@ +namespace TecniStamp.Model.Common; + +public class BreadcrumbViewModel +{ + public string Text { get; set; } + public string? Url { get; set; } + public bool IsActive { get; set; } +} \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Model/Common/TileViewModel.cs b/TecniStamp/TecniStamp/Model/Common/TileViewModel.cs new file mode 100644 index 0000000..14ea06b --- /dev/null +++ b/TecniStamp/TecniStamp/Model/Common/TileViewModel.cs @@ -0,0 +1,27 @@ +using TecniStamp.Domain; + +namespace TecniStamp.Model.Common; + +public class TileViewModel +{ + public Guid Id { get; set; } + public string Url { get; set; } + public bool Blank { get; set; } = false; + public string Icon { get; set; } + public string Text { get; set; } + public int Ordinamento { get; set; } + + public TileViewModel() + { + + } + + public TileViewModel(Sezione model) + { + Id = model.Id; + Url = model.Url; + Blank = model.Blank; + Icon = model.Icona; + Text = model.Nome; + } +} \ No newline at end of file diff --git a/TecniStamp/TecniStamp/Utils/BreadcrumbUtils.cs b/TecniStamp/TecniStamp/Utils/BreadcrumbUtils.cs new file mode 100644 index 0000000..64e5a79 --- /dev/null +++ b/TecniStamp/TecniStamp/Utils/BreadcrumbUtils.cs @@ -0,0 +1,45 @@ +using TecniStamp.Domain; +using TecniStamp.Model.Common; + +namespace TecniStamp.Utils; + +public static class BreadcrumbUtils +{ + public static List BuildBreadcrumb(Sezione sezione) + { + var stack = new Stack(); + var current = sezione; + + while (current != null) + { + stack.Push(current); + current = current.Parent; + } + + var breadcrumb = new List + { + new() + { + Text = "Home", + Url = "/", + IsActive = false + } + }; + + while (stack.Any()) + { + var s = stack.Pop(); + breadcrumb.Add(new BreadcrumbViewModel + { + Text = s.Nome, + Url = s.Url, + IsActive = false + }); + } + + breadcrumb.Last().IsActive = true; + breadcrumb.Last().Url = null; + + return breadcrumb; + } +} \ No newline at end of file