public IActionResult Available( string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, int page = 1 ) { sortBy ??= CourseSortByOptions.Name.PropertyName; var availableCourses = courseDataService.GetAvailableCourses( User.GetCandidateIdKnownNotNull(), User.GetCentreId() ); var bannerText = GetBannerText(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( availableCourses, searchSortPaginationOptions ); var model = new AvailablePageViewModel( result, bannerText ); return(View("Available/Available", model)); }
public IActionResult Index(int page = 1) { var adminId = User.GetAdminId() !.Value; var unacknowledgedNotifications = systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList(); if (unacknowledgedNotifications.Count > 0) { Response.Cookies.SetSkipSystemNotificationCookie(adminId, clockService.UtcNow); } else if (Request.Cookies.HasSkippedNotificationsCookie(adminId)) { Response.Cookies.DeleteSkipSystemNotificationCookie(); } const int numberOfNotificationsPerPage = 1; var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, null, null, new PaginationOptions(page, numberOfNotificationsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( unacknowledgedNotifications, searchSortPaginationOptions ); var model = new SystemNotificationsViewModel(result); return(View(model)); }
public void SearchFilterSortAndPaginate_with_filter_only_returns_expected_result() { // Given var availableFilters = new List <FilterModel> { new FilterModel( "Name", "Name", new List <FilterOptionModel> { new FilterOptionModel("A", "Name|Name|A", FilterStatus.Default) } ), }; var options = new SearchSortFilterAndPaginateOptions( null, null, new FilterOptions("Name|Name|A", availableFilters), null ); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(new[] { new SortableItem("A", 10) }, 1, 1, int.MaxValue, 1, true), null, null, null, "Name|Name|A" ); result.Should().BeEquivalentTo(expectedResult); }
public void SearchFilterSortAndPaginate_with_low_configured_item_limit_returns_javascript_enabled_false() { // Given var options = new SearchSortFilterAndPaginateOptions( null, null, null, new PaginationOptions(1, 8) ); A.CallTo(() => configuration["JavascriptSearchSortFilterPaginateItemLimit"]).Returns("2"); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(allItems.Take(8), 1, 2, 8, 10, false), null, null, null, null ); result.Should().BeEquivalentTo(expectedResult); }
private async Task <IActionResult> ReturnSignpostingRecommendedLearningView( int selfAssessmentId, int candidateId, int page, string?searchString ) { var assessment = selfAssessmentService.GetSelfAssessmentForCandidateById(candidateId, selfAssessmentId) !; var(recommendedResources, apiIsAccessible) = await recommendedLearningService.GetRecommendedLearningForSelfAssessment(selfAssessmentId, candidateId); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(nameof(RecommendedResource.RecommendationScore), GenericSortingHelper.Descending), null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( recommendedResources, searchSortPaginationOptions ); var model = new RecommendedLearningViewModel( assessment, result, apiIsAccessible ); return(View("RecommendedLearning", model)); }
public IActionResult LearningLog( int progressId, DelegateAccessRoute accessedVia, string?sortBy = null, string sortDirection = GenericSortingHelper.Descending ) { sortBy ??= LearningLogSortByOptions.When.PropertyName; var learningLog = courseService.GetLearningLogDetails(progressId); if (learningLog == null) { return(NotFound()); } var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, new SortOptions(sortBy, sortDirection), null, null ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( learningLog.Entries, searchSortPaginationOptions ); var model = new LearningLogViewModel(accessedVia, learningLog, result); return(View(model)); }
public SearchSortFilterPaginationResult <T> SearchFilterSortAndPaginate <T>( IEnumerable <T> items, SearchSortFilterAndPaginateOptions searchSortFilterAndPaginateOptions ) where T : BaseSearchableItem { var allItems = items.ToList(); var itemsToReturn = allItems; string?appliedFilterString = null; var javascriptSearchSortFilterPaginateShouldBeEnabled = allItems.Count <= configuration.GetJavascriptSearchSortFilterPaginateItemLimit(); if (searchSortFilterAndPaginateOptions.SearchOptions != null) { itemsToReturn = (searchSortFilterAndPaginateOptions.SearchOptions.UseTokeniseScorer ? GenericSearchHelper.SearchItemsUsingTokeniseScorer( itemsToReturn, searchSortFilterAndPaginateOptions.SearchOptions.SearchString, searchSortFilterAndPaginateOptions.SearchOptions.SearchMatchCutoff ) : GenericSearchHelper.SearchItems( itemsToReturn, searchSortFilterAndPaginateOptions.SearchOptions.SearchString, searchSortFilterAndPaginateOptions.SearchOptions.SearchMatchCutoff )).ToList(); } if (searchSortFilterAndPaginateOptions.FilterOptions != null) { var filteringReturnTuple = FilteringHelper.FilterOrResetFilterToDefault( itemsToReturn, searchSortFilterAndPaginateOptions.FilterOptions ); itemsToReturn = filteringReturnTuple.filteredItems.ToList(); appliedFilterString = filteringReturnTuple.appliedFilterString; } if (searchSortFilterAndPaginateOptions.SortOptions != null) { itemsToReturn = GenericSortingHelper.SortAllItems( itemsToReturn.AsQueryable(), searchSortFilterAndPaginateOptions.SortOptions.SortBy, searchSortFilterAndPaginateOptions.SortOptions.SortDirection ).ToList(); } var paginateResult = PaginateItems( itemsToReturn, searchSortFilterAndPaginateOptions.PaginationOptions, javascriptSearchSortFilterPaginateShouldBeEnabled ); return(new SearchSortFilterPaginationResult <T>( paginateResult, searchSortFilterAndPaginateOptions.SearchOptions?.SearchString, searchSortFilterAndPaginateOptions.SortOptions?.SortBy, searchSortFilterAndPaginateOptions.SortOptions?.SortDirection, appliedFilterString )); }
public IActionResult Index( int page = 1, string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int?itemsPerPage = null ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, DelegateFilterCookieName, DelegateActiveStatusFilterOptions.IsActive.FilterValue ); var centreId = User.GetCentreId(); var jobGroups = jobGroupsDataService.GetJobGroupsAlphabetical(); var customPrompts = promptsService.GetCentreRegistrationPrompts(centreId).ToList(); var delegateUsers = userDataService.GetDelegateUserCardsByCentreId(centreId); var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0); var availableFilters = AllDelegatesViewModelFilterOptions.GetAllDelegatesFilterViewModels( jobGroups, promptsWithOptions ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), new FilterOptions( existingFilterString, availableFilters, DelegateActiveStatusFilterOptions.IsActive.FilterValue ), new PaginationOptions(page, itemsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( delegateUsers, searchSortPaginationOptions ); var model = new AllDelegatesViewModel( result, customPrompts, availableFilters ); Response.UpdateFilterCookie(DelegateFilterCookieName, result.FilterString); return(View(model)); }
public IActionResult Index( int brandId, int page = 1, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false ) { var brand = brandsService.GetPublicBrandById(brandId); if (brand == null) { return(NotFound()); } sortBy ??= DefaultSortByOptions.Name.PropertyName; existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, BrandCoursesFilterCookieName ); var tutorials = tutorialService.GetPublicTutorialSummariesForBrand(brandId); var applications = courseService.GetApplicationsThatHaveSectionsByBrandId(brandId).ToList(); var categories = applications.Select(x => x.CategoryName).Distinct().OrderBy(x => x).ToList(); var topics = applications.Select(x => x.CourseTopic).Distinct().OrderBy(x => x).ToList(); var availableFilters = LearningContentViewModelFilterOptions .GetFilterOptions(categories, topics).ToList(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, new SortOptions(sortBy, sortDirection), new FilterOptions( existingFilterString, availableFilters ), new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( applications, searchSortPaginationOptions ); var model = new LearningContentViewModel(result, availableFilters, brand, tutorials); Response.UpdateFilterCookie(BrandCoursesFilterCookieName, result.FilterString); return(View(model)); }
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)); }
public IActionResult AddCourseToGroupSelectCourse( int groupId, string?searchString = null, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int page = 1 ) { existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, GroupAddCourseFilterCookieName ); var centreId = User.GetCentreId(); var adminCategoryFilter = User.GetAdminCourseCategoryFilter(); var courses = courseService.GetEligibleCoursesToAddToGroup(centreId, adminCategoryFilter, groupId).ToList(); var categories = courseService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId); var topics = courseService.GetTopicsForCentreAndCentrallyManagedCourses(centreId); var groupName = groupsService.GetGroupName(groupId, centreId); var availableFilters = (adminCategoryFilter == null ? AddCourseToGroupViewModelFilterOptions.GetAllCategoriesFilters(categories, topics) : AddCourseToGroupViewModelFilterOptions.GetSingleCategoryFilters(courses)).ToList(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(nameof(CourseAssessmentDetails.CourseName), GenericSortingHelper.Ascending), new FilterOptions(existingFilterString, availableFilters), new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( courses, searchSortPaginationOptions ); var model = new AddCourseToGroupCoursesViewModel( result, availableFilters, adminCategoryFilter, groupId, groupName ! ); Response.UpdateFilterCookie(GroupAddCourseFilterCookieName, result.FilterString); return(View(model)); }
public IActionResult MyStaffList( string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, int page = 1 ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; var adminId = GetAdminID(); var loggedInUserId = User.GetAdminId(); var centreId = GetCentreId(); var loggedInAdminUser = userDataService.GetAdminUserById(loggedInUserId !.GetValueOrDefault()); var centreRegistrationPrompts = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); var supervisorDelegateDetails = supervisorService.GetSupervisorDelegateDetailsForAdminId(adminId); var isSupervisor = User.GetCustomClaimAsBool(CustomClaimTypes.IsSupervisor) ?? false; var supervisorDelegateDetailViewModels = supervisorDelegateDetails.Select( supervisor => { return(new SupervisorDelegateDetailViewModel( supervisor, new ReturnPageQuery( page, $"{supervisor.ID}-card", PaginationOptions.DefaultItemsPerPage, searchString, sortBy, sortDirection ), isSupervisor )); } ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( supervisorDelegateDetailViewModels, searchSortPaginationOptions ); var model = new MyStaffListViewModel( loggedInAdminUser, result, centreRegistrationPrompts ); ModelState.ClearErrorsForAllFieldsExcept("DelegateEmail"); return(View("MyStaffList", model)); }
public async Task <IActionResult> Index( int page = 1, string?searchString = null, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int?itemsPerPage = null ) { if (!await featureManager.IsEnabledAsync(FeatureFlags.RefactoredFindYourCentrePage)) { var model = new FindYourCentreViewModel(configuration); return(View("Index", model)); } existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, FindCentreFilterCookieName ); var centreSummaries = centresService.GetAllCentreSummariesForFindCentre(); var regions = regionDataService.GetRegionsAlphabetical(); var availableFilters = FindYourCentreViewModelFilterOptions .GetFindCentreFilterModels(regions).ToList(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString, searchMatchCutoff: 90), null, new FilterOptions( existingFilterString, availableFilters ), new PaginationOptions(page, itemsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( centreSummaries, searchSortPaginationOptions ); var refactoredModel = new RefactoredFindYourCentreViewModel( result, availableFilters ); Response.UpdateFilterCookie(FindCentreFilterCookieName, result.FilterString); return(View("RefactoredFindYourCentre", refactoredModel)); }
public IActionResult SelectDelegate( int groupId, string?searchString = null, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int page = 1 ) { existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, AddGroupDelegateCookieName ); var centreId = User.GetCentreId(); var jobGroups = jobGroupsService.GetJobGroupsAlphabetical().ToList(); var customPrompts = promptsService.GetCentreRegistrationPrompts(centreId).ToList(); var delegateUsers = userService.GetDelegatesNotRegisteredForGroupByGroupId(groupId, centreId); var groupName = groupsService.GetGroupName(groupId, centreId); var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0); var availableFilters = GroupDelegatesViewModelFilterOptions.GetAddGroupDelegateFilterViewModels( jobGroups, promptsWithOptions ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions( DefaultSortByOptions.Name.PropertyName, GenericSortingHelper.Ascending ), new FilterOptions(existingFilterString, availableFilters), new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( delegateUsers, searchSortPaginationOptions ); var model = new AddGroupDelegateViewModel( result, availableFilters, customPrompts, groupId, groupName ! ); Response.UpdateFilterCookie(AddGroupDelegateCookieName, result.FilterString); return(View(model)); }
public IActionResult Index( EmailDelegatesFormData formData, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false ) { var delegateUsers = GetDelegateUserCards(); if (!ModelState.IsValid) { var newFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, EmailDelegateFilterCookieName ); var jobGroups = jobGroupsDataService.GetJobGroupsAlphabetical(); var customPrompts = promptsService.GetCentreRegistrationPrompts(User.GetCentreId()); var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0); var availableFilters = EmailDelegatesViewModelFilterOptions.GetEmailDelegatesFilterModels( jobGroups, promptsWithOptions ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, null, new FilterOptions(newFilterString, availableFilters), null ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( delegateUsers, searchSortPaginationOptions ); var viewModel = new EmailDelegatesViewModel(result, availableFilters, formData); return(View(viewModel)); } var selectedUsers = delegateUsers.Where(user => formData.SelectedDelegateIds !.Contains(user.Id)).ToList(); var emailDate = new DateTime(formData.Year !.Value, formData.Month !.Value, formData.Day !.Value); var baseUrl = config.GetAppRootPath(); passwordResetService.SendWelcomeEmailsToDelegates(selectedUsers, emailDate, baseUrl); return(View("Confirmation", selectedUsers.Count)); }
private SelectCourseViewModel GetSelectCourseViewModel( string?categoryFilterString, string?topicFilterString, int?selectedApplicationId = null ) { var centreId = User.GetCentreId(); var categoryIdFilter = User.GetAdminCourseCategoryFilter() !; var applications = courseService .GetApplicationOptionsAlphabeticalListForCentre(centreId, categoryIdFilter).ToList(); var categories = courseService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId); var topics = courseService.GetTopicsForCentreAndCentrallyManagedCourses(centreId); var availableFilters = (categoryIdFilter == null ? SelectCourseViewModelFilterOptions.GetAllCategoriesFilters( categories, topics, categoryFilterString, topicFilterString ) : SelectCourseViewModelFilterOptions.GetSingleCategoryFilters( applications, categoryFilterString, topicFilterString )).ToList(); var currentFilterString = FilteringHelper.GetCategoryAndTopicFilterString(categoryFilterString, topicFilterString); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, new SortOptions(nameof(ApplicationDetails.ApplicationName), GenericSortingHelper.Ascending), new FilterOptions(currentFilterString, availableFilters), null ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( applications, searchSortPaginationOptions ); return(new SelectCourseViewModel( result, availableFilters, categoryFilterString, topicFilterString, selectedApplicationId )); }
public IActionResult Index( string?searchString = null, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int page = 1, int?itemsPerPage = null ) { existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, AdminFilterCookieName ); var centreId = User.GetCentreId(); var adminUsersAtCentre = userDataService.GetAdminUsersByCentreId(centreId); var categories = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId); var loggedInUserId = User.GetAdminId(); var loggedInAdminUser = userDataService.GetAdminUserById(loggedInUserId !.GetValueOrDefault()); var availableFilters = AdministratorsViewModelFilterOptions.GetAllAdministratorsFilterModels(categories); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(GenericSortingHelper.DefaultSortOption, GenericSortingHelper.Ascending), new FilterOptions(existingFilterString, availableFilters), new PaginationOptions(page, itemsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( adminUsersAtCentre, searchSortPaginationOptions ); var model = new CentreAdministratorsViewModel( centreId, result, availableFilters, loggedInAdminUser ! ); Response.UpdateFilterCookie(AdminFilterCookieName, result.FilterString); return(View(model)); }
public IActionResult Index( string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, bool selectAll = false ) { var newFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, EmailDelegateFilterCookieName ); var jobGroups = jobGroupsDataService.GetJobGroupsAlphabetical(); var customPrompts = promptsService.GetCentreRegistrationPrompts(User.GetCentreId()); var delegateUsers = GetDelegateUserCards(); var promptsWithOptions = customPrompts.Where(customPrompt => customPrompt.Options.Count > 0); var availableFilters = EmailDelegatesViewModelFilterOptions.GetEmailDelegatesFilterModels( jobGroups, promptsWithOptions ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, null, new FilterOptions(newFilterString, availableFilters), null ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( delegateUsers, searchSortPaginationOptions ); var model = new EmailDelegatesViewModel( result, availableFilters, selectAll ); Response.UpdateFilterCookie(EmailDelegateFilterCookieName, result.FilterString); return(View(model)); }
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 ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, DelegateGroupsFilterCookieName ); var centreId = User.GetCentreId(); var groups = groupsService.GetGroupsForCentre(centreId).ToList(); var registrationPrompts = GetRegistrationPromptsWithSetOptions(centreId); var availableFilters = DelegateGroupsViewModelFilterOptions .GetDelegateGroupFilterModels(groups, registrationPrompts).ToList(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), new FilterOptions(existingFilterString, availableFilters), new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( groups, searchSortPaginationOptions ); var model = new DelegateGroupsViewModel( result, availableFilters ); Response.UpdateFilterCookie(DelegateGroupsFilterCookieName, result.FilterString); return(View(model)); }
public void SearchFilterSortAndPaginate_with_search_only_returns_expected_result() { // Given var options = new SearchSortFilterAndPaginateOptions(new SearchOptions("A"), null, null, null); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(new[] { new SortableItem("A", 10) }, 1, 1, int.MaxValue, 1, true), "A", null, null, null ); result.Should().BeEquivalentTo(expectedResult); }
public async Task <IActionResult> Current( string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Descending, int page = 1 ) { sortBy ??= CourseSortByOptions.LastAccessed.PropertyName; var delegateId = User.GetCandidateIdKnownNotNull(); var currentCourses = courseDataService.GetCurrentCourses(delegateId); var bannerText = GetBannerText(); var selfAssessments = selfAssessmentService.GetSelfAssessmentsForCandidate(delegateId); var(learningResources, apiIsAccessible) = await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateId); var allItems = currentCourses.Cast <CurrentLearningItem>().ToList(); allItems.AddRange(selfAssessments); allItems.AddRange(learningResources); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( allItems, searchSortPaginationOptions ); var model = new CurrentPageViewModel( result, apiIsAccessible, bannerText ); return(View("Current/Current", model)); }
public IActionResult Index(int groupId, int page = 1) { var centreId = User.GetCentreId(); var groupName = groupsService.GetGroupName(groupId, centreId); var groupDelegates = groupsService.GetGroupDelegates(groupId); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( null, null, null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( groupDelegates, searchSortPaginationOptions ); var model = new GroupDelegatesViewModel(groupId, groupName !, result); return(View(model)); }
public IActionResult Index( DlsSubApplication dlsSubApplication, int page = 1, string?searchString = null ) { // A MatchCutOffScore of 65 is being used here rather than the default 80. // The default Fuzzy Search configuration does not reliably bring back expected FAQs. // Through trial and error a combination of the PartialTokenSetScorer ratio scorer // and this cut off score bring back reliable results comparable to the JS search. const int matchCutOffScore = 65; const string faqSortBy = "Weighting,FaqId"; var faqs = faqsService.GetPublishedFaqsForTargetGroup(dlsSubApplication.FaqTargetGroupId !.Value) .Select(f => new SearchableFaq(f)); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString, matchCutOffScore, true), new SortOptions(faqSortBy, GenericSortingHelper.Descending), null, new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( faqs, searchSortPaginationOptions ); var model = new FaqsPageViewModel( dlsSubApplication, SupportPage.Faqs, configuration.GetCurrentSystemBaseUrl(), result ); return(View("Faqs", model)); }
public void SearchFilterSortAndPaginate_with_paginate_only_returns_expected_second_page() { // Given var options = new SearchSortFilterAndPaginateOptions( null, null, null, new PaginationOptions(2, 8) ); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(allItems.Skip(8), 2, 2, 8, 10, true), null, null, null, null ); result.Should().BeEquivalentTo(expectedResult); }
public void SearchFilterSortAndPaginate_with_sort_only_returns_expected_result() { // Given var options = new SearchSortFilterAndPaginateOptions( null, new SortOptions("Number", GenericSortingHelper.Ascending), null, null ); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(allItems.OrderBy(x => x.Number), 1, 1, int.MaxValue, 10, true), null, "Number", GenericSortingHelper.Ascending, null ); result.Should().BeEquivalentTo(expectedResult); }
public void SearchFilterSortAndPaginate_with_paginate_only_returns_first_page_with_invalid_page_numbers(int pageNumber) { // Given var options = new SearchSortFilterAndPaginateOptions( null, null, null, new PaginationOptions(pageNumber, 5) ); // When var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(allItems, options); // Then var expectedResult = new SearchSortFilterPaginationResult <SortableItem>( new PaginationResult <SortableItem>(allItems.Take(5), 1, 2, 5, 10, true), null, null, null, null ); result.Should().BeEquivalentTo(expectedResult); }
public IActionResult Index( int?customisationId = null, string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int page = 1 ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; var newFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, CourseDelegatesFilterCookieName, CourseDelegateAccountStatusFilterOptions.Active.FilterValue ); var centreId = User.GetCentreId(); var adminCategoryId = User.GetAdminCourseCategoryFilter(); try { var courseDelegatesData = courseDelegatesService.GetCoursesAndCourseDelegatesForCentre( centreId, adminCategoryId, customisationId ); var availableFilters = CourseDelegateViewModelFilterOptions.GetAllCourseDelegatesFilterViewModels( courseDelegatesData.CourseAdminFields ); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), new FilterOptions( newFilterString, availableFilters, CourseDelegateAccountStatusFilterOptions.Active.FilterValue ), new PaginationOptions(page) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( courseDelegatesData.Delegates, searchSortPaginationOptions ); var model = new CourseDelegatesViewModel( courseDelegatesData, result, availableFilters, "customisationId" ); Response.UpdateFilterCookie(CourseDelegatesFilterCookieName, result.FilterString); return(View(model)); } catch (CourseAccessDeniedException) { return(NotFound()); } }
public IActionResult ViewFrameworks(string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, int page = 1, string tabname = "All") { sortBy ??= FrameworkSortByOptions.FrameworkName.PropertyName; var adminId = GetAdminId(); var isFrameworkDeveloper = GetIsFrameworkDeveloper(); var isFrameworkContributor = GetIsFrameworkContributor(); IEnumerable <BrandedFramework> frameworks; if (tabname == "All") { frameworks = frameworkService.GetAllFrameworks(adminId); } else { if (!isFrameworkDeveloper && !isFrameworkContributor) { return(RedirectToAction("ViewFrameworks", "Frameworks", new { tabname = "All" })); } frameworks = frameworkService.GetFrameworksForAdminId(adminId); } MyFrameworksViewModel myFrameworksViewModel; AllFrameworksViewModel allFrameworksViewModel; var searchSortPaginateOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString, 60), new SortOptions(sortBy, sortDirection), null, new PaginationOptions(page, 12) ); if (tabname == "All") { var myFrameworksResult = searchSortFilterPaginateService.SearchFilterSortAndPaginate( new List <BrandedFramework>(), searchSortPaginateOptions ); myFrameworksViewModel = new MyFrameworksViewModel(myFrameworksResult, isFrameworkDeveloper); var allFrameworksResult = searchSortFilterPaginateService.SearchFilterSortAndPaginate( frameworks, searchSortPaginateOptions ); allFrameworksViewModel = new AllFrameworksViewModel(allFrameworksResult); } else { var myFrameworksResult = searchSortFilterPaginateService.SearchFilterSortAndPaginate( frameworks, searchSortPaginateOptions ); myFrameworksViewModel = new MyFrameworksViewModel(myFrameworksResult, isFrameworkDeveloper); var allFrameworksResult = searchSortFilterPaginateService.SearchFilterSortAndPaginate( new List <BrandedFramework>(), searchSortPaginateOptions ); allFrameworksViewModel = new AllFrameworksViewModel(allFrameworksResult); } var currentTab = tabname == "All" ? FrameworksTab.AllFrameworks : FrameworksTab.MyFrameworks; var frameworksViewModel = new FrameworksViewModel( isFrameworkDeveloper, isFrameworkContributor, myFrameworksViewModel, allFrameworksViewModel, currentTab ); return(View("Developer/Frameworks", frameworksViewModel)); }