private async ValueTask BuildViewModel(BuildPartDisplayContext context, ListPart part, ListPartViewModel model, ContainedItemOptions options)
        {
            var settings = context.TypePartDefinition.GetSettings <ListPartSettings>();
            var pager    = new PagerParameters()
            {
                Page = 1, PageSize = settings.PageSize
            };
            await context.Updater.TryUpdateModelAsync <PagerParameters>(pager);

            var count = (pager.Page - 1) * pager.PageSize;
            var query = _session.Query <ContentItem, ContainedPartIndex>(x => x.ListContentItemId == part.ContentItem.ContentItemId);

            if (settings.EnableOrdering)
            {
                query.OrderBy(x => x.Order);
            }
            var searchQuery = query.With <ContentItemIndex>();

            ApplyContainedItemOptionsFilter(options, searchQuery);
            if (settings.EnableOrdering == false)
            {
                searchQuery.OrderByDescending(x => x.CreatedUtc);
            }

            var totalCount = await searchQuery.CountAsync();

            var items = await searchQuery.Skip(Math.Max(0, count.Value)).Take(pager.PageSize.Value).ListAsync();

            var contentTypes = settings.ContainedContentTypes ?? Enumerable.Empty <string>();

            model.ContainedContentTypeDefinitions = contentTypes.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType));
            model.ContentItems   = items;
            model.ListPart       = part;
            model.Context        = context;
            model.EnableOrdering = settings.EnableOrdering;
            model.Pager          = (await context.New.Pager(pager)).TotalItemCount(totalCount);
        }
Example #2
0
        private async Task PopulateListPartSearchOptions(ListPartViewModel model, ShapeDisplayContext context)
        {
            //We populate the SelectLists
            model.ListPartOptions.ContentStatuses = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = S["Latest"], Value = nameof(ContentsStatus.Latest)
                },
                new SelectListItem()
                {
                    Text = S["Owned by me"], Value = nameof(ContentsStatus.Owner)
                },
                new SelectListItem()
                {
                    Text = S["Published"], Value = nameof(ContentsStatus.Published)
                },
                new SelectListItem()
                {
                    Text = S["Unpublished"], Value = nameof(ContentsStatus.Draft)
                },
                new SelectListItem()
                {
                    Text = S["All versions"], Value = nameof(ContentsStatus.AllVersions)
                }
            };

            // model.ListPartOptions.ContentSorts = new List<SelectListItem>() {
            //     new SelectListItem() { Text = S["Recently created"], Value = nameof(ContentsOrder.Created) },
            //     new SelectListItem() { Text = S["Recently modified"], Value = nameof(ContentsOrder.Modified) },
            //     new SelectListItem() { Text = S["Recently published"], Value = nameof(ContentsOrder.Published) },
            //     new SelectListItem() { Text = S["Title"], Value = nameof(ContentsOrder.Title) }
            // };


            if (model.DataFillMode == DataFillMode.ContentTypes)
            {
                model.ListPartOptions.ContentTypeOptions = new List <SelectListItem>();
                model.ListPartOptions.ContentTypeOptions.Add(new SelectListItem()
                {
                    Text = S["All content types"], Value = ""
                });
                if (model.ContainedContentTypeDefinitions != null)
                {
                    foreach (var option in model.ContainedContentTypeDefinitions)
                    {
                        model.ListPartOptions.ContentTypeOptions.Add(new SelectListItem()
                        {
                            Text = option.DisplayName, Value = option.Name
                        });
                    }
                }
            }
            else if (model.DataFillMode == DataFillMode.WorkMaps)
            {
                model.ListPartOptions.ContentTypeOptions = new List <SelectListItem>();
                model.ListPartOptions.ContentTypeOptions.Add(new SelectListItem()
                {
                    Text = S["All content types"], Value = ""
                });

                /*for classroom content types
                 *
                 *   1. get assigned workmaps (eg μαθηματικά γυμνασιου, επικοινωνίες)   ListPartViewModel.SelectedWorkMapContentItemIds
                 *   2. for each workmap get contained content types   WorkMapPart.WorkMapTerms.each get contenttype
                 *   2.1 if context type is shortcut get the content type assigned to shortcut content item instance
                 *   3. end result will be a list of content types
                 *   4. store this list at the content item (class room ) level to show as options in search picklist see PartyPartHandler to save at part level when saving the contentitem
                 */

                var contentManager = context.ServiceProvider.GetService <IContentManager>();
                var selectedworkMapContentItems = model.SelectedWorkMapContentItems;
                var containedContentTypes       = new List <string>();
                foreach (var selectedworkMapContentItem in selectedworkMapContentItems)
                {
                    var workMapPart = selectedworkMapContentItem.Content.WorkMapPart; // .As<WorkMapPart>();
                    if (workMapPart != null)
                    {
                        var workMapTerms = workMapPart?.WorkMapTerms as JArray;
                        if (workMapTerms != null)
                        {
                            foreach (var workmapterm in workMapTerms)
                            {
                                await WalkTreeNode(workmapterm, containedContentTypes, contentManager);

                                /*var workMapTerm = (dynamic) workmapterm;
                                 * var termContentType = workMapTerm?.ContentType?.ToString();
                                 * if (termContentType == "ShortCut")
                                 * {
                                 *  //get shortcut contentitem ids and from there its content type and add to array
                                 *  //FindTerm(workmap.Content.WorkMapPart.WorkMapTerms as JArray, workmaptermContentItemId);
                                 *  string[] shortcutsContentItemIds = workMapTerm?.ShortCut?.ContentItem?.ContentItemIds?.ToObject<string[]>();
                                 *  var shortCutContentItems = (await contentManager.GetAsync(shortcutsContentItemIds))?.ToArray();
                                 *  if (shortCutContentItems != null)
                                 *  {
                                 *      if (shortCutContentItems.Any())
                                 *      {
                                 *          foreach (var contentItem in shortCutContentItems)
                                 *          {
                                 *              containedContentTypes.Add(contentItem.ContentType);
                                 *          }
                                 *      }
                                 *  }
                                 *
                                 *
                                 * }
                                 * else
                                 * {
                                 *
                                 *  containedContentTypes.Add(termContentType);
                                 * }*/
                            }
                        }
                    }
                }
                //get final contained types for workmaps
                var contentDefinitionManager = context.ServiceProvider.GetService <IContentDefinitionManager>();
                containedContentTypes.Add("Post");                                                                               //also add post by default
                var distinctContainedContentTypes = containedContentTypes.Except(new [] { "PlaceHolder" }).Distinct().ToArray(); //dont show the folder content type in picklist
                var workMapContentTypes           = GetContainedContentTypes(distinctContainedContentTypes, contentDefinitionManager);
                if (workMapContentTypes != null)
                {
                    foreach (var option in workMapContentTypes)
                    {
                        model.ListPartOptions.ContentTypeOptions.Add(
                            new SelectListItem()
                        {
                            Text = option.DisplayName, Value = option.Name
                        });
                    }
                }
            }
        }