private static async Task <PagerSlim> GetPagerAsync(IUpdateModel updater, int pageSize) { var pagerParameters = new PagerSlimParameters(); await updater.TryUpdateModelAsync(pagerParameters); var pager = new PagerSlim(pagerParameters, pageSize); return(pager); }
private async Task <PagerSlim> GetPagerAsync(IUpdateModel updater, ListPart part) { var settings = GetSettings(part); PagerSlimParameters pagerParameters = new PagerSlimParameters(); await updater.TryUpdateModelAsync(pagerParameters); PagerSlim pager = new PagerSlim(pagerParameters, settings.PageSize); return(pager); }
private async Task <PagerSlim> GetPagerSlimAsync(BuildPartDisplayContext context) { var settings = context.TypePartDefinition.GetSettings <ListPartSettings>(); var pagerParameters = new PagerSlimParameters(); await context.Updater.TryUpdateModelAsync(pagerParameters); var pager = new PagerSlim(pagerParameters, settings.PageSize); return(pager); }
private async Task <PagerSlim> GetPagerAsync(IUpdateModel updater, TaxonomyPart part) { //var settings = GetSettings(part); PagerSlimParameters pagerParameters = new PagerSlimParameters(); await updater.TryUpdateModelAsync(pagerParameters); PagerSlim pager = new PagerSlim(pagerParameters, 10); return(pager); }
private async Task <PagerSlim> GetPagerAsync(IUpdateModel updater, CrossReferencePart part, string partName) { var settings = GetSettings(part, partName); PagerSlimParameters pagerParameters = new PagerSlimParameters(); await updater.TryUpdateModelAsync(pagerParameters); PagerSlim pager = new PagerSlim(pagerParameters, settings.PageSize); return(pager); }
private async Task <object> GetPagerObjectAsync(IUpdateModel updater, CrossReferencePart part, string partName) { var settings = GetSettings(part, partName); // if (settings.PagerSlimDisabled) // { // var pagerParameters = new PagerParameters(); // await updater.TryUpdateModelAsync(pagerParameters); // // var pager = new Pager(pagerParameters, settings.PageSize); // // return pager; // } // else // { var pagerParameters = new PagerSlimParameters(); await updater.TryUpdateModelAsync(pagerParameters); var pager = new PagerSlim(pagerParameters, settings.PageSize); return(pager); // } }
/// <summary> /// Constructs a new pager. /// </summary> /// <param name="site">The site settings.</param> /// <param name="pagerParameters">The pager parameters.</param> public PagerSlim(PagerSlimParameters pagerParameters, int pageSize) : this(pagerParameters.Before, pagerParameters.After, pageSize) { }
public async Task <IActionResult> Search(SearchIndexViewModel viewModel, PagerSlimParameters pagerParameters) { var permissionsProvider = _permissionProviders.FirstOrDefault(x => x.GetType().FullName == "OrchardCore.Lucene.Permissions"); var permissions = await permissionsProvider.GetPermissionsAsync(); var siteSettings = await _siteService.GetSiteSettingsAsync(); var searchSettings = siteSettings.As <LuceneSettings>(); if (permissions.FirstOrDefault(x => x.Name == "QueryLucene" + searchSettings.SearchIndex + "Index") != null) { if (!await _authorizationService.AuthorizeAsync(User, permissions.FirstOrDefault(x => x.Name == "QueryLucene" + searchSettings.SearchIndex + "Index"))) { return(this.ChallengeOrForbid()); } } else { _logger.LogInformation("Couldn't execute search. The search index doesn't exist."); return(BadRequest("Search is not configured.")); } if (searchSettings.SearchIndex != null && !_luceneIndexProvider.Exists(searchSettings.SearchIndex)) { _logger.LogInformation("Couldn't execute search. The search index doesn't exist."); return(BadRequest("Search is not configured.")); } var luceneSettings = await _luceneIndexingService.GetLuceneSettingsAsync(); if (luceneSettings == null || luceneSettings?.DefaultSearchFields == null) { _logger.LogInformation("Couldn't execute search. No Lucene settings was defined."); return(BadRequest("Search is not configured.")); } var luceneIndexSettings = await _luceneIndexSettingsService.GetSettingsAsync(searchSettings.SearchIndex); if (luceneIndexSettings == null) { _logger.LogInformation($"Couldn't execute search. No Lucene index settings was defined for ({searchSettings.SearchIndex}) index."); return(BadRequest($"Search index ({searchSettings.SearchIndex}) is not configured.")); } if (string.IsNullOrWhiteSpace(viewModel.Terms)) { return(View(new SearchIndexViewModel { SearchForm = new SearchFormViewModel("Search__Form") { }, })); } var pager = new PagerSlim(pagerParameters, siteSettings.PageSize); // We Query Lucene index var analyzer = _luceneAnalyzerManager.CreateAnalyzer(await _luceneIndexSettingsService.GetIndexAnalyzerAsync(luceneIndexSettings.IndexName)); var queryParser = new MultiFieldQueryParser(LuceneSettings.DefaultVersion, luceneSettings.DefaultSearchFields, analyzer); var query = queryParser.Parse(QueryParser.Escape(viewModel.Terms)); // Fetch one more result than PageSize to generate "More" links var start = 0; var end = pager.PageSize + 1; if (pagerParameters.Before != null) { start = Convert.ToInt32(pagerParameters.Before) - pager.PageSize - 1; end = Convert.ToInt32(pagerParameters.Before); } else if (pagerParameters.After != null) { start = Convert.ToInt32(pagerParameters.After); end = Convert.ToInt32(pagerParameters.After) + pager.PageSize + 1; } var contentItemIds = await _searchQueryService.ExecuteQueryAsync(query, searchSettings.SearchIndex, start, end); // We Query database to retrieve content items. IQuery <ContentItem> queryDb; if (luceneIndexSettings.IndexLatest) { queryDb = _session.Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId.IsIn(contentItemIds) && x.Latest == true) .Take(pager.PageSize + 1); } else { queryDb = _session.Query <ContentItem, ContentItemIndex>() .Where(x => x.ContentItemId.IsIn(contentItemIds) && x.Published == true) .Take(pager.PageSize + 1); } var containedItems = await queryDb.ListAsync(); // We set the PagerSlim before and after links if (pagerParameters.After != null || pagerParameters.Before != null) { if (start + 1 > 1) { pager.Before = (start + 1).ToString(); } else { pager.Before = null; } } if (containedItems.Count() == pager.PageSize + 1) { pager.After = (end - 1).ToString(); } else { pager.After = null; } var model = new SearchIndexViewModel { Terms = viewModel.Terms, SearchForm = new SearchFormViewModel("Search__Form") { Terms = viewModel.Terms }, SearchResults = new SearchResultsViewModel("Search__Results") { ContentItems = containedItems.Take(pager.PageSize) }, Pager = (await New.PagerSlim(pager)).UrlParams(new Dictionary <string, string>() { { "Terms", viewModel.Terms } }) }; return(View(model)); }
public async Task <IActionResult> UpdateContentItemOrders(string containerId, int oldIndex, int newIndex, PagerSlimParameters pagerSlimParameters, int pageSize) { var pager = new PagerSlim(pagerSlimParameters, pageSize); // Reverse pager as it represents the next page(s), rather than current page if (pager.Before != null && pager.After != null) { var beforeValue = int.Parse(pager.Before); beforeValue -= 1; var afterValue = int.Parse(pager.After); afterValue += 1; pager.Before = afterValue.ToString(); pager.After = beforeValue.ToString(); } else if (pager.Before != null) { var beforeValue = int.Parse(pager.Before); beforeValue -= 1; pager.Before = null; pager.After = beforeValue.ToString(); } else if (pager.After != null) { var afterValue = int.Parse(pager.After); afterValue += 1; pager.After = null; pager.Before = afterValue.ToString(); } // Include draft items. var pageOfContentItems = (await _containerService.QueryContainedItemsAsync(containerId, true, pager, false)).ToList(); if (pageOfContentItems == null || !pageOfContentItems.Any()) { return(NotFound()); } foreach (var pagedContentItem in pageOfContentItems) { if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.PublishContent, pagedContentItem)) { return(Forbid()); } } var currentOrderOfFirstItem = pageOfContentItems.FirstOrDefault().As <ContainedPart>().Order; var contentItem = pageOfContentItems[oldIndex]; pageOfContentItems.Remove(contentItem); pageOfContentItems.Insert(newIndex, contentItem); await _containerService.UpdateContentItemOrdersAsync(pageOfContentItems, currentOrderOfFirstItem); return(Ok()); }