Пример #1
0
        public string BuildRouteApiUrl(string language, bool?hasRouteError)
        {
            string baseUrl = $"{_navigationManager.BaseUri}/data/routes";

            string relativeUrl = _navigationManager.ToBaseRelativePath(_navigationManager.Uri);

            //Incorrect url
            if (hasRouteError.HasValue && hasRouteError.Value)
            {
                return($"{baseUrl}/error/{language}.json");
            }

            IBlazorItem rootItem = _blazorItemsService.GetBlazorItemRootMock(language);

            if (rootItem.GetItSelfAndDescendants().Any(item => item.Url == "/" + relativeUrl) || relativeUrl == "")
            {
                if (relativeUrl.Length <= language.Length)
                {
                    return($"{baseUrl}/{language}.json");
                }

                return($"{baseUrl}{relativeUrl.Substring(language.Length)}/{language}.json");
            }


            return($"{baseUrl}/error/{language}.json");
        }
Пример #2
0
 private NavigationItem CreateNavigationItem(IBlazorItem item)
 {
     return(new NavigationItem
     {
         Item = item,
         Url = item.Url,
         Children = item.HasChildren ? GetChildNavigationItems(item) : null
     });
 }
Пример #3
0
        public RouterDataRoot CreateRoutes(string language = "en")
        {
            IBlazorItem rootItem = GetBlazorItemRootMock();

            RouterDataRoot routesData = new RouterDataRoot()
            {
                //Home
                Routes = new List <RouterData>()
                {
                    new RouterData()
                    {
                        Path = "/{Language}",
                        Page = PageComponent
                    }
                }
            };

            //Rest of menu items
            foreach (IBlazorItem item in rootItem.Children)
            {
                routesData.Routes.Add(new RouterData()
                {
                    Path     = "/{Language}" + item.Url.Substring(language.Length + 1),
                    Page     = PageComponent,
                    Children = item.HasChildren ? GetChildren(item) : null
                });
            }


            return(routesData);



            List <RouterData>?GetChildren(IBlazorItem blazorItem)
            {
                List <RouterData> children = new List <RouterData>();

                if (!blazorItem.HasChildren)
                {
                    return(null);
                }

                foreach (IBlazorItem child in blazorItem.Children)
                {
                    children.Add(new RouterData()
                    {
                        Path     = child.Url.Substring(child.Url.LastIndexOf('/')),
                        Page     = PageComponent,
                        Children = child.HasChildren ? GetChildren(child) : null
                    });
                }

                return(children);
            }
        }
Пример #4
0
        public (bool IsCurrentUrl, string CurrentUrl)? UrlIsCurrent()
        {
            string relativeUrl = _navigationManager.ToBaseRelativePath(_navigationManager.Uri);

            if (string.IsNullOrWhiteSpace(_blazorStateMachine.CurrentRoute?.ItemLanguage))
            {
                return(false, $"/{relativeUrl}");
            }

            IBlazorItem rootItem = _blazorItemsService.GetBlazorItemRootMock(_blazorStateMachine?.CurrentRoute?.ItemLanguage);

            return(_blazorStateMachine?.CurrentRoute != null && rootItem.GetItSelfAndDescendants().Any(item => item.Url == "/" + relativeUrl && item.Id == _blazorStateMachine.CurrentRoute.Id)
              ? (true, $"/{relativeUrl}")
              : (false, $"/{relativeUrl}"));
        }
Пример #5
0
        public Task <List <NavigationItem> > GetMenu()
        {
            IBlazorItem rootItem = _blazorItemsService.GetBlazorItemRootMock(_blazorStateMachine.Language);

            List <NavigationItem> navigationItems = new List <NavigationItem>();


            if (this.IncludeInNavigation(rootItem))
            {
                navigationItems.Add(new NavigationItem()
                {
                    Item     = rootItem,
                    Url      = rootItem.Url,
                    Children = null
                });
            }

            navigationItems.AddRange(from item in rootItem.Children where item != null select CreateNavigationItem(item));


            return(Task.FromResult <List <NavigationItem> >(navigationItems));
        }
        public static IEnumerable <IBlazorItem> GetItSelfAndDescendants(this IBlazorItem thisItem)
        {
            yield return(thisItem);

            if (!thisItem.HasChildren)
            {
                yield break;
            }

            foreach (IBlazorItem child in thisItem.Children)
            {
                yield return(child);

                if (!child.HasChildren)
                {
                    continue;
                }

                foreach (IBlazorItem i in GetItSelfAndDescendants(child))
                {
                    yield return(i);
                }
            }
        }
 public static bool GetBoolValue(this IBlazorItem thisItem, string fieldName, bool defaultValue)
 {
     return(thisItem.Fields.Checkbox(fieldName) == null ? defaultValue : thisItem.Fields.Checkbox(fieldName).Value);
 }
Пример #8
0
 private List <NavigationItem> GetChildNavigationItems(IBlazorItem blazorItem)
 {
     return(!blazorItem.HasChildren ? new List <NavigationItem>() : blazorItem.Children.Where(child => this.IncludeInNavigation(child)).Select(this.CreateNavigationItem).ToList());
 }
Пример #9
0
 private bool IncludeInNavigation(IBlazorItem blazorItem, bool forceShowInMenu = false)
 {
     return(forceShowInMenu || blazorItem.GetBoolValue(Constants.Fields.ShowInNavigation, false));
 }