Commit ad16f9f9 by cahrens

Optimize search usages.

parent eff80bae
......@@ -1212,8 +1212,6 @@ courseware_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/modules/**/*.js'))
)
courseware_search_js = ['js/search/course/main.js']
# Before a student accesses courseware, we do not
# need many of the JS dependencies. This includes
......@@ -1252,7 +1250,6 @@ base_application_js = [
dashboard_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/dashboard/**/*.js'))
)
dashboard_search_js = ['js/search/dashboard/main.js']
discussion_js = sorted(rooted_glob(COMMON_ROOT / 'static', 'coffee/src/discussion/**/*.js'))
staff_grading_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/staff_grading/**/*.js'))
open_ended_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/open_ended/**/*.js'))
......@@ -1338,8 +1335,6 @@ incourse_reverify_js = [
ccx_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/ccx/**/*.js'))
discovery_js = ['js/discovery/main.js']
certificates_web_view_js = [
'js/vendor/jquery.min.js',
'js/vendor/jquery.cookie.js',
......@@ -1504,10 +1499,6 @@ PIPELINE_JS = {
'source_filenames': courseware_js,
'output_filename': 'js/lms-courseware.js',
},
'courseware_search': {
'source_filenames': courseware_search_js,
'output_filename': 'js/lms-courseware-search.js',
},
'base_vendor': {
'source_filenames': base_vendor_js,
'output_filename': 'js/lms-base-vendor.js',
......@@ -1548,10 +1539,6 @@ PIPELINE_JS = {
'source_filenames': dashboard_js,
'output_filename': 'js/dashboard.js'
},
'dashboard_search': {
'source_filenames': dashboard_search_js,
'output_filename': 'js/dashboard-search.js',
},
'student_account': {
'source_filenames': student_account_js,
'output_filename': 'js/student_account.js'
......@@ -1576,10 +1563,6 @@ PIPELINE_JS = {
'source_filenames': ['js/footer-edx.js'],
'output_filename': 'js/footer-edx.js'
},
'discovery': {
'source_filenames': discovery_js,
'output_filename': 'js/discovery.js'
},
'certificates_wv': {
'source_filenames': certificates_web_view_js,
'output_filename': 'js/certificates/web_view.js'
......
;(function (define) {
define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) {
'use strict';
return function (Collection, Form, ResultListView, FilterBarView, FacetsBarView, searchQuery) {
//facet types configuration - set default display names
var facetsTypes = meanings;
define(['backbone', 'js/discovery/collection', 'js/discovery/form', 'js/discovery/result_list_view',
'js/discovery/filter_bar_view', 'js/discovery/search_facets_view'],
function(Backbone, Collection, Form, ResultListView, FilterBarView, FacetsBarView) {
var collection = new Collection([]);
var results = new ResultListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
var form = new Form();
var filters = new FilterBarView();
var facetsBarView = new FacetsBarView(facetsTypes);
return function (meanings, searchQuery) {
//facet types configuration - set default display names
var facetsTypes = meanings;
dispatcher.listenTo(form, 'search', function (query) {
form.showLoadingIndicator();
filters.changeQueryFilter(query);
});
var collection = new Collection([]);
var results = new ResultListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
var form = new Form();
var filters = new FilterBarView();
var facetsBarView = new FacetsBarView(facetsTypes);
dispatcher.listenTo(filters, 'search', function (searchTerm, facets) {
collection.performSearch(searchTerm, facets);
form.showLoadingIndicator();
});
dispatcher.listenTo(form, 'search', function (query) {
form.showLoadingIndicator();
filters.changeQueryFilter(query);
});
dispatcher.listenTo(filters, 'clear', function () {
form.clearSearch();
collection.performSearch();
filters.hideClearAllButton();
});
dispatcher.listenTo(filters, 'search', function (searchTerm, facets) {
collection.performSearch(searchTerm, facets);
form.showLoadingIndicator();
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
form.showLoadingIndicator();
});
dispatcher.listenTo(filters, 'clear', function () {
form.clearSearch();
collection.performSearch();
filters.hideClearAllButton();
});
dispatcher.listenTo(collection, 'search', function () {
if (collection.length > 0) {
form.showFoundMessage(collection.totalCount);
results.render();
}
else {
form.showNotFoundMessage(collection.searchTerm);
}
facetsBarView.renderFacets(collection.facets);
form.hideLoadingIndicator();
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
form.showLoadingIndicator();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
form.hideLoadingIndicator();
});
dispatcher.listenTo(collection, 'search', function () {
if (collection.length > 0) {
form.showFoundMessage(collection.totalCount);
results.render();
}
else {
form.showNotFoundMessage(collection.searchTerm);
}
facetsBarView.renderFacets(collection.facets);
form.hideLoadingIndicator();
});
dispatcher.listenTo(collection, 'error', function () {
form.showErrorMessage();
form.hideLoadingIndicator();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
form.hideLoadingIndicator();
});
dispatcher.listenTo(facetsBarView, 'addFilter', function (data) {
filters.addFilter(data);
});
dispatcher.listenTo(collection, 'error', function () {
form.showErrorMessage();
form.hideLoadingIndicator();
});
// kick off search on page refresh
form.doSearch(searchQuery);
dispatcher.listenTo(facetsBarView, 'addFilter', function (data) {
filters.addFilter(data);
});
};
// kick off search on page refresh
form.doSearch(searchQuery);
});
};
});
})(define || RequireJS.define);
RequireJS.require([
'jquery',
'backbone',
'js/discovery/app',
'js/discovery/collection',
'js/discovery/form',
'js/discovery/result_list_view',
'js/discovery/filter_bar_view',
'js/discovery/search_facets_view'
], function ($, Backbone, App, Collection, DiscoveryForm, ResultListView, FilterBarView, FacetsBarView) {
'use strict';
var app = new App(
Collection,
DiscoveryForm,
ResultListView,
FilterBarView,
FacetsBarView,
getParameterByName('search_query')
);
});
;(function (define) {
define(['backbone'], function(Backbone) {
'use strict';
return function (courseId, SearchRouter, SearchForm, SearchCollection, SearchListView) {
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) {
var router = new SearchRouter();
var form = new SearchForm();
var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
return function (courseId) {
dispatcher.listenTo(router, 'search', function (query) {
form.doSearch(query);
});
var router = new SearchRouter();
var form = new CourseSearchForm();
var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchResultsView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(form, 'search', function (query) {
results.showLoadingMessage();
collection.performSearch(query);
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(router, 'search', function (query) {
form.doSearch(query);
});
dispatcher.listenTo(form, 'clear', function () {
collection.cancelSearch();
results.clear();
router.navigate('');
});
dispatcher.listenTo(form, 'search', function (query) {
results.showLoadingMessage();
collection.performSearch(query);
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
});
dispatcher.listenTo(form, 'clear', function () {
collection.cancelSearch();
results.clear();
router.navigate('');
});
dispatcher.listenTo(collection, 'search', function () {
results.render();
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
});
dispatcher.listenTo(collection, 'search', function () {
results.render();
});
dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
});
};
dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
});
};
});
})(define || RequireJS.define);
RequireJS.require([
'jquery',
'backbone',
'js/search/course/search_app',
'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, SearchApp, SearchRouter, CourseSearchForm, SearchCollection, CourseSearchResultsView) {
'use strict';
var courseId = $('#courseware-search-results').data('courseId');
var app = new SearchApp(
courseId,
SearchRouter,
CourseSearchForm,
SearchCollection,
CourseSearchResultsView
);
Backbone.history.start();
});
;(function (define) {
define(['backbone'], function(Backbone) {
'use strict';
return function (SearchRouter, SearchForm, SearchCollection, SearchListView) {
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) {
var router = new SearchRouter();
var form = new SearchForm();
var collection = new SearchCollection([]);
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
return function () {
dispatcher.listenTo(router, 'search', function (query) {
form.doSearch(query);
});
var router = new SearchRouter();
var form = new SearchForm();
var collection = new SearchCollection([]);
var results = new SearchListView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(form, 'search', function (query) {
results.showLoadingMessage();
collection.performSearch(query);
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(router, 'search', function (query) {
form.doSearch(query);
});
dispatcher.listenTo(form, 'clear', function () {
collection.cancelSearch();
results.clear();
router.navigate('');
});
dispatcher.listenTo(form, 'search', function (query) {
results.showLoadingMessage();
collection.performSearch(query);
router.navigate('search/' + query, { replace: true });
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
});
dispatcher.listenTo(form, 'clear', function () {
collection.cancelSearch();
results.clear();
router.navigate('');
});
dispatcher.listenTo(results, 'reset', function () {
form.resetSearchForm();
});
dispatcher.listenTo(results, 'next', function () {
collection.loadNextPage();
});
dispatcher.listenTo(collection, 'search', function () {
results.render();
});
dispatcher.listenTo(results, 'reset', function () {
form.resetSearchForm();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
});
dispatcher.listenTo(collection, 'search', function () {
results.render();
});
dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
dispatcher.listenTo(collection, 'next', function () {
results.renderNext();
});
};
dispatcher.listenTo(collection, 'error', function () {
results.showErrorMessage();
});
});
};
});
})(define || RequireJS.define);
RequireJS.require([
'backbone',
'js/search/dashboard/search_app',
'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, SearchApp, SearchRouter, DashSearchForm, SearchCollection, DashSearchResultsView) {
'use strict';
var app = new SearchApp(
SearchRouter,
DashSearchForm,
SearchCollection,
DashSearchResultsView
);
Backbone.history.start();
});
define({
org: {
name: 'Organization',
terms: {
edX1: "edX_1"
}
},
modes: {
name: 'Course Type',
terms: {
honor: 'Honor',
verified: 'Verified'
}
},
language: {
en: 'English',
hr: 'Croatian'
}
});
......@@ -84,9 +84,7 @@
'js/ccx/schedule': 'js/ccx/schedule',
// edxnotes
'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min',
'course_discovery_meanings': 'js/spec/discovery/course_discovery_meanings'
'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min'
},
shim: {
'gettext': {
......
......@@ -13,8 +13,8 @@ define([
'js/search/dashboard/views/search_form',
'js/search/course/views/search_results_view',
'js/search/dashboard/views/search_results_view',
'js/search/course/search_app',
'js/search/dashboard/search_app'
'js/search/course/course_search_factory',
'js/search/dashboard/dashboard_search_factory'
], function(
$,
Sinon,
......@@ -30,8 +30,8 @@ define([
DashSearchForm,
CourseSearchResultsView,
DashSearchResultsView,
CourseSearchApp,
DashSearchApp
CourseSearchFactory,
DashboardSearchFactory
) {
'use strict';
......@@ -681,13 +681,7 @@ define([
this.server = Sinon.fakeServer.create();
var courseId = 'a/b/c';
this.app = new CourseSearchApp(
courseId,
SearchRouter,
CourseSearchForm,
SearchCollection,
CourseSearchResultsView
);
CourseSearchFactory(courseId);
spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#course-content');
this.$searchResults = $('#courseware-search-results');
......@@ -718,12 +712,7 @@ define([
loadTemplates.call(this);
this.server = Sinon.fakeServer.create();
this.app = new DashSearchApp(
SearchRouter,
DashSearchForm,
SearchCollection,
DashSearchResultsView
);
DashboardSearchFactory();
spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#my-courses');
......
......@@ -18,7 +18,10 @@
* done.
*/
modules: getModulesList([
'js/discovery/discovery_factory',
'js/groups/views/cohorts_dashboard_factory',
'js/search/course/course_search_factory',
'js/search/dashboard/dashboard_search_factory',
'js/student_account/views/account_settings_factory',
'js/student_account/views/finish_auth_factory',
'js/student_profile/views/learner_profile_factory',
......@@ -57,7 +60,7 @@
'underscore': 'empty:',
'logger': 'empty:',
'utility': 'empty:',
'URI': 'empty:'
'URI': 'empty:',
},
/**
......
......@@ -2,33 +2,27 @@
import json
from django.utils.translation import ugettext as _
from microsite_configuration import microsite
from openedx.core.lib.json_utils import EscapedEdxJSONEncoder
%>
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%block name="header_extras">
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
% for template_name in ["result_item", "filter_bar", "filter", "search_facets_list", "search_facets_section", "search_facet", "more_less_links"]:
<script type="text/template" id="${template_name}-tpl">
<%static:include path="discovery/${template_name}.underscore" />
</script>
% endfor
<script type="text/javascript">;(function (define) {{
define('course_discovery_meanings', function() {{
'use strict';
return ${json.dumps(course_discovery_meanings)};
}});
}})(define || RequireJS.define);
</script>
% endif
</%block>
<%block name="js_extra">
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%static:js group='discovery'/>
% endif
<%static:require_module module_name="js/discovery/discovery_factory" class_name="DiscoveryFactory">
DiscoveryFactory(
${json.dumps(course_discovery_meanings, cls=EscapedEdxJSONEncoder)},
getParameterByName('search_query')
);
</%static:require_module>
</%block>
% endif
<%block name="pagetitle">${_("Courses")}</%block>
<%
......
......@@ -66,7 +66,10 @@ ${page_title_breadcrumbs(course_name())}
<%static:js group='courseware'/>
<%static:js group='discussion'/>
% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
<%static:js group='courseware_search'/>
<%static:require_module module_name="js/search/course/course_search_factory" class_name="CourseSearchFactory">
var courseId = $('#courseware-search-results').data('courseId');
CourseSearchFactory(courseId);
</%static:require_module>
% endif
<%include file="../discussion/_js_body_dependencies.html" />
......
......@@ -45,7 +45,9 @@ from django.core.urlresolvers import reverse
});
</script>
% if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'):
<%static:js group='dashboard_search'/>
<%static:require_module module_name="js/search/dashboard/dashboard_search_factory" class_name="DashboardSearchFactory">
DashboardSearchFactory();
</%static:require_module>
% endif
</%block>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment