Exemplo n.º 1
0
        public async Task TestTreeWithFilters(NextApiTransport transport)
        {
            await App.GenerateTreeItems();

            var service = App.ResolveService <ITestTreeItemService>("1", transport);

            var request = new TreeRequest <int?>()
            {
                ParentId     = null,
                PagedRequest = new PagedRequest()
                {
                    Filter = new FilterBuilder().Contains("Name", "0").Build()
                }
            };
            var response = await service.GetTree(request);

            Assert.Equal(3, response.Items.Count);

            var request1 = new TreeRequest <int?>()
            {
                ParentId     = null,
                PagedRequest = new PagedRequest()
                {
                    Filter = new FilterBuilder().Contains("Name", "node").Build(), Take = 20
                }
            };
            var response1 = await service.GetTree(request1);

            Assert.Equal(20, response1.Items.Count);
            Assert.Equal(31, response1.TotalItems);
        }
Exemplo n.º 2
0
 public TreeResponse Nodes([FromUri] TreeRequest request)
 {
     return(new TreeResponse
     {
         children = new List <TreeNode> {
             new TreeNode {
                 id = 1, parentId = request.node, text = "Folder# 1", leaf = false, cls = "folder",
                 children = new List <TreeNode> {
                     new TreeNode {
                         id = 3, parentId = 1, text = "File# 1.1", leaf = true, cls = "file"
                     },
                     new TreeNode {
                         id = 4, parentId = 1, text = "File# 1.2", leaf = true, cls = "file"
                     },
                 }
             },
             new TreeNode {
                 id = 2, parentId = request.node, text = "Folder# 2", leaf = false, cls = "folder",
                 children = new List <TreeNode> {
                     new TreeNode {
                         id = 5, parentId = 2, text = "File# 2.1", leaf = true, cls = "file"
                     },
                     new TreeNode {
                         id = 6, parentId = 2, text = "File# 2.2", leaf = true, cls = "file"
                     },
                 }
             },
         }
     });
 }
Exemplo n.º 3
0
        public IActionResult Tree([FromQuery] TreeRequest request)
        {
            var ctx = new RequestContext(SqlScope, SqlId)
                      .SetCmdType(CmdType.query)
                      .SetParam(request)
                      .SetExtraParam(AppCtx.AC.Params);
            var tree = AppCtx.Session.QueryDataTable(ctx);

            return(Json(new TreeResponse
            {
                Request = request,
                Data = tree
            }));
        }
Exemplo n.º 4
0
        public async Task TestTree(NextApiTransport transport, int?parentId, int shouldReturnCount)
        {
            await App.GenerateTreeItems();

            var service = App.ResolveService <ITestTreeItemService>("1", transport);

            var request = new TreeRequest <int?>()
            {
                ParentId = parentId
            };
            //Expand = new[] {"Children"}};

            var response = await service.GetTree(request);

            Assert.Equal(shouldReturnCount, response.Items.FirstOrDefault()?.ChildrenCount);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public virtual async Task <PagedList <TreeItem <TDto> > > GetTree(TreeRequest <TParentKey> request)
        {
            var entitiesQuery = _repository.GetAll();

            entitiesQuery = await BeforeGet(entitiesQuery);

            var rootQuery  = entitiesQuery.Where(e => e.ParentId.Equals(request.ParentId));
            var totalCount = 0;

            if (request.PagedRequest != null)
            {
                var filterExpression = request.PagedRequest.Filter?.ToLambdaFilter <TEntity>();
                if (filterExpression != null)
                {
                    rootQuery = rootQuery.Where(filterExpression);
                }

                totalCount = rootQuery.Count();
                if (request.PagedRequest.Skip != null)
                {
                    rootQuery = rootQuery.Skip(request.PagedRequest.Skip.Value);
                }
                if (request.PagedRequest.Take != null)
                {
                    rootQuery = rootQuery.Take(request.PagedRequest.Take.Value);
                }
                if (request.PagedRequest.Expand != null)
                {
                    rootQuery = _repository.Expand(rootQuery, request.PagedRequest.Expand);
                }
            }

            var treeChunk = await _repository.ToArrayAsync(rootQuery
                                                           .Select(e => new { Entity = e, ChildrenCount = entitiesQuery.Count(ce => e.Id.Equals(ce.ParentId)) }));

            var output = treeChunk.Select(chunkItem =>
                                          new TreeItem <TDto>
            {
                ChildrenCount = chunkItem.ChildrenCount, Entity = _mapper.Map <TEntity, TDto>(chunkItem.Entity)
            }).ToList();

            return(new PagedList <TreeItem <TDto> >
            {
                Items = output, TotalItems = totalCount == 0 ? output.Count : totalCount
            });
        }
Exemplo n.º 6
0
        public async Task <ActionResult <TreeResult> > Tree([FromBody] TreeRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.Contents))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var enabledChannelIds = await _authManager.GetContentPermissionsChannelIdsAsync(site.Id);

            var visibleChannelIds = await _authManager.GetVisibleChannelIdsAsync(enabledChannelIds);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var visible  = visibleChannelIds.Contains(summary.Id);
                var disabled = !enabledChannelIds.Contains(summary.Id);
                var current  = await _contentRepository.GetSummariesAsync(site, summary);

                if (!visible)
                {
                    return(null);
                }

                return(new
                {
                    current.Count,
                    Disabled = disabled
                });
            });

            if (!request.Reload)
            {
                var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

                var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

                var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

                var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

                return(new TreeResult
                {
                    Root = root,
                    SiteUrl = siteUrl,
                    GroupNames = groupNames,
                    TagNames = tagNames,
                    CheckedLevels = checkedLevels
                });
            }

            return(new TreeResult
            {
                Root = root
            });
        }
