private async Task <IEnumerable <PageVersion> > GetPagesAsync(GetPageRenderDetailsByIdRangeQuery query, IExecutionContext executionContext) { if (query.PublishStatus == PublishStatusQuery.SpecificVersion) { throw new InvalidOperationException("PublishStatusQuery.SpecificVersion not supported in GetPageRenderDetailsByIdRangeQuery"); } var dbResults = await _dbContext .PagePublishStatusQueries .AsNoTracking() .Include(v => v.PageVersion) .ThenInclude(v => v.Page) .Include(v => v.PageVersion) .ThenInclude(v => v.OpenGraphImageAsset) .Include(v => v.PageVersion) .ThenInclude(v => v.PageTemplate) .ThenInclude(t => t.PageTemplateRegions) .FilterActive() .FilterByStatus(query.PublishStatus, executionContext.ExecutionDate) .Where(v => query.PageIds.Contains(v.PageId)) .ToListAsync(); return(dbResults .Select(r => r.PageVersion)); }
public async Task <IDictionary <int, PageRenderDetails> > ExecuteAsync(GetPageRenderDetailsByIdRangeQuery query, IExecutionContext executionContext) { var dbPages = await GetPagesAsync(query, executionContext); var pageRoutesQuery = new GetPageRoutesByIdRangeQuery(GetAllPageIds(dbPages)); var pageRoutes = await _queryExecutor.ExecuteAsync(pageRoutesQuery, executionContext); var pages = dbPages .Select(p => _pageMapper.Map(p, pageRoutes)) .ToList(); MapPageRoutes(pages, pageRoutes); var dbPageBlocks = await QueryPageBlocks(pages).ToListAsync(); var allBlockTypes = await _queryExecutor.ExecuteAsync(new GetAllPageBlockTypeSummariesQuery(), executionContext); await _entityVersionPageBlockMapper.MapRegionsAsync( dbPageBlocks, pages.SelectMany(p => p.Regions), allBlockTypes, query.PublishStatus, executionContext ); return(pages.ToDictionary(d => d.PageId)); }
public async Task <IEnumerable <PageBlockTypeDisplayModelMapperOutput> > MapAsync( IReadOnlyCollection <PageBlockTypeDisplayModelMapperInput <PageListDataModel> > inputCollection, PublishStatusQuery publishStatus ) { var allPageIds = inputCollection.SelectManyDistinctModelValues(d => d.PageIds); // Page routes are cached and so are the quickest way to get simple page information. // If we needed more data we could use a different but slower query to get it. var query = new GetPageRenderDetailsByIdRangeQuery(allPageIds); var allPageRoutes = await _pageRepository.GetPageRenderDetailsByIdRangeAsync(query); var results = new List <PageBlockTypeDisplayModelMapperOutput>(inputCollection.Count); foreach (var input in inputCollection) { var output = new PageListDisplayModel(); // Here will get the relevant pages and order them correctly. // Additionally if we are viewing the published version of the page // then we make sure we only show published pages in the list. output.Pages = allPageRoutes .FilterAndOrderByKeys(input.DataModel.PageIds) .ToList(); // The CreateOutput() method wraps the mapped display // model with it's identifier so we can identify later on results.Add(input.CreateOutput(output)); } return(results); }
public async Task MapAsync( PageBlockTypeDisplayModelMapperContext <PageSnippetDataModel> context, PageBlockTypeDisplayModelMapperResult <PageSnippetDataModel> result ) { var allPageIds = context.Items.SelectDistinctModelValuesWithoutEmpty(m => m.PageId); // The PageRenderDetails object contains page, template and block data targeting // a specific version. We pass through the PublishStatusQuery to ensure this is // respected when querying related data i.e. if we're viewing a draft version then we // should also be able to see connected entities in draft status. var pagesQuery = new GetPageRenderDetailsByIdRangeQuery(allPageIds, context.PublishStatusQuery); var allPages = await _contentRepository .WithExecutionContext(context.ExecutionContext) .Pages() .GetByIdRange(allPageIds) .AsRenderDetails() .ExecuteAsync(); foreach (var item in context.Items) { var displayModel = new PageSnippetDisplayModel(); displayModel.Page = allPages.GetOrDefault(item.DataModel.PageId); // We have to code defensively here and bear in mind that the related // entities may be in draft status and may not be available when viewing // the live site. if (displayModel.Page != null) { // An example of querying the block data. Here we find all the raw html // page blocks and select all the data and strip out the html tags var strippedHtml = displayModel .Page .Regions .SelectMany(s => s.Blocks) .Select(m => m.DisplayModel as RawHtmlDisplayModel) .Where(m => m != null) .Select(m => _htmlSanitizer.StripHtml(m.RawHtml)); // This is just an example of working with the data, in reality this // would be much more dependent on your content. var combinedText = string.Join(Environment.NewLine, strippedHtml); displayModel.Snippet = TextFormatter.LimitWithElipsesOnWordBoundary(combinedText, 300); } // The CreateOutput() method wraps the mapped display // model with it's identifier so we can identify later on result.Add(item, displayModel); } }
public IEnumerable <IPermissionApplication> GetPermissions(GetPageRenderDetailsByIdRangeQuery query) { yield return(new PageReadPermission()); }
public IDomainRepositoryQueryContext <IDictionary <int, PageRenderDetails> > AsRenderDetails(PublishStatusQuery?publishStatus = null) { var query = new GetPageRenderDetailsByIdRangeQuery(_pageIds, publishStatus); return(DomainRepositoryQueryContextFactory.Create(query, ExtendableContentRepository)); }