예제 #1
0
        public virtual ActionResult Selectable(string categoryFolder, int?page, int?pageSize, string orderField = null, string direction = null)
        {
            var        textFolder = (TextFolder)(FolderHelper.Parse <TextFolder>(Repository, categoryFolder).AsActual());
            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);


            IContentQuery <TextContent> query = textFolder.CreateQuery();

            if (string.IsNullOrEmpty(orderField))
            {
                query = query.DefaultOrder();
            }
            else
            {
                if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "asc")
                {
                    query = query.OrderBy(orderField);
                }
                else
                {
                    query = query.OrderByDescending(orderField);
                }
            }
            return(View(query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize)));
        }
예제 #2
0
        protected override DriverResult Display(ContainerWidgetPart part, string displayType, dynamic shapeHelper)
        {
            return(ContentShape(
                       "Parts_ContainerWidget",
                       () => {
                var container = _contentManager.Get(part.Record.ContainerId);

                IContentQuery <ContentItem> query = _contentManager
                                                    .Query(VersionOptions.Published)
                                                    .Join <CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);

                var descendingOrder = part.Record.OrderByDirection == (int)OrderByDirection.Descending;
                query = query.OrderBy(part.Record.OrderByProperty, descendingOrder);

                if (part.Record.ApplyFilter)
                {
                    query = query.Where(part.Record.FilterByProperty, part.Record.FilterByOperator, part.Record.FilterByValue);
                }

                var pageOfItems = query.Slice(0, part.Record.PageSize).ToList();

                var list = shapeHelper.List();
                list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));

                return shapeHelper.Parts_ContainerWidget(ContentItems: list);
            }));
        }
예제 #3
0
        public static IContentQuery <T> OrderBy <T>(this IContentQuery <T> query, string partAndProperty, bool descendingOrder) where T : IContent
        {
            //todo: (heskew) order by custom part properties
            switch (partAndProperty)
            {
            case "ContainablePart.Weight":
                query = descendingOrder
                                ? query.OrderByDescending <ContainablePartRecord>(record => record.Position)
                                : query.OrderBy <ContainablePartRecord>(record => record.Position);
                break;

            case "TitlePart.Title":
                query = descendingOrder
                                ? query.OrderByDescending <TitlePartRecord>(record => record.Title)
                                : query.OrderBy <TitlePartRecord>(record => record.Title);
                break;

            case "CustomPropertiesPart.CustomOne":
                query = descendingOrder
                                ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomOne)
                                : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomOne);
                break;

            case "CustomPropertiesPart.CustomTwo":
                query = descendingOrder
                                ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomTwo)
                                : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomTwo);
                break;

            case "CustomPropertiesPart.CustomThree":
                query = descendingOrder
                                ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomThree)
                                : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomThree);
                break;

            case "CommonPart.CreatedUtc":
                query = descendingOrder
                                ? query.OrderByDescending <CommonPartRecord>(record => record.CreatedUtc)
                                : query.OrderBy <CommonPartRecord>(record => record.CreatedUtc);
                break;

            default:     // "CommonPart.PublishedUtc"
                query = descendingOrder
                                ? query.OrderByDescending <CommonPartRecord>(record => record.PublishedUtc)
                                : query.OrderBy <CommonPartRecord>(record => record.PublishedUtc);
                break;
            }

            return(query);
        }
예제 #4
0
 public static IContentQuery <T> SortBy <T>(this IContentQuery <T> list, string sortField, string sortDir)
     where T : ContentBase
 {
     if (!string.IsNullOrEmpty(sortField))
     {
         var sort = sortField;
         if (sortDir == "desc")
         {
             return(list.OrderByDescending(sortField));
         }
         else
         {
             return(list.OrderBy(sortField));
         }
     }
     return(list);
 }
예제 #5
0
        protected override DriverResult Display(ContainerPart part, string displayType, dynamic shapeHelper)
        {
            if (!part.ItemsShown)
            {
                return(null);
            }

            return(ContentShape("Parts_Container_Contained",
                                () => {
                var container = part.ContentItem;

                IContentQuery <ContentItem> query = _contentManager
                                                    .Query(VersionOptions.Published)
                                                    .Join <CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);

                var descendingOrder = part.OrderByDirection == (int)OrderByDirection.Descending;
                query = query.OrderBy(part.OrderByProperty, descendingOrder);
                var metadata = container.ContentManager.GetItemMetadata(container);
                if (metadata != null)
                {
                    _feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary {
                        { "containerid", container.Id }
                    });
                }

                var pager = new Pager(_siteService.GetSiteSettings(), part.PagerParameters);
                pager.PageSize = part.PagerParameters.PageSize != null && part.Paginated
                                                ? pager.PageSize
                                                : part.PageSize;

                var pagerShape = shapeHelper.Pager(pager).TotalItemCount(query.Count());

                var startIndex = part.Paginated ? pager.GetStartIndex() : 0;
                var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList();

                var listShape = shapeHelper.List();
                listShape.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));
                listShape.Classes.Add("content-items");
                listShape.Classes.Add("list-items");

                return shapeHelper.Parts_Container_Contained(
                    List: listShape,
                    Pager: part.Paginated ? pagerShape : null
                    );
            }));
        }
