public async Task <List <string> > GetNetworkOnlyUrls(PwaOptions options, HttpContext context)
        {
            var result = new List <string>()
            {
                "/blog/canedit",
                "/page/canedit",
                "/pwa/topnav"
            };

            if (!context.User.Identity.IsAuthenticated)
            {
                //admin pages won't be in the menu anyway so just return empty list
                return(result);
            }

            var rootNode = await _siteMapTreeBuilder.GetTree();

            var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccesor.ActionContext);

            foreach (var navNode in rootNode.Flatten())
            {
                if (await WouldRenderNode(navNode))
                {
                    if (ShouldBeNetworkOnly(navNode))
                    {
                        var url = ResolveUrl(navNode, urlHelper);
                        result.Add(url);
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
        public async Task <IEnumerable <ISiteMapNode> > GetSiteMapNodes(
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var rootNode = await siteMapTreeBuilder.GetTree();

            var mapNodes  = new List <SiteMapNode>();
            var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext);

            foreach (var navNode in rootNode.Flatten())
            {
                if (navNode.ExcludeFromSearchSiteMap)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(navNode.ViewRoles) || navNode.ViewRoles.Contains("All Users"))
                {
                    var url = ResolveUrl(navNode, urlHelper);
                    if (string.IsNullOrEmpty(url))
                    {
                        log.LogWarning("failed to resolve url for node " + navNode.Key + ", skipping this node for sitemap");
                        continue;
                    }

                    if (!url.StartsWith("http"))
                    {
                        log.LogWarning("skipping relative url " + url + ", sitemap urls must be absolute");
                        continue;
                    }

                    if (addedUrls.Contains(url))
                    {
                        continue;
                    }

                    if (navNode is ISiteMapNode)
                    {
                        var smNode = navNode as ISiteMapNode;
                        mapNodes.Add(
                            new SiteMapNode(url)
                        {
                            ChangeFrequency = smNode.ChangeFrequency,
                            LastModified    = smNode.LastModified,
                            Priority        = smNode.Priority
                        }
                            );
                    }
                    else
                    {
                        mapNodes.Add(new SiteMapNode(url));
                    }

                    addedUrls.Add(url);
                }
            }

            return(mapNodes);
        }
Beispiel #3
0
        private TreeNode <NavigationNode> GetCurrentNode(ActionExecutingContext context)
        {
            var result         = _builderService.GetTree();
            var tree           = result.Result;
            var controller     = context.Controller as ControllerBase;
            var controllerName = controller?.ControllerContext.ActionDescriptor.ControllerName;
            var actionName     = controller?.ControllerContext.ActionDescriptor.ActionName;
            var node           = tree.FindByKey($"{controllerName}.{actionName}");

            return(node);
        }
        public async Task <List <ServiceWorkerCacheItem> > GetItems()
        {
            var result   = new List <ServiceWorkerCacheItem>();
            var rootNode = await _siteMapTreeBuilder.GetTree();

            var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccesor.ActionContext);

            foreach (var navNode in rootNode.Flatten())
            {
                bool include = true;
                foreach (var filter in _navigationNodeServiceWorkerFilters)
                {
                    include = await filter.ShouldRenderNode(navNode);
                }

                if (!include)
                {
                    continue;
                }


                if (!await ShouldRenderNode(navNode))
                {
                    continue;
                }

                var url = ResolveUrl(navNode, urlHelper);

                if (string.IsNullOrWhiteSpace(url))
                {
                    continue;
                }

                if (addedUrls.Contains(url))
                {
                    continue;
                }



                result.Add(new ServiceWorkerCacheItem()
                {
                    Url             = url,
                    LastModifiedUtc = navNode.LastModifiedUtc
                });
            }


            return(result);
        }
        public async Task <IViewComponentResult> InvokeAsync(string viewName, string filterName, string startingNodeKey)
        {
            var rootNode = await builder.GetTree();

            var urlHelper             = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext);
            NavigationViewModel model = new NavigationViewModel(
                startingNodeKey,
                filterName,
                Request.HttpContext,
                urlHelper,
                rootNode,
                permissionResolvers,
                nodeFinders,
                prefixProvider.GetPrefix(),
                log);

            //  return View(viewName, model);

            return(View($"/Modules/SimpleFramework.Module.Navigation/Views/Components/Navigation/{viewName}.cshtml", model));
        }