public IActionResult SetNewFrameworkName(string frameworkname, string actionname) { if (actionname == "New") { var sessionNewFramework = TempData.Peek <SessionNewFramework>(); TempData.Set(sessionNewFramework); } var adminId = GetAdminId(); var sameItems = frameworkService.GetFrameworkByFrameworkName(frameworkname, adminId); var frameworks = frameworkService.GetAllFrameworks(adminId); var sortedItems = GenericSortingHelper.SortAllItems( frameworks.AsQueryable(), FrameworkSortByOptions.FrameworkName.PropertyName, BaseSearchablePageViewModel.Ascending ); var similarItems = GenericSearchHelper.SearchItems(sortedItems, frameworkname, 55, true); var brandedFrameworks = similarItems.ToList(); var matchingSearchResults = brandedFrameworks.ToList().Count; if (matchingSearchResults > 0) { var model = new SimilarViewModel() { FrameworkName = frameworkname, MatchingSearchResults = matchingSearchResults, SimilarFrameworks = brandedFrameworks, SameFrameworks = sameItems }; return(View("Developer/Similar", model)); } return(RedirectToAction("SaveNewFramework", "Frameworks", new { frameworkname, actionname })); }
public CourseSetupViewModel( IEnumerable <CourseStatistics> courses, IEnumerable <string> categories, IEnumerable <string> topics, string?searchString, string sortBy, string sortDirection, string?filterBy, int page ) : base(searchString, page, true, sortBy, sortDirection, filterBy, searchLabel: "Search courses") { var sortedItems = GenericSortingHelper.SortAllItems( courses.AsQueryable(), sortBy, sortDirection ); var filteredItems = FilteringHelper.FilterItems(sortedItems.AsQueryable(), filterBy).ToList(); var searchedItems = GenericSearchHelper.SearchItems(filteredItems, SearchString).ToList(); MatchingSearchResults = searchedItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(searchedItems); Courses = paginatedItems.Select(c => new SearchableCourseStatisticsViewModel(c)); Filters = CourseStatisticsViewModelFilterOptions.GetFilterOptions(categories, topics); }
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 void Current_courses_with_self_assessment_should_be_filtered_correctly( string searchString, int[] expectedIds ) { // When var result = GenericSearchHelper.SearchItems(currentCoursesWithSelfAssessment, searchString); var filteredIds = result.Select(course => course.Id); // Then filteredIds.Should().Equal(expectedIds); }
public void SearchItemsUsingTokeniseScorer_returns_expected_result_from_available_courses() { // Given var searchString = "title text"; var expectedId = 73; // When var result = GenericSearchHelper.SearchItemsUsingTokeniseScorer(availableCourses, searchString); // Then result.Should().Contain(r => r.Id == expectedId); }
public void Completed_courses_should_be_filtered_correctly( string searchString, int[] expectedIds ) { // When var result = GenericSearchHelper.SearchItems(completedCourses, searchString); var filteredIds = result.Select(course => course.Id); // Then filteredIds.Should().Equal(expectedIds); }
public void DelegateUsers_should_be_filtered_on_name_and_candidateNumber_correctly( string searchString, int[] expectedIds ) { // When var result = GenericSearchHelper.SearchItems(delegateUsers, searchString); var filteredIds = result.Select(delegateUser => delegateUser.Id); // Then filteredIds.Should().Equal(expectedIds); }
public FaqsPageViewModel( DlsSubApplication dlsSubApplication, SupportPage currentPage, string currentSystemBaseUrl, IEnumerable <SearchableFaq> faqs, int page, string?searchString ) : base(searchString, page, false, FaqSortBy, Descending, searchLabel: "Search faqs") { CurrentPage = currentPage; DlsSubApplication = dlsSubApplication; CurrentSystemBaseUrl = currentSystemBaseUrl; var searchedItems = GenericSearchHelper.SearchItemsUsingTokeniseScorer(faqs, SearchString, MatchCutOffScore).ToList(); var faqsToShow = SortFilterAndPaginate(searchedItems); Faqs = faqsToShow.Select(f => new SearchableFaqViewModel(DlsSubApplication, f)); }
private IEnumerable <DelegateUserCard> GetDelegatesToExport( int centreId, string?searchString, string?sortBy, string sortDirection, string?filterString ) { var delegateUsers = userDataService.GetDelegateUserCardsByCentreId(centreId); var searchedUsers = GenericSearchHelper.SearchItems(delegateUsers, searchString).AsQueryable(); var filteredItems = FilteringHelper.FilterItems(searchedUsers, filterString).AsQueryable(); var sortedItems = GenericSortingHelper.SortAllItems( filteredItems, sortBy ?? nameof(DelegateUserCard.SearchableName), sortDirection ); return(sortedItems); }
private IEnumerable <CourseStatisticsWithAdminFieldResponseCounts> GetCoursesToExport( int centreId, int?adminCategoryId, string?searchString, string?sortBy, string?filterString, string sortDirection ) { var details = courseService.GetCentreCourseDetailsWithAllCentreCourses(centreId, adminCategoryId); var searchedCourses = GenericSearchHelper.SearchItems(details.Courses, searchString); var filteredCourses = FilteringHelper.FilterItems(searchedCourses.AsQueryable(), filterString); var sortedCourses = GenericSortingHelper.SortAllItems( filteredCourses.AsQueryable(), sortBy ?? nameof(CourseStatisticsWithAdminFieldResponseCounts.CourseName), sortDirection ); return(sortedCourses); }
public AllFrameworksViewModel( IEnumerable <BrandedFramework> brandedFrameworks, string?searchString, string sortBy, string sortDirection, int page ) : base(searchString, page, false, sortBy, sortDirection, itemsPerPage: 12) { var sortedItems = GenericSortingHelper.SortAllItems( brandedFrameworks.AsQueryable(), sortBy, sortDirection ); var filteredItems = GenericSearchHelper.SearchItems(sortedItems, SearchString, 60).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); BrandedFrameworks = paginatedItems; }
public DelegateGroupsViewModel( List <Group> groups, IEnumerable <CustomPrompt> registrationPrompts, string searchString, string sortBy, string sortDirection, string?filterBy, int page ) : base(searchString, page, true, sortBy, sortDirection, filterBy) { var sortedItems = GenericSortingHelper.SortAllItems( groups.AsQueryable(), sortBy, sortDirection ); var searchedItems = GenericSearchHelper.SearchItems(sortedItems, SearchString); var filteredItems = FilteringHelper.FilterItems(searchedItems.AsQueryable(), filterBy).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); DelegateGroups = paginatedItems.Select(g => new SearchableDelegateGroupViewModel(g)); var admins = groups.Select(g => (g.AddedByAdminId, g.AddedByName)).Distinct(); Filters = new[] { new FilterViewModel( nameof(Group.AddedByAdminId), "Added by", DelegateGroupsViewModelFilterOptions.GetAddedByOptions(admins) ), new FilterViewModel( nameof(Group.LinkedToField), "Linked field", DelegateGroupsViewModelFilterOptions.GetLinkedFieldOptions(registrationPrompts) ) }; }
public CentreAdministratorsViewModel( int centreId, IEnumerable <AdminUser> adminUsers, IEnumerable <string> categories, string?searchString, string?filterBy, int page ) : base(searchString, page, true, filterBy: filterBy, searchLabel: "Search administrators") { CentreId = centreId; var sortedItems = GenericSortingHelper.SortAllItems( adminUsers.AsQueryable(), DefaultSortOption, Ascending ); var searchedItems = GenericSearchHelper.SearchItems(sortedItems, SearchString); var filteredItems = FilteringHelper.FilterItems(searchedItems.AsQueryable(), filterBy).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); Admins = paginatedItems.Select(adminUser => new SearchableAdminViewModel(adminUser)); Filters = new[] { new FilterViewModel("Role", "Role", AdministratorsViewModelFilterOptions.RoleOptions), new FilterViewModel( "CategoryName", "Category", AdministratorsViewModelFilterOptions.GetCategoryOptions(categories) ), new FilterViewModel( "AccountStatus", "Account Status", AdministratorsViewModelFilterOptions.AccountStatusOptions ) }; }
public CurrentPageViewModel( IEnumerable <CurrentCourse> currentCourses, string?searchString, string sortBy, string sortDirection, IEnumerable <SelfAssessment> selfAssessments, IEnumerable <ActionPlanResource> actionPlanResources, string?bannerText, int page ) : base(searchString, page, false, sortBy, sortDirection, searchLabel: "Search your current courses") { BannerText = bannerText; var allItems = currentCourses.Cast <CurrentLearningItem>().ToList(); allItems.AddRange(selfAssessments); allItems.AddRange(actionPlanResources); var sortedItems = GenericSortingHelper.SortAllItems( allItems.AsQueryable(), sortBy, sortDirection ); var filteredItems = GenericSearchHelper.SearchItems(sortedItems, SearchString).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); CurrentActivities = paginatedItems.Select <BaseLearningItem, CurrentLearningItemViewModel>( activity => { return(activity switch { CurrentCourse currentCourse => new CurrentCourseViewModel(currentCourse), SelfAssessment selfAssessment => new SelfAssessmentCardViewModel(selfAssessment), _ => new CurrentLearningResourceViewModel((ActionPlanResource)activity) }); }
public AvailablePageViewModel( IEnumerable <AvailableCourse> availableCourses, string?searchString, string sortBy, string sortDirection, string?bannerText, int page ) : base(searchString, page, false, sortBy, sortDirection, searchLabel: "Search courses") { BannerText = bannerText; var sortedItems = GenericSortingHelper.SortAllItems( availableCourses.AsQueryable(), sortBy, sortDirection ); var filteredItems = GenericSearchHelper.SearchItems(sortedItems, SearchString).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); AvailableCourses = paginatedItems.Select(c => new AvailableCourseViewModel(c)); }
public MyStaffListViewModel( IEnumerable <SupervisorDelegateDetail> supervisorDelegateDetails, CentreCustomPrompts centreCustomPrompts, string?searchString, string sortBy, string sortDirection, int page ) : base(searchString, page, false, sortBy, sortDirection, searchLabel: "Search administrators") { CentreCustomPrompts = centreCustomPrompts; var sortedItems = GenericSortingHelper.SortAllItems( supervisorDelegateDetails.AsQueryable(), sortBy, sortDirection ); var searchedItems = GenericSearchHelper.SearchItems(sortedItems, SearchString).ToList(); MatchingSearchResults = searchedItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(searchedItems); SuperviseDelegateDetails = paginatedItems; }
public CompletedPageViewModel( IEnumerable <CompletedCourse> completedCourses, IEnumerable <CompletedActionPlanResource> completedResources, IConfiguration config, string?searchString, string sortBy, string sortDirection, string?bannerText, int page ) : base(searchString, page, false, sortBy, sortDirection, searchLabel: "Search your completed courses") { BannerText = bannerText; var allItems = completedCourses.Cast <CompletedLearningItem>().ToList(); allItems.AddRange(completedResources); var sortedItems = GenericSortingHelper.SortAllItems( allItems.AsQueryable(), sortBy, sortDirection ); var filteredItems = GenericSearchHelper.SearchItems(sortedItems, SearchString).ToList(); MatchingSearchResults = filteredItems.Count; SetTotalPages(); var paginatedItems = GetItemsOnCurrentPage(filteredItems); CompletedActivities = paginatedItems.Select <BaseLearningItem, CompletedLearningItemViewModel>( activity => { return(activity switch { CompletedCourse completedCourse => new CompletedCourseViewModel(completedCourse, config), _ => new CompletedLearningResourceViewModel((CompletedActionPlanResource)activity), }); }