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", EnvironmentsKeyName, EnvironmentsRouteLocation, nameof(EnvironmentsPageController), new List(), ViewType.Environments) }, 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(); menuToShow.Add(Root.ToUrl()); if (!userAuthenticated) { return menuToShow; } 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 }