Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: filter courses by user language by default #609

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def courses(request):
"""
courses_list = []
course_discovery_meanings = getattr(settings, 'COURSE_DISCOVERY_MEANINGS', {})
set_default_filter = settings.FEATURES.get('ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER')
if not settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
courses_list = get_courses(request.user)

Expand All @@ -293,6 +294,7 @@ def courses(request):
{
'courses': courses_list,
'course_discovery_meanings': course_discovery_meanings,
'set_default_filter': set_default_filter,
'programs_list': programs_list,
}
)
Expand Down
11 changes: 11 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,17 @@
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/7845
'ENABLE_COURSE_DISCOVERY': False,

# .. toggle_name: FEATURES['ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
# .. toggle_description: Enable courses to be filtered by user language by default.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2023-11-02
# .. toggle_target_removal_date: None
# .. toggle_warning: The ENABLE_COURSE_DISCOVERY setting should be enabled.
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/33647
'ENABLE_COURSE_DISCOVERY_DEFAULT_LANGUAGE_FILTER': False,

# .. toggle_name: FEATURES['ENABLE_COURSE_FILENAME_CCX_SUFFIX']
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
Expand Down
11 changes: 9 additions & 2 deletions lms/static/js/discovery/discovery_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'js/discovery/views/search_form', 'js/discovery/views/courses_listing',
'js/discovery/views/filter_bar', 'js/discovery/views/refine_sidebar'],
function(Backbone, SearchState, Filters, SearchForm, CoursesListing, FilterBar, RefineSidebar) {
return function(meanings, searchQuery, userLanguage, userTimezone) {
return function(meanings, searchQuery, userLanguage, userTimezone, setDefaultFilter) {
var dispatcher = _.extend({}, Backbone.Events);
var search = new SearchState();
var filters = new Filters();
Expand All @@ -21,10 +21,16 @@
userLanguage: userLanguage,
userTimezone: userTimezone
};
if (setDefaultFilter && userLanguage) {
filters.add({
type: 'language',
query: userLanguage,
name: refineSidebar.termName('language', userLanguage)
});
}
listing = new CoursesListing({model: courseListingModel});

dispatcher.listenTo(form, 'search', function(query) {
filters.reset();
form.showLoadingIndicator();
search.performSearch(query, filters.getTerms());
});
Expand All @@ -42,6 +48,7 @@
dispatcher.listenTo(filterBar, 'clearFilter', removeFilter);

dispatcher.listenTo(filterBar, 'clearAll', function() {
filters.reset();
form.doSearch('');
});

Expand Down
15 changes: 14 additions & 1 deletion lms/static/js/spec/discovery/discovery_factory_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ define([
start: '1970-01-01T05:00:00+00:00',
image_url: '/c4x/edX/DemoX/asset/images_course_image.jpg',
org: 'edX',
id: 'edX/DemoX/Demo_Course'
id: 'edX/DemoX/Demo_Course',
language: 'en'
}
}
],
Expand Down Expand Up @@ -197,5 +198,17 @@ define([
$('.search-facets li [data-value="edX1"]').trigger('click');
expect($('.active-filter [data-value="edX1"]').length).toBe(0);
});

it('filters by default language', function() {
DiscoveryFactory(MEANINGS, '', 'en', 'Asia/Kolkata', true);
var requests = AjaxHelpers.requests(this);
$('.discovery-submit').trigger('click');
AjaxHelpers.respondWithJson(requests, JSON_RESPONSE);
expect($('.courses-listing article').length).toEqual(1);
expect($('.courses-listing .course-title')).toContainHtml('edX Demonstration Course');
expect($('.active-filter').length).toBe(1);
expect($('.active-filter .query')).toContainHtml("English");
});

});
});
3 changes: 2 additions & 1 deletion lms/templates/courseware/courses.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
${course_discovery_meanings | n, dump_js_escaped_json},
getParameterByName('search_query'),
"${user_language | n, js_escaped_string}",
"${user_timezone | n, js_escaped_string}"
"${user_timezone | n, js_escaped_string}",
${set_default_filter | n, dump_js_escaped_json}
);
</%static:require_module>
</%block>
Expand Down
Loading