Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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 }));
        }
Exemplo n.º 3
0
        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 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 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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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)
                    )
            };
        }
Exemplo n.º 11
0
        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
                    )
            };
        }
Exemplo n.º 12
0
        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)
                });
            }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        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),
                });
            }