Ejemplo n.º 1
0
        public virtual ActionResult SelectCategories(string folderName, string selected, int? page, int? pageSize, string search, IEnumerable<WhereClause> whereClause)
        {
            var textFolder = (TextFolder)(FolderHelper.Parse<TextFolder>(Repository, folderName).AsActual());

            var singleChoice = string.Equals("True", Request.RequestContext.GetRequestValue("SingleChoice"), StringComparison.OrdinalIgnoreCase);

            Schema schema = new Schema(Repository, textFolder.SchemaName).AsActual();
            SchemaPath schemaPath = new SchemaPath(schema);
            ViewData["Folder"] = textFolder;
            ViewData["Schema"] = schema;
            ViewData["Template"] = textFolder.GetFormTemplate(FormType.Selectable);
            ViewData["WhereClause"] = whereClause;

            IEnumerable<TextFolder> childFolders = new TextFolder[0];
            //Skip the child folders on the embedded folder grid.
            if (!page.HasValue || page.Value <= 1)
            {
                childFolders = ServiceFactory.TextFolderManager.ChildFoldersWithSameSchema(textFolder).Select(it => it.AsActual());
            }

            var query = textFolder.CreateQuery().DefaultOrder();

            bool showTreeStyle = schema.IsTreeStyle;
            if (showTreeStyle)
            {
                query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", "")));
            }

            if (!string.IsNullOrEmpty(search))
            {
                IWhereExpression exp = new FalseExpression();
                foreach (var item in schema.Columns.Where(it => it.ShowInGrid))
                {
                    exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search)));
                }
                if (exp != null)
                {
                    query = query.Where(exp);
                }
            }
            if (whereClause != null && whereClause.Count() > 0)
            {
                var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider));
                query = query.Where(expression);
            }

            var contents = query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize);
            SelectableViewModel viewModel = new SelectableViewModel() { ChildFolders = childFolders, Contents = contents, SingleChoice = singleChoice };

            if (Request.IsAjaxRequest())
            {
                return PartialView("", viewModel);
            }
            else
            {
                IEnumerable<TextContent> selectedContents = new TextContent[0];
                if (!string.IsNullOrEmpty(selected))
                {
                    string[] selectedArr = selected.Split(',');
                    IContentQuery<TextContent> selectedQuery = textFolder.CreateQuery().DefaultOrder();
                    foreach (var userKey in selectedArr)
                    {
                        selectedQuery = selectedQuery.Or((IWhereExpression)textFolder.CreateQuery().DefaultOrder().WhereEquals("UUID", userKey).Expression);
                    }

                    selectedContents = selectedQuery;
                }
                viewModel.Selected = selectedContents;
            }

            return View(viewModel);
        }
