示例#1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            SidePanelViewModel model = new SidePanelViewModel
            {
                Categories = repository.Categories.OrderByDescending(n => n.Name.Length).Select(x => x.Name),
                Posts      = repository.Posts.OrderByDescending(p => p.DateChanged).Take(countArticle),
            };

            return(View(model));
        }
        /// <summary>
        /// Отображение боковой панели.
        /// </summary>
        /// <param name="id">Уникальный Id папки, для которой запрашивается представление.</param>
        /// <returns>Представление боковой панели для папки с идентификатором Id.</returns>
        public IViewComponentResult GetSidePanel(Guid?id)
        {
            id = id ?? DObject.RootId;

            var context     = _contextHolder.GetContext(HttpContext);
            var repo        = context.Repository;
            var rootObject  = repo.GetObjects(new[] { id.Value }).First();
            var bRootObject = repo.GetObjects(new[] { DObject.RootId }).First();
            var mTypes      = repo.GetTypes().ToDictionary(x => x.Id, y => y);
            var model       = new SidePanelViewModel
            {
                ObjectId = id.Value,
                Types    = mTypes,
                Items    = new List <SidePanelItem>()
            };

            var prevId   = rootObject.Id;
            var parentId = rootObject.Id;

            do
            {
                var parentObject    = repo.GetObjects(new[] { parentId }).First();
                var parentChildsIds = parentObject.Children
                                      .Where(x => mTypes[x.TypeId].IsService == false)
                                      .Select(x => x.ObjectId).ToArray();
                if (parentChildsIds.Length != 0)
                {
                    var parentChilds    = repo.GetObjects(parentChildsIds);
                    var visibleChildren = parentChilds.Where(x => x.IsVisible()).ToList();
                    var subtree         = model.Items;
                    model.Items = new List <SidePanelItem>();
                    foreach (var parentChild in visibleChildren)
                    {
                        if (parentChild.IsForbidden())
                        {
                            continue;
                        }

                        model.Items.Add(new SidePanelItem
                        {
                            Type     = mTypes[parentChild.TypeId],
                            DObject  = parentChild,
                            SubItems = parentChild.Id == prevId ? subtree : null,
                            Selected = parentChild.Id == id
                        });
                    }
                }

                prevId   = parentId;
                parentId = parentObject.ParentId;
            } while (parentId != bRootObject.ParentId);
            return(View(model));
        }
示例#3
0
        /// <summary>
        /// Отображение боковой панели.
        /// </summary>
        /// <param name="id">Уникальный Id папки, для которой запрашивается представление.</param>
        /// <returns>Представление боковой панели для папки с идентификатором Id.</returns>
        public IViewComponentResult GetSidePanel(Guid?id)
        {
            id = id ?? DObject.RootId;

            var serverApi  = HttpContext.GetServerApi();
            var rootObject = serverApi.GetObjects(new[] { id.Value }).First();

            var mTypes = HttpContext.Session.GetMetatypes();
            var model  = new SidePanelViewModel
            {
                ObjectId = id.Value,
                Types    = mTypes,
                Items    = new List <SidePanelItem>()
            };

            var prevId   = rootObject.Id;
            var parentId = rootObject.Id;

            do
            {
                var parentObject    = serverApi.GetObjects(new[] { parentId }).First();
                var parentChildsIds = parentObject.Children
                                      .Where(x => mTypes[x.TypeId].Children.Any())
                                      .Select(x => x.ObjectId).ToArray();
                if (parentChildsIds.Length != 0)
                {
                    var parentChilds = serverApi.GetObjects(parentChildsIds);
                    var subtree      = model.Items;
                    model.Items = new List <SidePanelItem>(parentChilds.Count);
                    foreach (var parentChild in parentChilds)
                    {
                        model.Items.Add(new SidePanelItem
                        {
                            Type     = mTypes[parentChild.TypeId],
                            DObject  = parentChild,
                            SubItems = parentChild.Id == prevId ? subtree : null,
                            Selected = parentChild.Id == id
                        });
                    }
                }

                prevId   = parentId;
                parentId = parentObject.ParentId;
            } while (parentId != Guid.Empty);
            return(View(model));
        }