Exemplo n.º 7
0
        public async Task <ActionResult <TreeResult> > Tree([FromBody] TreeRequest request)
        {
            var siteIdList = await _authManager.GetSiteIdsAsync();

            if (siteIdList == null || siteIdList.Count == 0)
            {
                return(Unauthorized());
            }

            var  sites = new List <Select <int> >();
            Site site  = null;

            foreach (var siteId in siteIdList)
            {
                var permissionSite = await _siteRepository.GetAsync(siteId);

                if (request.SiteId == siteId)
                {
                    site = permissionSite;
                }
                sites.Add(new Select <int>
                {
                    Value = permissionSite.Id,
                    Label = permissionSite.SiteName
                });
            }

            if (site == null && siteIdList.Count > 0)
            {
                site = await _siteRepository.GetAsync(siteIdList[0]);
            }

            if (site == null)
            {
                return(Unauthorized());
            }

            var channel = await _channelRepository.GetAsync(site.Id);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            if (!request.Reload)
            {
                var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

                var groupNames = await _contentGroupRepository.GetGroupNamesAsync(site.Id);

                var tagNames = await _contentTagRepository.GetTagNamesAsync(site.Id);

                var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

                var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
                var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.SearchContents);

                var permissions = new TreePermissions
                {
                    IsAdd         = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Add),
                    IsDelete      = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Delete),
                    IsEdit        = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Edit),
                    IsArrange     = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Arrange),
                    IsTranslate   = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Translate),
                    IsCheck       = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.CheckLevel1),
                    IsCreate      = await _authManager.HasSitePermissionsAsync(site.Id, Types.SitePermissions.CreateContents) || await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, Types.ContentPermissions.Create),
                    IsChannelEdit = await _authManager.HasChannelPermissionsAsync(site.Id, channel.Id, Types.ChannelPermissions.Edit)
                };

                return(new TreeResult
                {
                    Sites = sites,
                    SiteId = site.Id,
                    SiteName = site.SiteName,
                    SiteUrl = siteUrl,
                    Root = root,
                    GroupNames = groupNames,
                    TagNames = tagNames,
                    CheckedLevels = checkedLevels,
                    Columns = columns,
                    Permissions = permissions
                });
            }

            return(new TreeResult
            {
                Root = root
            });
        }
        public async Task <ActionResult <TreeResult> > Tree([FromBody] TreeRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            MenuUtils.SitePermissions.ContentsSearch))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var root = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count = await _contentRepository.GetCountAsync(site, summary);
                return(new
                {
                    Count = count
                });
            });

            if (!request.Reload)
            {
                var siteUrl = await _pathManager.GetSiteUrlAsync(site, true);

                var groupNames = await _contentGroupRepository.GetGroupNamesAsync(request.SiteId);

                var tagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

                var checkedLevels = ElementUtils.GetCheckBoxes(CheckManager.GetCheckedLevels(site, true, site.CheckContentLevel, true));

                var columnsManager = new ColumnsManager(_databaseManager, _pathManager);
                var columns        = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.SearchContents);

                var permissions = new Permissions
                {
                    IsAdd         = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Add),
                    IsDelete      = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Delete),
                    IsEdit        = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Edit),
                    IsArrange     = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Arrange),
                    IsTranslate   = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Translate),
                    IsCheck       = await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.CheckLevel1),
                    IsCreate      = await _authManager.HasSitePermissionsAsync(site.Id, MenuUtils.SitePermissions.CreateContents) || await _authManager.HasContentPermissionsAsync(site.Id, channel.Id, MenuUtils.ContentPermissions.Create),
                    IsChannelEdit = await _authManager.HasChannelPermissionsAsync(site.Id, channel.Id, MenuUtils.ChannelPermissions.Edit)
                };

                var titleColumn =
                    columns.FirstOrDefault(x => StringUtils.EqualsIgnoreCase(x.AttributeName, nameof(Models.Content.Title)));
                columns.Remove(titleColumn);

                return(new TreeResult
                {
                    Root = root,
                    SiteUrl = siteUrl,
                    GroupNames = groupNames,
                    TagNames = tagNames,
                    CheckedLevels = checkedLevels,
                    TitleColumn = titleColumn,
                    Columns = columns,
                    Permissions = permissions
                });
            }

            return(new TreeResult
            {
                Root = root
            });
        }