예제 #6
0
 private static IContentQuery <TextContent> SortByField(string sortField, string sortDir, IContentQuery <TextContent> query)
 {
     if (string.IsNullOrEmpty(sortField))
     {
         query = query.DefaultOrder();
     }
     else
     {
         if (!string.IsNullOrEmpty(sortDir) && sortDir.ToLower() == "desc")
         {
             query = query.OrderByDescending(sortField);
         }
         else
         {
             query = query.OrderBy(sortField);
         }
     }
     return(query);
 }
        public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> textContents, string orderField, OrderDirection orderDirection = OrderDirection.Descending)
        {
            if (textContents is TextContentQueryBase)
            {
                var textFolder = ((TextContentQueryBase)textContents).Folder.AsActual();
                if (textFolder.Sortable.HasValue && textFolder.Sortable.Value)
                {
                    orderField     = "Sequence";
                    orderDirection = OrderDirection.Descending;
                }

                if (orderDirection == OrderDirection.Ascending)
                {
                    return(textContents.OrderBy(orderField));
                }
                else
                {
                    return(textContents.OrderByDescending(orderField));
                }
            }
            return(textContents);
        }
예제 #8
0
        public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> contentQuery)
        {
            if (contentQuery is TextContentQueryBase)
            {
                var textFolder = ((TextContentQueryBase)contentQuery).Folder.AsActual();
                var orderField = "UtcCreationDate";
                var direction  = OrderDirection.Descending;

                if (textFolder.OrderSetting != null && !string.IsNullOrEmpty(textFolder.OrderSetting.FieldName))
                {
                    orderField = textFolder.OrderSetting.FieldName;
                    direction  = textFolder.OrderSetting.Direction;
                }
                if (direction == OrderDirection.Ascending)
                {
                    return(contentQuery.OrderBy(orderField));
                }
                else
                {
                    return(contentQuery.OrderByDescending(orderField));
                }
            }
            return(contentQuery);
        }
예제 #9
0
        public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> contentQuery)
        {
            if (contentQuery is TextContentQueryBase)
            {
                var textFolder = ((TextContentQueryBase)contentQuery).Folder.AsActual();
                var orderField = "UtcCreationDate";
                var direction  = OrderDirection.Descending;

                if (textFolder.Sortable.HasValue && textFolder.Sortable.Value == true)
                {
                    orderField = "Sequence";
                    direction  = OrderDirection.Descending;
                }
                if (direction == OrderDirection.Ascending)
                {
                    return(contentQuery.OrderBy(orderField));
                }
                else
                {
                    return(contentQuery.OrderByDescending(orderField));
                }
            }
            return(contentQuery);
        }
예제 #10
0
        public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> textContents, TextFolder textFolder)
        {
            if (textContents is TextContentQueryBase)
            {
                string         orderField     = SystemFieldNames.UtcCreationDate;
                OrderDirection orderDirection = OrderDirection.Descending;

                if (textFolder.Sortable.HasValue && textFolder.Sortable.Value)
                {
                    orderField     = "Sequence";
                    orderDirection = OrderDirection.Descending;
                }

                if (orderDirection == OrderDirection.Ascending)
                {
                    return(textContents.OrderBy(orderField));
                }
                else
                {
                    return(textContents.OrderByDescending(orderField));
                }
            }
            return(textContents);
        }
예제 #11
0
 private static IContentQuery<TextContent> SortByField(string sortField, string sortDir, IContentQuery<TextContent> query)
 {
     if (string.IsNullOrEmpty(sortField))
     {
         query = query.DefaultOrder();
     }
     else
     {
         if (!string.IsNullOrEmpty(sortDir) && sortDir.ToLower() == "desc")
         {
             query = query.OrderByDescending(sortField);
         }
         else
         {
             query = query.OrderBy(sortField);
         }
     }
     return query;
 }
예제 #12
0
        public override NCMIS.ObjectModel.PathedCmisObjectList GetChildren(string repositoryId, string folderId, int?maxItems, int skipCount, string orderBy, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            Kooboo.CMS.Content.Models.Repository repository = new Models.Repository(repositoryId);
            IObjectService folderService = ObjectService.GetService(typeof(Folder));
            string         objectId      = folderId;

            folderService.TryPraseObjectId(objectId, out folderId);

            FolderType folderType = CmisFolderHelper.IdentifyFolderType(repository, folderId);

            PathedCmisObjectList           pathedList = new PathedCmisObjectList();
            IEnumerable <PathedCmisObject> children   = folderService.GetChildren(repositoryId, objectId, filter, includeRelationships)
                                                        .Select(it => new PathedCmisObject()
            {
                Object = it
            });

            var count = children.Count();

            pathedList.NumItems     = count.ToString();
            pathedList.HasMoreItems = false;

            //IEnumerable<ContentBase> contents = new ContentBase[0];
            if (folderType == FolderType.Content_Folder || folderType == FolderType.Media_Folder)
            {
                var folder = CmisFolderHelper.Parse(repository, folderId).AsActual();
                IContentQuery <ContentBase> contentQuery = null;
                if (folder is TextFolder)
                {
                    var textFolder = (TextFolder)folder;
                    var schema     = new Schema(repository, textFolder.SchemaName).AsActual();
                    contentQuery = textFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        foreach (var item in schema.Columns)
                        {
                            contentQuery = contentQuery.Or(new WhereContainsExpression(null, item.Name, filter));
                        }
                    }
                }
                else
                {
                    var mediaFolder = (TextFolder)folder;
                    contentQuery = mediaFolder.CreateQuery();
                    if (!string.IsNullOrEmpty(filter))
                    {
                        contentQuery = contentQuery.WhereContains("FileName", filter);
                    }
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    contentQuery = contentQuery.OrderBy(orderBy);
                }

                count = contentQuery.Count();
                var take = maxItems.HasValue ? maxItems.Value : count;
                pathedList.NumItems     = count.ToString();
                pathedList.HasMoreItems = count > count + take;

                children = children.Concat(contentQuery.Select(it => new PathedCmisObject()
                {
                    Object = ObjectConvertor.ToCmis((TextContent)(it), includeRelationships != IncludeRelationships.None)
                }).Take(take));
            }

            pathedList.Objects = children.ToArray();

            return(pathedList);
        }
예제 #13
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
            }));
        }