Skip to content

Commit

Permalink
Refactor course search into openedx/features
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-armstrong authored and dianakhuang committed Jun 13, 2017
1 parent 7721237 commit 0096c80
Show file tree
Hide file tree
Showing 34 changed files with 197 additions and 284 deletions.
1 change: 1 addition & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,7 @@
# Features
'openedx.features.course_bookmarks',
'openedx.features.course_experience',
'openedx.features.course_search',
'openedx.features.enterprise_support',
)

Expand Down
1 change: 1 addition & 0 deletions lms/static/course_search
11 changes: 0 additions & 11 deletions lms/static/js/search/course/views/search_form.js

This file was deleted.

11 changes: 0 additions & 11 deletions lms/static/js/search/course/views/search_item_view.js

This file was deleted.

11 changes: 0 additions & 11 deletions lms/static/js/search/dashboard/views/search_form.js

This file was deleted.

11 changes: 0 additions & 11 deletions lms/static/js/search/dashboard/views/search_item_view.js

This file was deleted.

1 change: 1 addition & 0 deletions lms/static/karma_lms.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var options = {
sourceFiles: [
{pattern: 'coffee/src/**/!(*spec).js'},
{pattern: 'course_bookmarks/**/!(*spec).js'},
{pattern: 'course_search/**/!(*spec).js'},
{pattern: 'discussion/js/**/!(*spec).js'},
{pattern: 'js/**/!(*spec|djangojs).js'},
{pattern: 'lms/js/**/!(*spec).js'},
Expand Down
4 changes: 2 additions & 2 deletions lms/static/lms/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
modules: getModulesList([
'course_bookmarks/js/course_bookmarks_factory',
'course_search/js/course_search_factory',
'course_search/js/dashboard_search_factory',
'discussion/js/discussion_board_factory',
'discussion/js/discussion_profile_page_factory',
'js/api_admin/catalog_preview_factory',
Expand All @@ -32,8 +34,6 @@
'js/header_factory',
'js/learner_dashboard/program_details_factory',
'js/learner_dashboard/program_list_factory',
'js/search/course/course_search_factory',
'js/search/dashboard/dashboard_search_factory',
'js/student_account/logistration_factory',
'js/student_account/views/account_settings_factory',
'js/student_account/views/finish_auth_factory',
Expand Down
2 changes: 1 addition & 1 deletion lms/static/lms/js/spec/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@
'course_bookmarks/js/spec/bookmark_button_view_spec.js',
'course_bookmarks/js/spec/bookmarks_list_view_spec.js',
'course_bookmarks/js/spec/course_bookmarks_factory_spec.js',
'course_search/js/spec/search_spec.js',
'discussion/js/spec/discussion_board_factory_spec.js',
'discussion/js/spec/discussion_profile_page_factory_spec.js',
'discussion/js/spec/discussion_board_view_spec.js',
Expand Down Expand Up @@ -749,7 +750,6 @@
'js/spec/markdown_editor_spec.js',
'js/spec/dateutil_factory_spec.js',
'js/spec/navigation_spec.js',
'js/spec/search/search_spec.js',
'js/spec/shoppingcart/shoppingcart_spec.js',
'js/spec/staff_debug_actions_spec.js',
'js/spec/student_account/access_spec.js',
Expand Down
10 changes: 1 addition & 9 deletions lms/templates/courseware/courseware.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
</script>
% endfor

% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
% for template_name in ["course_search_item", "course_search_results", "search_loading", "search_error"]:
<script type="text/template" id="${template_name}-tpl">
<%static:include path="search/${template_name}.underscore" />
</script>
% endfor
% endif

% if include_special_exams is not UNDEFINED and include_special_exams:
% for template_name in ["proctored-exam-status"]:
<script type="text/template" id="${template_name}-tpl">
Expand Down Expand Up @@ -81,7 +73,7 @@
<%include file="/mathjax_include.html" args="disable_fast_preview=True"/>

% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
<%static:require_module module_name="js/search/course/course_search_factory" class_name="CourseSearchFactory">
<%static:require_module module_name="course_search/js/course_search_factory" class_name="CourseSearchFactory">
var courseId = $('.courseware-results').data('courseId');
CourseSearchFactory(courseId);
</%static:require_module>
Expand Down
8 changes: 1 addition & 7 deletions lms/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
<%static:include path="dashboard/${template_name}.underscore" />
</script>
% endfor

% for template_name in ["dashboard_search_item", "dashboard_search_results", "search_loading", "search_error"]:
<script type="text/template" id="${template_name}-tpl">
<%static:include path="search/${template_name}.underscore" />
</script>
% endfor
</%block>

<%block name="js_extra">
Expand All @@ -49,7 +43,7 @@
});
</script>
% if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'):
<%static:require_module module_name="js/search/dashboard/dashboard_search_factory" class_name="DashboardSearchFactory">
<%static:require_module module_name="course_search/js/dashboard/dashboard_search_factory" class_name="DashboardSearchFactory">
DashboardSearchFactory();
</%static:require_module>
% endif
Expand Down
2 changes: 1 addition & 1 deletion openedx/features/course_bookmarks/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Defines URLs for the course experience.
Defines URLs for course bookmarks.
"""

from django.conf.urls import url
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(function(define) {
'use strict';

define([
'underscore',
'backbone',
'js/search/base/models/search_result'
], function(Backbone, SearchResult) {
'use strict';

'course_search/js/models/search_result'
], function(_, Backbone, SearchResult) {
return Backbone.Collection.extend({

model: SearchResult,
Expand All @@ -26,7 +27,9 @@
},

performSearch: function(searchTerm) {
this.fetchXhr && this.fetchXhr.abort();
if (this.fetchXhr) {
this.fetchXhr.abort();
}
this.searchTerm = searchTerm || '';
this.resetState();
this.fetchXhr = this.fetch({
Expand All @@ -36,29 +39,31 @@
page_index: 0
},
type: 'POST',
success: function(self, xhr) {
success: function(self) {
self.trigger('search');
},
error: function(self, xhr) {
error: function(self) {
self.trigger('error');
}
});
},

loadNextPage: function() {
this.fetchXhr && this.fetchXhr.abort();
if (this.fetchXhr) {
this.fetchXhr.abort();
}
this.fetchXhr = this.fetch({
data: {
search_string: this.searchTerm,
page_size: this.pageSize,
page_index: this.page + 1
},
type: 'POST',
success: function(self, xhr) {
self.page += 1;
success: function(self) {
self.page += 1; // eslint-disable-line no-param-reassign
self.trigger('next');
},
error: function(self, xhr) {
error: function(self) {
self.trigger('error');
},
add: true,
Expand All @@ -68,7 +73,9 @@
},

cancelSearch: function() {
this.fetchXhr && this.fetchXhr.abort();
if (this.fetchXhr) {
this.fetchXhr.abort();
}
this.resetState();
},

Expand Down Expand Up @@ -101,4 +108,4 @@

});
});
})(define || RequireJS.define);
}(define || RequireJS.define));
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
(function(define) {
'use strict';

define(['backbone', 'js/search/base/routers/search_router', 'js/search/course/views/search_form',
'js/search/base/collections/search_collection', 'js/search/course/views/search_results_view'],
function(Backbone, SearchRouter, CourseSearchForm, SearchCollection, SearchResultsView) {
define([
'underscore', 'backbone', 'course_search/js/search_router', 'course_search/js/views/search_form',
'course_search/js/collections/search_collection', 'course_search/js/views/course_search_results_view'
],
function(_, Backbone, SearchRouter, CourseSearchForm, SearchCollection, CourseSearchResultsView) {
return function(courseId) {
var router = new SearchRouter();
var form = new CourseSearchForm();
var collection = new SearchCollection([], {courseId: courseId});
var results = new SearchResultsView({collection: collection});
var results = new CourseSearchResultsView({collection: collection});
var dispatcher = _.clone(Backbone.Events);

dispatcher.listenTo(router, 'search', function(query) {
Expand Down Expand Up @@ -44,4 +46,4 @@
});
};
});
})(define || RequireJS.define);
}(define || RequireJS.define));
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
(function(define) {
'use strict';

define(['backbone', 'js/search/base/routers/search_router', 'js/search/dashboard/views/search_form',
'js/search/base/collections/search_collection', 'js/search/dashboard/views/search_results_view'],
function(Backbone, SearchRouter, SearchForm, SearchCollection, SearchListView) {
define([
'underscore', 'backbone', 'course_search/js/search_router', 'course_search/js/views/search_form',
'course_search/js/collections/search_collection', 'course_search/js/views/dashboard_search_results_view'
],
function(_, Backbone, SearchRouter, SearchForm, SearchCollection, SearchListView) {
return function() {
var router = new SearchRouter();
var form = new SearchForm();
var form = new SearchForm({
el: $('#dashboard-search-bar')
});
var collection = new SearchCollection([]);
var results = new SearchListView({collection: collection});
var dispatcher = _.clone(Backbone.Events);
Expand Down Expand Up @@ -48,4 +52,4 @@
});
};
});
})(define || RequireJS.define);
}(define || RequireJS.define));
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(define) {
define(['backbone'], function(Backbone) {
'use strict';
'use strict';

define(['backbone'], function(Backbone) {
return Backbone.Model.extend({
defaults: {
location: [],
Expand All @@ -11,4 +11,4 @@
}
});
});
})(define || RequireJS.define);
}(define || RequireJS.define));
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function(define) {
define(['backbone'], function(Backbone) {
'use strict';
'use strict';

define(['backbone'], function(Backbone) {
return Backbone.Router.extend({
routes: {
'search/:query': 'search'
Expand All @@ -11,4 +11,4 @@
}
});
});
})(define || RequireJS.define);
}(define || RequireJS.define));
Loading

0 comments on commit 0096c80

Please sign in to comment.