Exemplo n.º 9
0
 /// <inheritdoc />
 public async Task <PagedList <TreeItem <TEntity> > > GetTree(TreeRequest <TParentKey> request) =>
 await InvokeService <PagedList <TreeItem <TEntity> > >(nameof(GetTree),
                                                        new NextApiArgument(nameof(request), request));
Exemplo n.º 10
0
        private void WriteJson(JsonWriter writer, IEnumerable <DataRow> rows, TreeRequest request)
        {
            writer.WriteStartArray();

            if (request != null && request.NullSelect)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("id");
                writer.WriteValue("");
                writer.WritePropertyName("text");
                writer.WriteValue(" ");
                writer.WriteEndObject();
            }

            foreach (DataRow row in rows)
            {
                var id   = row[0].ToString();
                var text = row[1].ToString();
                if (row.Table.Columns.Contains("title"))
                {
                    text = $"<span title=\"{row["title"]}\">{text}</span>";
                }

                writer.WriteStartObject();
                writer.WritePropertyName("id");
                writer.WriteValue(id);
                writer.WritePropertyName("text");
                writer.WriteValue(text);

                if (row.Table.Columns.Contains("checked"))
                {
                    writer.WritePropertyName("checked");
                    writer.WriteValue(row["checked"] != Convert.DBNull && Convert.ToBoolean(row["checked"]));
                }
                if (row.Table.Columns.Contains("icon"))
                {
                    writer.WritePropertyName("iconCls");
                    writer.WriteDbValue(row["icon"]);
                }
                if (row.Table.Columns.Count > 4)
                {
                    writer.WritePropertyName("attributes");
                    writer.WriteStartObject();
                    for (int i = 4; i < row.Table.Columns.Count; i++)
                    {
                        DataColumn col = row.Table.Columns[i];
                        if (!(col.ColumnName == "checked") && !(col.ColumnName == "icon"))
                        {
                            writer.WritePropertyName(col.ColumnName);
                            writer.WriteDbValue(row[col]);
                        }
                    }
                    writer.WriteEndObject();
                }

                DataRow[] childRows = null;
                var       childs    = row.Table.Columns.Contains("childs") ? Convert.ToInt32(row["childs"]) : 0;
                if (row.Table.Columns.Contains("parentid"))
                {
                    childRows = row.Table.Select("parentid='" + id + "'", "orderno");
                }
                if (childs > 0 && (childRows == null || (childRows != null && childRows.Length == 0)))
                {
                    writer.WritePropertyName("state");
                    writer.WriteValue("closed");
                }
                else if (childRows != null && childRows.Length != 0)
                {
                    writer.WritePropertyName("children");
                    WriteJson(writer, childRows, null);
                }

                writer.WriteEndObject();
            }
            writer.WriteEndArray();
        }