示例#1
0
        public void CourseSetupViewModel_filters_should_be_set()
        {
            // Given
            var categories = new[]
            {
                "Category 1",
                "Category 2"
            };
            var topics = new[]
            {
                "Topic 1",
                "Topic 2"
            };

            var expectedFilters = CourseStatisticsViewModelFilterOptions.GetFilterOptions(categories, topics);

            // When
            var model = new CourseSetupViewModel(
                courses,
                categories,
                topics,
                null,
                nameof(CourseStatistics.SearchableName),
                BaseSearchablePageViewModel.Ascending,
                null,
                2
                );

            // Then
            model.Filters.Should().BeEquivalentTo(expectedFilters);
            model.Courses.First().CourseName.Should().BeEquivalentTo("K");
        }
示例#2
0
        public IActionResult Index(
            string?searchString         = null,
            string?sortBy               = null,
            string sortDirection        = GenericSortingHelper.Ascending,
            string?existingFilterString = null,
            string?newFilterToAdd       = null,
            bool clearFilters           = false,
            int page         = 1,
            int?itemsPerPage = null
            )
        {
            sortBy ??= DefaultSortByOptions.Name.PropertyName;
            existingFilterString = FilteringHelper.GetFilterString(
                existingFilterString,
                newFilterToAdd,
                clearFilters,
                Request,
                CourseFilterCookieName,
                CourseStatusFilterOptions.IsActive.FilterValue
                );

            var centreId   = User.GetCentreId();
            var categoryId = User.GetAdminCourseCategoryFilter();

            var details = courseService.GetCentreCourseDetails(centreId, categoryId);

            var availableFilters = CourseStatisticsViewModelFilterOptions
                                   .GetFilterOptions(categoryId.HasValue ? new string[] { } : details.Categories, details.Topics).ToList();

            var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
                new SearchOptions(searchString),
                new SortOptions(sortBy, sortDirection),
                new FilterOptions(
                    existingFilterString,
                    availableFilters,
                    CourseStatusFilterOptions.IsActive.FilterValue
                    ),
                new PaginationOptions(page, itemsPerPage)
                );

            var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                details.Courses,
                searchSortPaginationOptions
                );

            var model = new CourseSetupViewModel(
                result,
                availableFilters,
                config
                );

            Response.UpdateFilterCookie(CourseFilterCookieName, result.FilterString);

            return(View(model));
        }
示例#3
0
        public void GetFilterOptions_correctly_sets_up_filters()
        {
            // When
            var result =
                CourseStatisticsViewModelFilterOptions.GetFilterOptions(filterableCategories, filterableTopics);

            // Then
            result.Should().BeEquivalentTo(
                new List <FilterViewModel>
            {
                expectedCategoriesFilterViewModel,
                expectedTopicsFilterViewModel,
                expectedStatusFilterViewModel,
                expectedVisibilityFilterViewModel
            }
                );
        }
示例#4
0
        public void GetFilterOptions_excludes_category_option_if_passed_no_categories()
        {
            // When
            var result =
                CourseStatisticsViewModelFilterOptions.GetFilterOptions(new string[] { }, filterableTopics);

            // Then
            result.Should().BeEquivalentTo(
                new List <FilterModel>
            {
                expectedTopicsFilterViewModel,
                expectedStatusFilterViewModel,
                expectedVisibilityFilterViewModel,
                expectedHasAdminFieldsFilterViewModel,
            }
                );
        }