Ejemplo n.º 1
0
        protected override Facets InitialiseViewModel(Rendering rendering, DataSource dataSource)
        {
            var searchContext    = additionalContexts.Get <ISearchContext>();
            var facetedResultSet = additionalContexts.Get <IFacetedResultSet>();
            var resultAspect     = additionalContexts.Get <IPagedResultsAspect>();

            var vm = new Facets();

            // show the sorting button only if there is more than 1 result (and sorting is enabled)
            vm.ShowMobileSorting = resultAspect.ResultsTotal > 1 && searchContext.CollectionSettings.SortOptions != null &&
                                   searchContext.CollectionSettings.SortOptions.Any();

            vm.ClearAllFacetsLink = selectedFacetsFactory.ClearAllFiltersUrl(searchContext);
            vm.SelectedFacets     = selectedFacetsFactory.CreateSelectedFacets(searchContext);
            vm.ShowKeywordFacet   = searchContext.CollectionSettings.ShowKeywordFacet;
            vm.AvailableFacets    = facetFactory.Create(searchContext, facetedResultSet.Facets);
            vm.ShowMobileFilters  = (resultAspect.ResultsTotal > 1 && vm.AvailableFacets.Any()) || vm.ShowKeywordFacet;

            vm.Query        = searchContext.Query.Value;
            vm.FormBaseUrl  = HttpContext.Current.Request.Url.AbsolutePath;
            vm.HiddenFields =
                searchContext.AsNameValueCollection()
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.Query)
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.PageNumber)
                .RemoveKey(Business.Search.Constants.SearchContext.Keys.Facets);
            return(vm);
        }
        protected override ResultsHeader InitialiseViewModel(Rendering rendering, DataSource dataSource)
        {
            var vm = Map <ResultsHeader>(CurrentItem);

            // get the results numbers
            var pagedRedultsAspect = contextStore.Get <IPagedResultsAspect>();

            vm.ResultsTotal   = pagedRedultsAspect.ResultsTotal;
            vm.ResultPageTo   = pagedRedultsAspect.PageNumber * pagedRedultsAspect.PageSize;
            vm.ResultPageFrom = vm.ResultPageTo - pagedRedultsAspect.PageSize + 1;
            if (vm.ResultPageTo > vm.ResultsTotal)
            {
                vm.ResultPageTo = vm.ResultsTotal;
            }

            // set paging related aspect
            var pagingContext = contextStore.Get <IPagingContextAspect>();

            if (pagingContext != null)
            {
                var largest = pagingContext.ValidPageSizes.Last();

                vm.ItemsPerPage =
                    pagingContext.ValidPageSizes.Select(x => new SelectOption
                {
                    Value      = x.ToString(),
                    Label      = (x == largest && vm.ResultsTotal < largest) ? "View all" : x.ToString(),
                    IsSelected = pagingContext.PageSize.Value == x
                });
            }

            // set sort order aspect
            var sortingContext = contextStore.Get <ISortingContextAspect>();

            vm.SortOrderOptions = sortingContext.SortOrderOptions.Select(x => new SelectOption
            {
                Value      = x.Key,
                Label      = x.Label,
                IsSelected = (string.Equals(x.Key, sortingContext.SortBy.Value.Key, StringComparison.InvariantCultureIgnoreCase))
            });

            // set search context aspect
            var searchContext = contextStore.Get <IQueryStringContextAspect>();

            vm.FormBaseUrl  = HttpContext.Current.Request.Url.AbsolutePath;
            vm.HiddenFields =
                searchContext.AsNameValueCollection()
                .RemoveKey(Constants.SearchContext.Keys.Sort)
                .RemoveKey(Constants.SearchContext.Keys.PageSize)
                .RemoveKey(Constants.SearchContext.Keys.PageNumber);

            return(vm);
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            var res = contextStore.Get <PagedSearchResult <ISearchResult> >();

            if (res != null && res.ResultsTotal > 0)
            {
                return(View("~/Modules/Search/Results/ResultsView.cshtml",
                            new Results(res.Results, Sitecore.Context.Item.ID.ToString(), resultPartialFactory)));
            }

            var searchContext = contextStore.Get <ISearchContext>();
            var vm            = new NoResults.NoResults(selectedFacetsFactory.AnyFiltersActive(searchContext), selectedFacetsFactory.ClearAllFiltersUrl(searchContext), Sitecore.Context.Item.ID.ToString());

            return(View("~/Modules/Search/Results/NoResults/NoResultsView.cshtml", vm));
        }
Ejemplo n.º 4
0
 protected override Pagination InitialiseViewModel(Rendering rendering, DataSource dataSource)
 {
     return(new Pagination(_contextStore.Get <IPagingContextAspect>(), _contextStore.Get <IPagedResultsAspect>()));
 }