예제 #1
0
        public MenuViewModel Build(IStartPage startPage, AbstractPage currentPage)
        {
            if (startPage == null)
            {
                return(null);
            }

            var model = new MenuViewModel();

            var topLevelItems = startPage.GetChildren()
                                .Where(w => w.IsPage)
                                .OfType <AbstractPage>()
                                .Where(p => p.IsVisible)
                                .OrderBy(o => o.SortOrder);

            var currentPageId = (currentPage?.Id).GetValueOrDefault(0);//currentPage может быть Null, если страница не в структуре сайта

            foreach (var tlitem in topLevelItems)
            {
                var resultBuildMenu = BuildMenu(tlitem, MenuDepth, currentPageId);
                model.Items.Add(new MenuItem
                {
                    Title          = tlitem.Title,
                    Alias          = tlitem.Alias,
                    Href           = tlitem.GetUrl(UrlTransformator),
                    Children       = resultBuildMenu,
                    IsActive       = tlitem.Id == currentPageId,
                    HasActiveChild = resultBuildMenu.Where(w => w.IsActive).Any()
                });
            }

            model.Items = model.Items?.OrderBy(o => o.Order).ToList();

            return(model);
        }
예제 #2
0
        public PathData Find(string path, IStartPage root, ITargetingFilter targetingFilter, IHeadUrlResolver urlResolver)
        {
            path = urlResolver.SanitizeUrl(path);

            var tokens = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length == 0)
            {
                return(new PathData(root, path));
            }

            IAbstractItem stopItem      = root;
            IAbstractItem node          = root;
            string        remainingPath = path;
            int           index         = 0;

            foreach (var token in tokens)
            {
                if (StopCondition != null && StopCondition(node))
                {
                    break;
                }
                node = node.GetChildPageByAlias(token, targetingFilter);
                if (node == null)
                {
                    break;
                }
                index++;
                stopItem      = node;
                remainingPath = $"/{string.Join("/", tokens.Select((x, i) => i < index ? (string)null : x).Where(x => x != null))}";
            }

            return(new PathData(stopItem, remainingPath));
        }
예제 #3
0
 /// <summary>
 /// Определяем, что abstractItem принадлежит стартовой странице startPage
 /// </summary>
 private bool IsStartPageContainAbstractItem(IStartPage startPage, IAbstractItem abstractItem)
 {
     if (startPage == null || abstractItem == null)
     {
         return(false);
     }
     while (abstractItem.Parent != null)
     {
         if (abstractItem.Id == startPage.Id)
         {
             return(true);
         }
         abstractItem = abstractItem.Parent;
     }
     return(false);
 }
예제 #4
0
 public StartPageSteps(Guid driverId)
 {
     startPage = DependencyResolver.For <IStartPage>(driverId);
 }
 public StartPagePresenter(IStartPage view, AppSettingsStorage settings)
 {
     startPageView = view;
     storageSettings = settings;
 }