protected virtual SearchPageViewModel GetPreviousPage(CreateSearchPaginationParam <TParam> param) { var searchCriteria = param.SearchParameters.Criteria; var previousPage = new SearchPageViewModel { DisplayName = LocalizationProvider .GetLocalizedString(new GetLocalizedParam { Category = "List-Search", Key = "B_Previous", CultureInfo = searchCriteria.CultureInfo }) }; if (param.CurrentPageIndex > 1) { searchCriteria.Page = param.CurrentPageIndex - 1; previousPage.Url = GenerateUrl(param); } else { previousPage.IsCurrentPage = true; } return(previousPage); }
protected virtual SearchPageViewModel GetNextPage(CreateSearchPaginationParam <TParam> param) { var searchCriteria = param.SearchParameters.Criteria; var nextPage = new SearchPageViewModel { DisplayName = LocalizationProvider .GetLocalizedString(new GetLocalizedParam { Category = "List-Search", Key = "B_Next", CultureInfo = searchCriteria.CultureInfo }) }; if (param.CurrentPageIndex < param.TotalNumberOfPages) { searchCriteria.Page = param.CurrentPageIndex + 1; nextPage.Url = GenerateUrl(param); } else { nextPage.IsCurrentPage = true; } return(nextPage); }
private SearchPaginationViewModel BuildPaginationForSearchResults( ProductSearchResult searchResult, TParam searchParam, int maxPages) { var totalCount = searchResult.TotalCount; var itemsPerPage = SearchConfiguration.MaxItemsPerPage; var totalPages = (int)Math.Ceiling((double)totalCount / itemsPerPage); var param = new CreateSearchPaginationParam <TParam> { SearchParameters = searchParam, CurrentPageIndex = searchParam.Criteria.Page, MaximumPages = SearchConfiguration.ShowAllPages ? totalPages : maxPages, TotalNumberOfPages = totalPages, CorrectedSearchTerms = searchResult.CorrectedSearchTerms }; var pages = GetPages(param); var pager = new SearchPaginationViewModel { PreviousPage = GetPreviousPage(param), NextPage = GetNextPage(param), CurrentPage = pages.FirstOrDefault(p => p.IsCurrentPage), Pages = pages, TotalNumberOfPages = totalPages }; return(pager); }
protected override string GenerateUrl(CreateSearchPaginationParam <SearchParam> param) { var cloneParam = (SearchParam)param.SearchParameters.Clone(); var nameValueCollection = SearchQueryUrlProvider.BuildSearchQueryString(new BuildSearchUrlParam() { SearchCriteria = cloneParam.Criteria }); return(UrlFormatter.ToUrlString(nameValueCollection)); }
protected override string GenerateUrl(CreateSearchPaginationParam <BrowsingSearchParam> param) { var cloneParam = (BrowsingSearchParam)param.SearchParameters.Clone(); if (cloneParam.CategoryFilters != null) { RemoveAppendedCategoryFacet(cloneParam); } var nameValueCollection = CategoryBrowsingUrlProvider.BuildSearchQueryString(new BuildSearchUrlParam() { SearchCriteria = cloneParam.Criteria }); return(UrlFormatter.ToUrlString(nameValueCollection)); }
protected override string GenerateUrl(CreateSearchPaginationParam <SearchParam> param) { if (param.SearchParameters == null) { throw new ArgumentNullException(nameof(param)); } if (param.SearchParameters.Criteria == null) { throw new ArgumentException("param.Criteria is null", nameof(param)); } return(SearchUrlProvider.BuildSearchUrl(new BuildSearchUrlParam { SearchCriteria = param.SearchParameters.Criteria, CorrectedSearchTerms = param.CorrectedSearchTerms })); }
protected virtual IEnumerable <SearchPageViewModel> GetPages(CreateSearchPaginationParam <TParam> param) { var pages = new List <SearchPageViewModel>(); var endPage = 0; var startPage = 0; if (param.TotalNumberOfPages < param.MaximumPages) { startPage = 1; endPage = param.TotalNumberOfPages; } else if (param.MaximumPages <= param.TotalNumberOfPages) { var maxPagesSplit = (int)Math.Floor((double)param.MaximumPages / 2); var potentialStartPage = param.CurrentPageIndex - maxPagesSplit; if (potentialStartPage < 1) { startPage = 1; endPage = param.MaximumPages; } else { //Can you explain what it does var potentialEndPage = param.CurrentPageIndex + maxPagesSplit - (param.MaximumPages % 2 == 0 ? 1 : 0); if (potentialEndPage > param.TotalNumberOfPages) { startPage = param.TotalNumberOfPages - param.MaximumPages + 1; endPage = param.TotalNumberOfPages; } else { startPage = potentialStartPage; endPage = potentialEndPage; } } } else if (param.MaximumPages > param.TotalNumberOfPages) { startPage = 1; endPage = param.TotalNumberOfPages; } for (var index = startPage; index <= endPage; index++) { var displayName = index.ToString(CultureInfo.InvariantCulture); param.SearchParameters.Criteria.Page = index; var searchUrl = GenerateUrl(param); var searchPage = new SearchPageViewModel { DisplayName = displayName, Url = searchUrl, IsCurrentPage = index == param.CurrentPageIndex, UrlPath = searchUrl.Replace(param.SearchParameters.Criteria.BaseUrl, string.Empty) }; pages.Add(searchPage); } return(pages); }
protected abstract string GenerateUrl(CreateSearchPaginationParam <TParam> param);