Ejemplo n.º 2
0
        public virtual ActionResult Index(string folderName, string parentUUID, string parentFolder, string search
            , IEnumerable<WhereClause> whereClause, int? page, int? pageSize, string orderField = null, string direction = null)
        {
            //compatible with the Folder parameter changed to FolderName.
            folderName = folderName ?? this.ControllerContext.RequestContext.GetRequestValue("Folder");

            TextFolder textFolder = new TextFolder(Repository, folderName).AsActual();
            var schema = textFolder.GetSchema().AsActual();

            SchemaPath schemaPath = new SchemaPath(schema);
            ViewData["Folder"] = textFolder;
            ViewData["Schema"] = schema;
            ViewData["Template"] = textFolder.GetFormTemplate(FormType.Grid);
            ViewData["WhereClause"] = whereClause;

            SetPermissionData(textFolder);

            IEnumerable<TextFolder> childFolders = new TextFolder[0];
            //Skip the child folders on the embedded folder grid.
            if (string.IsNullOrEmpty(parentFolder))
            {
                if (!page.HasValue || page.Value <= 1)
                {
                    childFolders = ServiceFactory.TextFolderManager.ChildFolders(textFolder, search).Select(it => it.AsActual());
                }
            }

            IContentQuery<TextContent> query = textFolder.CreateQuery();
            if (string.IsNullOrEmpty(orderField))
            {
                query = query.DefaultOrder();
            }
            else
            {
                if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "desc")
                {
                    query = query.OrderByDescending(orderField);
                }
                else
                {
                    query = query.OrderBy(orderField);
                }
            }
            bool showTreeStyle = schema.IsTreeStyle;
            //如果有带搜索条件,则不输出树形结构
            if (!string.IsNullOrEmpty(search))
            {
                IWhereExpression exp = new FalseExpression();
                foreach (var item in schema.Columns.Where(it => it.ShowInGrid))
                {
                    exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search)));
                }
                if (exp != null)
                {
                    query = query.Where(exp);
                }
                showTreeStyle = false;
            }
            if (whereClause != null && whereClause.Count() > 0)
            {
                var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider));
                query = query.Where(expression);
                showTreeStyle = false;
            }
            if (!string.IsNullOrWhiteSpace(parentUUID))
            {
                query = query.WhereEquals("ParentUUID", parentUUID);
            }
            else
            {
                //有两种情况需要考虑要不要查询所有的数据(ParentUUID=null)
                //1.树形结构数据,第一次查询需要过滤ParentUUID==null
                //2.自嵌套的目前结构,也需要过滤ParentUUID==null
                var selfEmbedded = textFolder.EmbeddedFolders != null && textFolder.EmbeddedFolders.Contains(textFolder.FullName, StringComparer.OrdinalIgnoreCase);
                if (showTreeStyle || selfEmbedded)
                {
                    query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", "")));
                }
            }

            if (childFolders != null)
            {
                childFolders = childFolders
                    .Select(it => it.AsActual())
                    .Where(it => it.VisibleOnSidebarMenu == null || it.VisibleOnSidebarMenu.Value == true)
                    .Where(it => Kooboo.CMS.Content.Services.ServiceFactory.WorkflowManager.AvailableViewContent(it, User.Identity.Name));
            }
            page = page ?? 1;
            pageSize = pageSize ?? textFolder.PageSize;

            //var pagedList = query.ToPageList(page.Value, pageSize.Value);

            //IEnumerable<TextContent> contents = pagedList.ToArray();

            //if (Repository.EnableWorkflow == true)
            //{
            //    contents = ServiceFactory.WorkflowManager.GetPendWorkflowItemForContents(Repository, contents.ToArray(), User.Identity.Name);
            //}

            //var workflowContentPagedList = new PagedList<TextContent>(contents, page.Value, pageSize.Value, pagedList.TotalItemCount);
            //ViewData["ContentPagedList"] = workflowContentPagedList;
            return View(new TextContentGrid()
            {
                ChildFolders = childFolders.ToArray(),
                ContentQuery = query,
                PageIndex = page.Value,
                PageSize = pageSize.Value,
                ShowTreeStyle = showTreeStyle
            });
        }
Ejemplo n.º 3
0
        public void Test_NestedOr()
        {
            IWhereExpression exp = new FalseExpression();

            exp = new OrElseExpression(exp, (new WhereContainsExpression(null, "title", "news1")));
            exp = new OrElseExpression(exp, (new WhereContainsExpression(null, "title", "news2")));

            var news = newsFolder.CreateQuery().Where(exp);

            Assert.AreEqual(3, news.Count());

        }
Ejemplo n.º 4
0
        protected override void VisitOrElse(OrElseExpression expression)
        {
            string leftClause = "";
            string leftViewName = "";
            if (!(expression.Left is FalseExpression))
            {
                var leftVisitor = VisitInner(expression.Left);
                leftClause = leftVisitor.WhereClause;
                leftViewName = leftVisitor.ViewName;
                if (leftVisitor.OrderClause != null)
                {
                    this.OrderClause = leftVisitor.OrderClause;
                }
            }

            string rightClause = "";
            string rightViewName = "";
            if (!(expression.Right is FalseExpression))
            {
                var rightVisitor = VisitInner(expression.Right);
                rightClause = rightVisitor.WhereClause;
                rightViewName = rightVisitor.ViewName;
                if (rightVisitor.OrderClause != null)
                {
                    this.OrderClause = rightVisitor.OrderClause;
                }
            }

            if (!string.IsNullOrEmpty(leftClause) && !string.IsNullOrEmpty(rightClause))
            {
                whereClause.AppendFormat(string.Format("({0}||{1})", leftClause, rightClause));
                viewNameBuilder.AppendFormat("_({0}_OR_{1})", leftViewName, rightViewName);
            }
            else if (!string.IsNullOrEmpty(leftClause))
            {
                whereClause.AppendFormat(string.Format("{0}", leftClause));
                viewNameBuilder.AppendFormat("_{0}", leftViewName);
            }
            else if (!string.IsNullOrEmpty(rightClause))
            {
                whereClause.AppendFormat(string.Format("{0}", rightClause));
                viewNameBuilder.AppendFormat("_{0}", rightViewName);
            }
        }
Ejemplo n.º 5
0
 protected virtual void VisitWhereIn(WhereInExpression expression)
 {
     IWhereExpression exp = new FalseExpression();
     foreach (var value in expression.Values)
     {
         exp = new OrElseExpression(exp, new WhereEqualsExpression(null, expression.FieldName, value));
     }
     this.VisitWhere(exp);
 }
Ejemplo n.º 6
0
 protected abstract void VisitOrElse(OrElseExpression expression);