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 SortAllItems_should_sort_available_courses_correctly( string sortBy, string sortDirection, int[] expectedIdsOrder) { var sortedCompletedCourses = GenericSortingHelper.SortAllItems(availableCourses, sortBy, sortDirection); var sortedIds = sortedCompletedCourses.Select(course => course.Id); sortedIds.Should().Equal(expectedIdsOrder); }
private void PopulateCourseDelegatesSheetForCourse( IXLWorkbook workbook, int customisationId, int centreId, string?sortBy, string?filterString, string sortDirection ) { var adminFields = courseAdminFieldsService.GetCourseAdminFieldsForCourse(customisationId); var customRegistrationPrompts = registrationPromptsService.GetCentreRegistrationPromptsByCentreId(centreId); var courseDelegates = courseDataService.GetDelegatesOnCourseForExport(customisationId, centreId) .ToList(); var filteredCourseDelegates = FilteringHelper.FilterItems(courseDelegates.AsQueryable(), filterString).ToList(); var sortedCourseDelegates = GenericSortingHelper.SortAllItems( filteredCourseDelegates.AsQueryable(), sortBy ?? nameof(CourseDelegateForExport.FullNameForSearchingSorting), sortDirection ); var dataTable = new DataTable(); SetUpDataTableColumns(customRegistrationPrompts, adminFields, dataTable); foreach (var courseDelegate in sortedCourseDelegates) { AddDelegateToDataTable(dataTable, courseDelegate, customRegistrationPrompts, adminFields); } if (dataTable.Rows.Count == 0) { var row = dataTable.NewRow(); dataTable.Rows.Add(row); } ClosedXmlHelper.AddSheetToWorkbook( workbook, $"Course {customisationId}", dataTable.AsEnumerable(), XLTableTheme.None ); FormatWorksheetColumns(workbook, dataTable); }
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); }
public AddCourseToGroupCoursesViewModel( IEnumerable <CourseAssessmentDetails> courses, int groupId, string groupName ) { GroupId = groupId; GroupName = groupName; var sortedCourses = GenericSortingHelper.SortAllItems( courses.AsQueryable(), nameof(CourseAssessmentDetails.CourseName), BaseSearchablePageViewModel.Ascending ); var coursesToShow = sortedCourses.Take(10); Courses = coursesToShow.Select(c => new SearchableCourseViewModel(c, groupId)); }
public RecommendedLearningViewModel( SelfAssessment selfAssessment, IEnumerable <RecommendedResource> recommendedResources ) { SelfAssessment = selfAssessment; var sortedResources = GenericSortingHelper.SortAllItems( recommendedResources.AsQueryable(), nameof(RecommendedResource.RecommendationScore), BaseSearchablePageViewModel.Descending ); // TODO HEEDLS-650 Search/Pagination var resourcesToDisplay = sortedResources.Take(10); RecommendedResources = resourcesToDisplay.Select(r => new SearchableRecommendedResourceViewModel(r, selfAssessment.Id)); }
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 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 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)); }
private void AddCourseToSheet( IXLWorksheet sheet, int centreId, Course course, CentreRegistrationPrompts customRegistrationPrompts ) { var courseNameCell = sheet.Cell(GetNextEmptyRowNumber(sheet), 1); courseNameCell.Value = course.CourseName; courseNameCell.Style.Font.Bold = true; var sortedCourseDelegates = GenericSortingHelper.SortAllItems( courseDataService.GetDelegatesOnCourseForExport(course.CustomisationId, centreId) .AsQueryable(), nameof(CourseDelegateForExport.FullNameForSearchingSorting), GenericSortingHelper.Ascending ); var dataTable = new DataTable(); SetUpDataTableColumnsForExportAll(customRegistrationPrompts, dataTable); foreach (var courseDelegate in sortedCourseDelegates) { AddDelegateToDataTableForExportAll(dataTable, courseDelegate, customRegistrationPrompts); } var insertedDataRange = sheet.Cell(GetNextEmptyRowNumber(sheet), 1).InsertData(dataTable.Rows); if (dataTable.Rows.Count > 0) { sheet.Rows(insertedDataRange.FirstRow().RowNumber(), insertedDataRange.LastRow().RowNumber()) .Group(true); } }
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), }); }