예제 #1
0
        /// <summary>
        /// Generate site map
        /// </summary>
        /// <param name="pageRootId"></param>
        /// <returns></returns>
        public List <ITree <NavigationNodeModel> > GenerateSiteMap(int?pageRootId = null)
        {
            var root = GetByPage(pageRootId);

            var clientNavigations = root != null
                ? _clientNavigationRepository.GetHierarchies(root)
                : _clientNavigationRepository.GetAll();

            var models = clientNavigations.ToList().Select(Navigation => new NavigationNodeModel(Navigation));

            var result =
                HierachyTree <NavigationNodeModel> .CreateForest(models).OrderBy(i => i.Data.RecordOrder).ToList();

            //Setup the permissions
            var rootViewableGroupIds = GetViewableGroups(pageRootId);
            var rootEditableGroupIds = GetEditableGroups(pageRootId);

            foreach (var tree in result)
            {
                SetupGroupPermissions(tree, rootViewableGroupIds, rootEditableGroupIds, true);
            }

            var comparer =
                Comparer <NavigationNodeModel> .Create(
                    (i, j) => Comparer <int> .Default.Compare(i.RecordOrder, j.RecordOrder));

            //For page included in navigation, just need the view permission
            //For page which is not included in navigation, users need the edit permission to see it in the site map.
            result.RemoveAll(i => !i.Data.CanView || (!i.Data.CanEdit && !i.Data.IncludeInSiteNavigation));

            foreach (var tree in result)
            {
                tree.RemoveAll(i => !i.CanView || (!i.CanEdit && !i.IncludeInSiteNavigation));
                tree.OrderChildren(comparer);
            }

            return(result.Cast <ITree <NavigationNodeModel> >().ToList());
        }
예제 #2
0
        /// <summary>
        /// Generate Navigation
        /// </summary>
        /// <param name="pageRootId"></param>
        /// <param name="includeRoot"></param>
        /// <returns></returns>
        public List <ITree <NavigationNodeModel> > GenerateNavigations(int?pageRootId = null, bool includeRoot = false)
        {
            var root = GetByPage(pageRootId);

            //Get all avail Navigations
            var clientNavigations = root != null
                ? _clientNavigationRepository.GetHierarchies(root, false)
                : _clientNavigationRepository.GetAll();


            //Remove disabled cascade Navigations and their children
            var disableNavigationCascadeNavigations =
                clientNavigations.Where(
                    m => m.PageId.HasValue ? m.Page.DisableNavigationCascade : m.DisableNavigationCascade)
                .Select(m => m.Hierarchy)
                .ToList();

            clientNavigations =
                clientNavigations.Where(
                    m =>
                    !disableNavigationCascadeNavigations.Any(
                        hierarchy => !m.Hierarchy.Equals(hierarchy) && m.Hierarchy.StartsWith(hierarchy)));

            //Remove hide from navigation cascade Navigation, not publishing pages, offline pages and their children
            var now = DateTime.UtcNow;
            var hidingNavigations = clientNavigations.Where(m =>

                                                            //Not Include in site navigation page
                                                            (m.PageId.HasValue ? !m.Page.IncludeInSiteNavigation : !m.IncludeInSiteNavigation)

                                                            //Not Include in site navigation page
                                                            || (m.PageId.HasValue && m.Page.Status == PageEnums.PageStatus.Offline)

                                                            //Not publishing page
                                                            ||
                                                            ((m.PageId.HasValue ? m.Page.StartPublishingDate.HasValue : m.StartPublishingDate.HasValue) &&
                                                             (m.PageId.HasValue ? now < m.Page.StartPublishingDate : now < m.StartPublishingDate))
                                                            ||
                                                            ((m.PageId.HasValue ? m.Page.EndPublishingDate.HasValue : m.EndPublishingDate.HasValue) &&
                                                             (m.PageId.HasValue ? now > m.Page.EndPublishingDate : now > m.EndPublishingDate)))
                                    .Select(m => m.Hierarchy).ToList();

            clientNavigations =
                clientNavigations.Where(m => !hidingNavigations.Any(hierarchy => m.Hierarchy.StartsWith(hierarchy)));

            var NavigationModels =
                clientNavigations.ToList().Select(Navigation => new NavigationNodeModel(Navigation)).ToList();

            var result =
                HierachyTree <NavigationNodeModel> .CreateForest(NavigationModels)
                .OrderBy(i => i.Data.RecordOrder)
                .ToList();

            //Setup the permissions
            var rootViewableGroupIds = GetViewableGroups(pageRootId);
            var rootEditableGroupIds = GetEditableGroups(pageRootId);

            foreach (var tree in result)
            {
                SetupGroupPermissions(tree, rootViewableGroupIds, rootEditableGroupIds);
            }

            //Order all items
            var comparer =
                Comparer <NavigationNodeModel> .Create(
                    (i, j) => Comparer <int> .Default.Compare(i.RecordOrder, j.RecordOrder));

            foreach (var tree in result)
            {
                tree.OrderChildren(comparer);
            }

            // Add root Navigation if required
            if (includeRoot && root != null)
            {
                var rootNode = new NavigationNodeModel(root)
                {
                    ViewableGroups = rootViewableGroupIds,
                    EditableGroups = rootEditableGroupIds
                };

                result.Insert(0, new HierachyTree <NavigationNodeModel>(rootNode));
            }

            return(result.Cast <ITree <NavigationNodeModel> >().ToList());
        }