2022-10-27 20:13:02 +03:00
|
|
|
using System.Diagnostics;
|
2022-10-30 19:48:24 +03:00
|
|
|
using CodeLiturgy.Views.Controllers;
|
|
|
|
using CodeLiturgy.Views.Languages;
|
2022-09-26 04:05:23 +03:00
|
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
|
|
|
2022-10-30 19:48:24 +03:00
|
|
|
namespace CodeLiturgy.Views.Utils;
|
2022-09-26 04:05:23 +03:00
|
|
|
|
|
|
|
internal class LayoutCache
|
|
|
|
{
|
|
|
|
#region Route Tree
|
|
|
|
|
2022-10-27 20:13:02 +03:00
|
|
|
private static readonly RouteRecord NonLoggedInRoot = new RouteRecord(
|
2022-11-17 00:17:44 +03:00
|
|
|
"Login",
|
2022-10-27 20:13:02 +03:00
|
|
|
AuthLoginRoute,
|
|
|
|
AuthLoginKeyName,
|
|
|
|
nameof(AuthController), new List<RouteRecord>());
|
|
|
|
|
2022-11-17 00:17:44 +03:00
|
|
|
|
|
|
|
internal static readonly RouteRecord Root = new RouteRecord(
|
|
|
|
"Code Liturgy - Dashboard",
|
2022-09-26 04:05:23 +03:00
|
|
|
RootKeyName,
|
|
|
|
RootLocation,
|
|
|
|
nameof(HomeController),
|
2022-11-17 00:17:44 +03:00
|
|
|
new List<RouteRecord>()
|
|
|
|
{
|
|
|
|
new RouteRecord("Environments", EnvironmentsKeyName, EnvironmentsRouteLocation, nameof(EnvironmentsPageController), new List<RouteRecord>(), ViewType.Environments)
|
|
|
|
|
|
|
|
}, ViewType.Root);
|
2022-09-26 04:05:23 +03:00
|
|
|
|
|
|
|
#endregion Route Tree
|
|
|
|
|
|
|
|
#region Routing Utils
|
|
|
|
|
|
|
|
internal static readonly RouteRecord SystemRoute =
|
|
|
|
Root.Children.FirstOrDefault(x => x.ViewType == ViewType.System)!;
|
|
|
|
|
2022-10-27 20:13:02 +03:00
|
|
|
internal static readonly RouteRecord AccountRouteRecord =
|
|
|
|
Root.Children.FirstOrDefault(x => x.ViewType == ViewType.Account)!;
|
2022-09-26 04:05:23 +03:00
|
|
|
|
|
|
|
#endregion Routing Utils
|
|
|
|
|
|
|
|
#region Internal Menus
|
|
|
|
|
2022-11-17 00:17:44 +03:00
|
|
|
|
|
|
|
internal static List<Url> GetDefaultHeaderMenu(ViewDataDictionary dictionary, bool userAuthenticated = false)
|
2022-09-26 04:05:23 +03:00
|
|
|
{
|
2022-11-17 00:17:44 +03:00
|
|
|
var menuToShow = new List<Url>();
|
2022-09-26 04:05:23 +03:00
|
|
|
|
2022-11-17 00:17:44 +03:00
|
|
|
menuToShow.Add(Root.ToUrl());
|
|
|
|
|
|
|
|
if (!userAuthenticated)
|
2022-09-26 04:05:23 +03:00
|
|
|
{
|
2022-11-17 00:17:44 +03:00
|
|
|
return menuToShow;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dictionary[HeaderMenuId] is List<Url> headerMenu)
|
|
|
|
{
|
|
|
|
menuToShow = menuToShow
|
|
|
|
.Concat(headerMenu)
|
|
|
|
.ToList();
|
2022-09-26 04:05:23 +03:00
|
|
|
}
|
|
|
|
|
2022-11-17 00:17:44 +03:00
|
|
|
return menuToShow;
|
2022-09-26 04:05:23 +03:00
|
|
|
}
|
|
|
|
|
2022-11-17 00:17:44 +03:00
|
|
|
|
|
|
|
internal static List<Url> GetDefaultFooterMenu(ViewDataDictionary dictionary, bool userAuthenticated)
|
2022-09-26 04:05:23 +03:00
|
|
|
{
|
2022-11-17 00:17:44 +03:00
|
|
|
var menuToShow = new List<Url>();
|
|
|
|
|
|
|
|
menuToShow.Add(Root.ToUrl());
|
|
|
|
|
2022-10-27 20:13:02 +03:00
|
|
|
if (!userAuthenticated)
|
|
|
|
{
|
|
|
|
return menuToShow;
|
|
|
|
}
|
2022-11-17 00:17:44 +03:00
|
|
|
|
|
|
|
if (dictionary[FooterMenuViewDataId] is List<Url> footerMenu)
|
2022-09-26 04:05:23 +03:00
|
|
|
{
|
2022-11-17 00:17:44 +03:00
|
|
|
menuToShow = menuToShow
|
|
|
|
.Concat(footerMenu)
|
|
|
|
.ToList();
|
2022-09-26 04:05:23 +03:00
|
|
|
}
|
2022-11-17 00:17:44 +03:00
|
|
|
|
|
|
|
return menuToShow;
|
2022-09-26 04:05:23 +03:00
|
|
|
}
|
2022-10-27 20:13:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
[Conditional("DEBUG")]
|
|
|
|
internal static void IsDevMode(ref bool isDebug)
|
|
|
|
{
|
|
|
|
isDebug = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal static string GetUserLanguage(ViewDataDictionary dictionary)
|
2022-09-26 04:05:23 +03:00
|
|
|
{
|
|
|
|
return (dictionary[LanguageViewStorage] as string)!;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion Internal Menus
|
|
|
|
|
|
|
|
}
|