Exemplo n.º 1
0
        public ActionResult ExportContent(ListExportContentsViewModel model, PagerParameters pagerParameters)
        {
            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            var versionOptions = VersionOptions.Latest;

            switch (model.Options.ContentsStatus)
            {
            case ContentsStatus.Published:
                versionOptions = VersionOptions.Published;
                break;

            case ContentsStatus.Draft:
                versionOptions = VersionOptions.Draft;
                break;

            case ContentsStatus.AllVersions:
                versionOptions = VersionOptions.AllVersions;
                break;

            default:
                versionOptions = VersionOptions.Latest;
                break;
            }

            var query = _contentManager.Query(versionOptions, GetListableTypes(false).Select(ctd => ctd.Name).ToArray());

            if ("--content--".Equals(model.TypeName, StringComparison.InvariantCultureIgnoreCase))
            {
                model.HasCommonPartOrdering = true;
                model.TypeDisplayName       = "--content--";
            }
            else if (!string.IsNullOrEmpty(model.TypeName))
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName);
                if (contentTypeDefinition == null)
                {
                    return(HttpNotFound());
                }

                model.TypeDisplayName = !string.IsNullOrWhiteSpace(contentTypeDefinition.DisplayName)
                                            ? contentTypeDefinition.DisplayName
                                            : contentTypeDefinition.Name;
                query = query.ForType(model.TypeName);
                model.HasCommonPartOrdering = contentTypeDefinition.Parts.Any(x => "CommonPart".Equals(x.PartDefinition.Name));
            }
            else
            {
                model.HasCommonPartOrdering = false;
            }

            if (!String.IsNullOrWhiteSpace(model.Options.SelectedCulture))
            {
                query = _cultureFilter.FilterCulture(query, model.Options.SelectedCulture);
            }

            if (model.HasCommonPartOrdering)
            {
                switch (model.Options.OrderBy)
                {
                case ContentsOrder.Modified:
                    query = query.OrderByDescending <CommonPartRecord>(cr => cr.ModifiedUtc);
                    break;

                case ContentsOrder.Published:
                    query = query.OrderByDescending <CommonPartRecord>(cr => cr.PublishedUtc);
                    break;

                case ContentsOrder.Created:
                    query = query.OrderByDescending <CommonPartRecord>(cr => cr.CreatedUtc);
                    break;
                }
            }

            model.Options.SelectedFilter = model.TypeName;
            model.Options.FilterOptions  = GetListableTypes(false)
                                           .Select(ctd => new KeyValuePair <string, string>(ctd.Name, ctd.DisplayName))
                                           .ToList().OrderBy(kvp => kvp.Value);

            model.Options.Cultures = _cultureManager.ListCultures();

            var maxPagedCount = _siteService.GetSiteSettings().MaxPagedCount;

            if (maxPagedCount > 0 && pager.PageSize > maxPagedCount)
            {
                pager.PageSize = maxPagedCount;
            }
            var pagerShape         = Shape.Pager(pager).TotalItemCount(maxPagedCount > 0 ? maxPagedCount : query.Count());
            var pageOfContentItems = query.Slice(pager.GetStartIndex(), pager.PageSize).ToList();

            var list = Shape.List();

            list.AddRange(pageOfContentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));

            var viewModel = Shape.ViewModel()
                            .ContentItems(list)
                            .Pager(pagerShape)
                            .Options(model.Options)
                            .TypeDisplayName(model.TypeDisplayName ?? "")
                            .HasCommonPartOrdering(model.HasCommonPartOrdering);

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult List(ListContentsViewModel model, PagerParameters pagerParameters)
        {
            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            var versionOptions = VersionOptions.Latest;

            switch (model.Options.ContentsStatus)
            {
            case ContentsStatus.Published:
                versionOptions = VersionOptions.Published;
                break;

            case ContentsStatus.Draft:
                versionOptions = VersionOptions.Draft;
                break;

            case ContentsStatus.AllVersions:
                versionOptions = VersionOptions.AllVersions;
                break;

            default:
                versionOptions = VersionOptions.Latest;
                break;
            }

            var query = _contentManager.Query(versionOptions, GetListableTypes(false).Select(ctd => ctd.Name).ToArray());
            ContentTypeDefinition contentTypeDefinition = null;

            if (!string.IsNullOrEmpty(model.TypeName))
            {
                contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName);
                if (contentTypeDefinition == null)
                {
                    return(HttpNotFound());
                }

                model.TypeDisplayName = !string.IsNullOrWhiteSpace(contentTypeDefinition.DisplayName)
                                            ? contentTypeDefinition.DisplayName
                                            : contentTypeDefinition.Name;

                // We display a specific type even if it's not listable so that admin pages
                // can reuse the Content list page for specific types.
                query = _contentManager.Query(versionOptions, model.TypeName);
            }

            switch (model.Options.OrderBy)
            {
            case ContentsOrder.Modified:
                //query = query.OrderByDescending<ContentPartRecord, int>(ci => ci.ContentItemRecord.Versions.Single(civr => civr.Latest).Id);
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.ModifiedUtc);
                break;

            case ContentsOrder.Published:
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.PublishedUtc);
                break;

            case ContentsOrder.Created:
                //query = query.OrderByDescending<ContentPartRecord, int>(ci => ci.Id);
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.CreatedUtc);
                break;
            }

            if (!String.IsNullOrWhiteSpace(model.Options.SelectedCulture))
            {
                query = _cultureFilter.FilterCulture(query, model.Options.SelectedCulture);
            }

            if (model.Options.ContentsStatus == ContentsStatus.Owner)
            {
                query = query.Where <CommonPartRecord>(cr => cr.OwnerId == Services.WorkContext.CurrentUser.Id);
            }

            model.Options.SelectedFilter = model.TypeName;
            model.Options.FilterOptions  = GetListableTypes(false)
                                           .Select(ctd => new KeyValuePair <string, string>(ctd.Name, ctd.DisplayName))
                                           .ToList().OrderBy(kvp => kvp.Value);

            model.Options.Cultures = _cultureManager.ListCultures();

            var maxPagedCount = _siteService.GetSiteSettings().MaxPagedCount;

            if (maxPagedCount > 0 && pager.PageSize > maxPagedCount)
            {
                pager.PageSize = maxPagedCount;
            }
            var pagerShape         = Shape.Pager(pager).TotalItemCount(maxPagedCount > 0 ? maxPagedCount : query.Count());
            var pageOfContentItems = query.Slice(pager.GetStartIndex(), pager.PageSize).ToList();

            var list = Shape.List();

            list.AddRange(pageOfContentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));

            var viewModel = Shape.ViewModel(ContentType: contentTypeDefinition)
                            .ContentItems(list)
                            .Pager(pagerShape)
                            .Options(model.Options)
                            .TypeDisplayName(model.TypeDisplayName ?? "");

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult Index(ListContentsViewModel model, PagerParameters pagerParameters, string part, string field, string type, int hostId)
        {
            // Check Permissions to Edit the content hosting shortcodes
            if (hostId > 0 && !Services.Authorizer.Authorize(Permissions.EditContent, Services.ContentManager.Get(hostId)))
            {
                Services.Notifier.Add(NotifyType.Error, T("Cannot add shortcode."));
                return(new HttpUnauthorizedResult());
            }

            var menuItems             = _navigationManager.BuildMenu("content-picker").ToList();
            var contentPickerMenuItem = menuItems.FirstOrDefault();

            if (contentPickerMenuItem == null)
            {
                return(HttpNotFound());
            }

            if (contentPickerMenuItem.Items.All(x => x.Text.TextHint != "Recent Content"))
            {
                // the default tab should not be displayed, redirect to the next one
                var root = menuItems.FirstOrDefault();
                if (root == null)
                {
                    return(HttpNotFound());
                }

                var firstChild = root.Items.First();
                if (firstChild == null)
                {
                    return(HttpNotFound());
                }

                var routeData   = new RouteValueDictionary(firstChild.RouteValues);
                var queryString = Request.QueryString;
                foreach (var key in queryString.AllKeys)
                {
                    if (!String.IsNullOrEmpty(key))
                    {
                        routeData[key] = queryString[key];
                    }
                }

                return(RedirectToRoute(routeData));
            }

            // Filters the contents by ContentType or filters at least "Listable" content types
            ContentShortCodeSettings settings;
            var types = "";

            if (!string.IsNullOrWhiteSpace(part) && string.IsNullOrWhiteSpace(field))
            {
                ContentTypePartDefinition defintion = _contentDefinitionManager.GetTypeDefinition(type).Parts.FirstOrDefault(x => x.PartDefinition.Name == part);
                if (defintion != null)
                {
                    settings = defintion.Settings.GetModel <ContentShortCodeSettings>();
                    types    = settings.DisplayedContentTypes;
                }
            }
            else if (!string.IsNullOrWhiteSpace(part) && !string.IsNullOrWhiteSpace(field))
            {
                ContentPartFieldDefinition defintion = _contentDefinitionManager.GetTypeDefinition(type)
                                                       .Parts.Where(x => x.PartDefinition.Name == part)
                                                       .SelectMany(x => x.PartDefinition.Fields)
                                                       .FirstOrDefault(x => x.Name == field);

                settings = defintion.Settings.GetModel <ContentShortCodeSettings>();
                types    = settings.DisplayedContentTypes;
            }



            IEnumerable <ContentTypeDefinition> contentTypes;

            if (!String.IsNullOrEmpty(types))
            {
                var rawTypes = types.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                contentTypes = _contentDefinitionManager
                               .ListTypeDefinitions()
                               .Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)) || rawTypes.Contains(x.Name))
                               .ToArray();
            }
            else
            {
                contentTypes = GetListableTypes(false).ToList();
            }

            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            var query = Services.ContentManager.Query(VersionOptions.Latest, contentTypes.Select(ctd => ctd.Name).ToArray());

            if (!string.IsNullOrEmpty(model.Options.SelectedFilter))
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.Options.SelectedFilter);
                if (contentTypeDefinition == null)
                {
                    return(HttpNotFound());
                }

                model.TypeDisplayName = !string.IsNullOrWhiteSpace(contentTypeDefinition.DisplayName)
                                            ? contentTypeDefinition.DisplayName
                                            : contentTypeDefinition.Name;
                query = query.ForType(model.Options.SelectedFilter);
            }

            switch (model.Options.OrderBy)
            {
            case ContentsOrder.Modified:
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.ModifiedUtc);
                break;

            case ContentsOrder.Published:
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.PublishedUtc);
                break;

            case ContentsOrder.Created:
                query = query.OrderByDescending <CommonPartRecord>(cr => cr.CreatedUtc);
                break;
            }

            if (!String.IsNullOrWhiteSpace(model.Options.SelectedCulture))
            {
                query = _cultureFilter.FilterCulture(query, model.Options.SelectedCulture);
            }

            model.Options.FilterOptions = contentTypes
                                          .Select(ctd => new KeyValuePair <string, string>(ctd.Name, ctd.DisplayName))
                                          .ToList().OrderBy(kvp => kvp.Value);

            model.Options.Cultures = _cultureManager.ListCultures();

            var pagerShape         = Services.New.Pager(pager).TotalItemCount(query.Count());
            var pageOfContentItems = query.Slice(pager.GetStartIndex(), pager.PageSize).ToList();
            var list = Services.New.List();

            list.AddRange(pageOfContentItems.Select(ci => Services.ContentManager.BuildDisplay(ci, "SummaryAdmin")));

            foreach (IShape item in list.Items)
            {
                item.Metadata.Type = "ContentPicker";
            }

            var tab = Services.New.RecentContentTab()
                      .ContentItems(list)
                      .Pager(pagerShape)
                      .Options(model.Options)
                      .TypeDisplayName(model.TypeDisplayName ?? "");

            // retain the parameter in the pager links
            RouteData.Values["Options.SelectedFilter"]  = model.Options.SelectedFilter;
            RouteData.Values["Options.OrderBy"]         = model.Options.OrderBy.ToString();
            RouteData.Values["Options.ContentsStatus"]  = model.Options.ContentsStatus.ToString();
            RouteData.Values["Options.SelectedCulture"] = model.Options.SelectedCulture;

            return(new ShapeResult(this, Services.New.ShortCodes_ContentPicker().Tab(tab)));
        }