using System.Diagnostics; using CodeLiturgy.Views.Controllers; using CodeLiturgy.Views.Languages; using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace CodeLiturgy.Views.Utils; internal class LayoutCache { #region Route Tree private static readonly RouteRecord NonLoggedInRoot = new RouteRecord( "Login", AuthLoginRoute, AuthLoginKeyName, nameof(AuthController), new List()); internal static readonly RouteRecord Root = new RouteRecord( "Code Liturgy - Dashboard", RootKeyName, RootLocation, nameof(HomeController), new List() { new RouteRecord("Environments", "envs0", "environments", nameof(EnvironmentsApiController), new List()), new RouteRecord("Standalone Sites", "sites0", "sites", nameof(SitesApiController), new List()), } , 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 AccountRouteRecord = Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Account)!; #endregion Routing Utils #region Internal Menus internal static List GetDefaultHeaderMenu(ViewDataDictionary dictionary, bool userAuthenticated = false) { var menuToShow = new List(); // Add Root URL menuToShow.Add(Root.ToUrl()); if (!userAuthenticated) { return menuToShow; } var rootChildrenUrls = Root.Children.Select(x => x.ToUrl()).ToList(); menuToShow = menuToShow .Concat(rootChildrenUrls) .ToList(); if (dictionary[HeaderMenuId] is List headerMenu) { menuToShow = menuToShow .Concat(headerMenu) .ToList(); } return menuToShow; } internal static List GetDefaultFooterMenu(ViewDataDictionary dictionary, bool userAuthenticated) { var menuToShow = new List(); menuToShow.Add(Root.ToUrl()); if (!userAuthenticated) { return menuToShow; } if (dictionary[FooterMenuViewDataId] is List footerMenu) { menuToShow = menuToShow .Concat(footerMenu) .ToList(); } return menuToShow; } [Conditional("DEBUG")] internal static void IsDevMode(ref bool isDebug) { isDebug = true; } internal static string GetUserLanguage(ViewDataDictionary dictionary) { return (dictionary[LanguageViewStorage] as string)!; } #endregion Internal Menus }