using BlueWest.Views.Controllers; using BlueWest.Views.Controllers.Data; using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace BlueWest.Views.Utils; internal class LayoutCache { #region Route Tree private static readonly RouteRecord Root = new RouteRecord( RootKeyName, RootLocation, nameof(HomeController), new List() { new RouteRecord( DataKeyName, DataLocation, nameof(DataController), new List() { new RouteRecord( CompaniesKeyName, CompaniesLocation, nameof(CompaniesController), new List() ), new RouteRecord( CountriesKeyName, CountriesLocation, nameof(CountriesController), new List() ), new RouteRecord( CurrenciesKeyName, CurrenciesLocation, nameof(CurrenciesController), new List() ), new RouteRecord( BanksKeyName, BanksLocation, nameof(BanksController), new List() ), new RouteRecord( DataUsersKeyName, DataUsersLocation, nameof(DataUsersController), new List() ), }, ViewType.Data ), new RouteRecord( SystemKeyName, SystemRouteLocation, nameof(SystemController), new List() { new RouteRecord( RolesKeyName, RolesLocation, nameof(RolesController), new List() ), new RouteRecord( ApplicationUsersKeyName, ApplicationUsersLocation, nameof(ApplicationUsersController), new List() ), new RouteRecord( LogsKeyName, LogsLocation, nameof(LogsController), new List() ) }, ViewType.System ), new RouteRecord( JobsKeyName, JobsRouteLocation, nameof(JobsController), new List(), ViewType.Jobs ), }, ViewType.Root); #endregion Route Tree #region Routing Utils internal static readonly RouteRecord SystemRoute = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.System)!; internal static readonly RouteRecord DataRoute = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Data)!; internal static readonly RouteRecord JobRoute = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Jobs)!; internal static readonly RouteRecord ProfileRoute = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Profile)!; #endregion Routing Utils #region Internal Menus internal static List GetDefaultFooterMenu(ViewDataDictionary dictionary) { var location = GetLocation(dictionary); var menu = LayoutCache .Root .Children; if (dictionary[FooterMenuId] is List footerMenu) { menu = footerMenu; } return menu .Select(x => { if (Translation[x.routeKey].ContainsKey(location)) { return new RouteView(Translation[x.routeKey][location], location); } return new RouteView(Translation[x.routeKey][DefaultCultureName], x.location); }) .ToList(); } internal static List GetDefaultHeaderMenu(ViewDataDictionary dictionary) { var location = GetLocation(dictionary); var menu = LayoutCache .Root .Children; if (dictionary[HeaderMenuId] is List footerMenu) { menu = footerMenu; } return menu .Select(x => { if (Translation[x.routeKey].ContainsKey(location)) { return new RouteView(Translation[x.routeKey][location], x.Location); } return new RouteView(Translation[x.routeKey][DefaultCultureName], x.location); }) .ToList(); } internal static string GetLocation(ViewDataDictionary dictionary) { return (dictionary[LanguageViewStorage] as string)!; } #endregion Internal Menus }