Example #1
0
            private string GetAbsolutePageUrl(PointerPageItem pointer)
            {
                if (pointer == null)
                {
                    return(null);
                }
                var page = _pageService.Get(pointer.EntitySystemId);

                if (page == null)
                {
                    return(null);
                }

                var channelSystemId = pointer.ChannelSystemId != Guid.Empty ? pointer.ChannelSystemId : _routeRequestLookupInfoAccessor.RouteRequestLookupInfo.Channel.SystemId;

                return(_urlService.GetUrl(page, new PageUrlArgs(channelSystemId)
                {
                    AbsoluteUrl = true
                }));
            }
Example #2
0
        private List <ContentLinkModel> GetSubPageLinks(PointerPageItem pointerPageItem, bool showNextLevel)
        {
            var links = new List <ContentLinkModel>();

            foreach (var subPage in _pageService.GetChildPages(pointerPageItem.EntitySystemId).Select(x => new PointerPageItem {
                EntitySystemId = x.SystemId, ChannelSystemId = pointerPageItem.ChannelSystemId
            })
                     .Select(x => new Tuple <PointerPageItem, LinkModel>(x, x.MapTo <LinkModel>())).Where(x => x.Item2?.Href != null))
            {
                var subLinkModel = new ContentLinkModel
                {
                    Name       = subPage.Item2.Text,
                    Url        = subPage.Item2.Href,
                    IsSelected = _selectedStructureId.Contains(subPage.Item1.EntitySystemId)
                };
                if (showNextLevel)
                {
                    subLinkModel.Links = GetSubPageLinks(subPage.Item1, false);
                }
                links.Add(subLinkModel);
            }

            return(links);
        }
Example #3
0
        /// <summary>
        /// Builds model
        /// </summary>
        /// <returns></returns>
        public async Task <NavigationViewModel> BuildAsync()
        {
            var model = new NavigationViewModel();

            SetSelectedPages(_requestModelAccessor.RequestModel.CurrentPageModel, _requestModelAccessor.RequestModel.WebsiteModel.SystemId);
            var megaMenuPages = GetMegaMenuPages();

            foreach (var megaMenuPage in megaMenuPages)
            {
                var linkName = megaMenuPage?.Page?.Localizations.CurrentCulture.Name;
                if (string.IsNullOrEmpty(linkName))
                {
                    continue;
                }
                var contentLinkModel = new ContentLinkModel
                {
                    Name = linkName
                };
                var             categoryModel   = megaMenuPage.GetValue <Guid?>(MegaMenuPageFieldNameConstants.MegaMenuCategory)?.MapTo <CategoryModel>();
                PointerPageItem pointerPageItem = null;
                // If a category is chosen, the link will redirect to the category in the first place
                if (categoryModel != null)
                {
                    if (categoryModel.Category == null || !categoryModel.Category.IsPublished(_channelSystemId))
                    {
                        //Category must be published
                        continue;
                    }
                    contentLinkModel.Url        = _urlService.GetUrl(categoryModel.Category);
                    contentLinkModel.IsSelected = _selectedStructureId.Contains(categoryModel.Category.SystemId);
                }
                else
                {
                    pointerPageItem = megaMenuPage.GetValue <PointerPageItem>(MegaMenuPageFieldNameConstants.MegaMenuPage);
                    var linkModel = pointerPageItem?.MapTo <LinkModel>();
                    if (linkModel == null)
                    {
                        //Page must be active
                        continue;
                    }

                    contentLinkModel.Url        = linkModel.Href;
                    contentLinkModel.IsSelected = _selectedStructureId.Contains(pointerPageItem.EntitySystemId);
                }

                model.ContentLinks.Add(contentLinkModel);

                if (megaMenuPage.GetValue <bool>(MegaMenuPageFieldNameConstants.MegaMenuShowContent))
                {
                    if (megaMenuPage.GetValue <bool>(MegaMenuPageFieldNameConstants.MegaMenuShowSubCategories))
                    {
                        // Show two levels of sub categories/pages
                        contentLinkModel.Links = categoryModel != null?GetSubCategoryLinks(categoryModel, true) : GetSubPageLinks(pointerPageItem, true);
                    }
                    else
                    {
                        // Render mega menu context
                        contentLinkModel.Links = await GetMegaMenuContentAsync(megaMenuPage, categoryModel);
                    }
                }
                if (!contentLinkModel.IsSelected)
                {
                    contentLinkModel.IsSelected = IsChildSelected(contentLinkModel);
                }
            }

            var selectedCount = model.ContentLinks.Count(x => x.IsSelected);

            if (selectedCount <= 1)
            {
                return(model);
            }

            var selectedPagesToClear = model.ContentLinks.Where(x => x.IsSelected).Take(selectedCount - 1);

            foreach (var page in selectedPagesToClear)
            {
                UnSelect(page);
            }
            return(model);
        }