Commit ad16f9f9 by cahrens

Optimize search usages.

parent eff80bae
...@@ -1212,8 +1212,6 @@ courseware_js = ( ...@@ -1212,8 +1212,6 @@ courseware_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/modules/**/*.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 # Before a student accesses courseware, we do not
# need many of the JS dependencies. This includes # need many of the JS dependencies. This includes
...@@ -1252,7 +1250,6 @@ base_application_js = [ ...@@ -1252,7 +1250,6 @@ base_application_js = [
dashboard_js = ( dashboard_js = (
sorted(rooted_glob(PROJECT_ROOT / 'static', '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')) 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')) 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')) open_ended_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'coffee/src/open_ended/**/*.js'))
...@@ -1338,8 +1335,6 @@ incourse_reverify_js = [ ...@@ -1338,8 +1335,6 @@ incourse_reverify_js = [
ccx_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/ccx/**/*.js')) ccx_js = sorted(rooted_glob(PROJECT_ROOT / 'static', 'js/ccx/**/*.js'))
discovery_js = ['js/discovery/main.js']
certificates_web_view_js = [ certificates_web_view_js = [
'js/vendor/jquery.min.js', 'js/vendor/jquery.min.js',
'js/vendor/jquery.cookie.js', 'js/vendor/jquery.cookie.js',
...@@ -1504,10 +1499,6 @@ PIPELINE_JS = { ...@@ -1504,10 +1499,6 @@ PIPELINE_JS = {
'source_filenames': courseware_js, 'source_filenames': courseware_js,
'output_filename': 'js/lms-courseware.js', 'output_filename': 'js/lms-courseware.js',
}, },
'courseware_search': {
'source_filenames': courseware_search_js,
'output_filename': 'js/lms-courseware-search.js',
},
'base_vendor': { 'base_vendor': {
'source_filenames': base_vendor_js, 'source_filenames': base_vendor_js,
'output_filename': 'js/lms-base-vendor.js', 'output_filename': 'js/lms-base-vendor.js',
...@@ -1548,10 +1539,6 @@ PIPELINE_JS = { ...@@ -1548,10 +1539,6 @@ PIPELINE_JS = {
'source_filenames': dashboard_js, 'source_filenames': dashboard_js,
'output_filename': 'js/dashboard.js' 'output_filename': 'js/dashboard.js'
}, },
'dashboard_search': {
'source_filenames': dashboard_search_js,
'output_filename': 'js/dashboard-search.js',
},
'student_account': { 'student_account': {
'source_filenames': student_account_js, 'source_filenames': student_account_js,
'output_filename': 'js/student_account.js' 'output_filename': 'js/student_account.js'
...@@ -1576,10 +1563,6 @@ PIPELINE_JS = { ...@@ -1576,10 +1563,6 @@ PIPELINE_JS = {
'source_filenames': ['js/footer-edx.js'], 'source_filenames': ['js/footer-edx.js'],
'output_filename': 'js/footer-edx.js' 'output_filename': 'js/footer-edx.js'
}, },
'discovery': {
'source_filenames': discovery_js,
'output_filename': 'js/discovery.js'
},
'certificates_wv': { 'certificates_wv': {
'source_filenames': certificates_web_view_js, 'source_filenames': certificates_web_view_js,
'output_filename': 'js/certificates/web_view.js' 'output_filename': 'js/certificates/web_view.js'
......
;(function (define) { ;(function (define) {
define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) {
'use strict'; 'use strict';
return function (Collection, Form, ResultListView, FilterBarView, FacetsBarView, searchQuery) { 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) {
return function (meanings, searchQuery) {
//facet types configuration - set default display names //facet types configuration - set default display names
var facetsTypes = meanings; var facetsTypes = meanings;
...@@ -66,6 +68,6 @@ define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) { ...@@ -66,6 +68,6 @@ define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) {
}; };
}); });
})(define || RequireJS.define); })(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) { ;(function (define) {
define(['backbone'], function(Backbone) {
'use strict'; '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) {
return function (courseId) {
var router = new SearchRouter(); var router = new SearchRouter();
var form = new SearchForm(); var form = new CourseSearchForm();
var collection = new SearchCollection([], { courseId: courseId }); var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchListView({ collection: collection }); var results = new SearchResultsView({ collection: collection });
var dispatcher = _.clone(Backbone.Events); var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(router, 'search', function (query) { dispatcher.listenTo(router, 'search', function (query) {
...@@ -45,6 +47,6 @@ define(['backbone'], function(Backbone) { ...@@ -45,6 +47,6 @@ define(['backbone'], function(Backbone) {
}; };
}); });
})(define || RequireJS.define); })(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) { ;(function (define) {
define(['backbone'], function(Backbone) {
'use strict'; '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) {
return function () {
var router = new SearchRouter(); var router = new SearchRouter();
var form = new SearchForm(); var form = new SearchForm();
...@@ -49,6 +51,6 @@ define(['backbone'], function(Backbone) { ...@@ -49,6 +51,6 @@ define(['backbone'], function(Backbone) {
}; };
}); });
})(define || RequireJS.define); })(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'
}
});
...@@ -4,7 +4,7 @@ define([ ...@@ -4,7 +4,7 @@ define([
'logger', 'logger',
'common/js/spec_helpers/ajax_helpers', 'common/js/spec_helpers/ajax_helpers',
'common/js/spec_helpers/template_helpers', 'common/js/spec_helpers/template_helpers',
'js/discovery/app', 'js/discovery/discovery_factory',
'js/discovery/collection', 'js/discovery/collection',
'js/discovery/form', 'js/discovery/form',
'js/discovery/result', 'js/discovery/result',
...@@ -14,16 +14,14 @@ define([ ...@@ -14,16 +14,14 @@ define([
'js/discovery/filters', 'js/discovery/filters',
'js/discovery/filter_bar_view', 'js/discovery/filter_bar_view',
'js/discovery/filter_view', 'js/discovery/filter_view',
'js/discovery/search_facets_view', 'js/discovery/search_facets_view'
'js/discovery/facet_view',
'js/discovery/facets_view'
], function( ], function(
$, $,
Backbone, Backbone,
Logger, Logger,
AjaxHelpers, AjaxHelpers,
TemplateHelpers, TemplateHelpers,
App, DiscoveryFactory,
Collection, Collection,
DiscoveryForm, DiscoveryForm,
ResultItem, ResultItem,
...@@ -33,9 +31,7 @@ define([ ...@@ -33,9 +31,7 @@ define([
FiltersCollection, FiltersCollection,
FiltersBarView, FiltersBarView,
FilterView, FilterView,
SearchFacetView, SearchFacetView
FacetView,
FacetsView
) { ) {
'use strict'; 'use strict';
...@@ -113,6 +109,8 @@ define([ ...@@ -113,6 +109,8 @@ define([
var SEARCH_FILTER = {"type": "search_string", "query": "search3"}; var SEARCH_FILTER = {"type": "search_string", "query": "search3"};
describe('Course Discovery', function () {
describe('Collection', function () { describe('Collection', function () {
beforeEach(function () { beforeEach(function () {
...@@ -222,6 +220,16 @@ define([ ...@@ -222,6 +220,16 @@ define([
expect(this.result.get('id')).toBeDefined(); expect(this.result.get('id')).toBeDefined();
}); });
it('renders correctly', function () {
var data = this.item.model.attributes;
this.item.render();
expect(this.item.$el).toContainHtml(data.content.display_name);
expect(this.item.$el).toContain('a[href="/courses/' + data.course + '/about"]');
expect(this.item.$el).toContain('img[src="' + data.image_url + '"]');
expect(this.item.$el.find('.course-name')).toContainHtml(data.org);
expect(this.item.$el.find('.course-name')).toContainHtml(data.content.number);
expect(this.item.$el.find('.course-name')).toContainHtml(data.content.display_name);
expect(this.item.$el.find('.course-date')).toContainHtml('Jan 01, 1970');
}); });
...@@ -238,7 +246,7 @@ define([ ...@@ -238,7 +246,7 @@ define([
var data = this.item.model.attributes; var data = this.item.model.attributes;
this.item.render(); this.item.render();
expect(this.item.$el).toContainHtml(data.content.display_name); expect(this.item.$el).toContainHtml(data.content.display_name);
expect(this.item.$el).toContain('a[href="/courses/' + data.course + '/about"]'); expect(this.item.$el).toContain('a[href="/courses/' + data.course + '/info"]');
expect(this.item.$el).toContain('img[src="' + data.image_url + '"]'); expect(this.item.$el).toContain('img[src="' + data.image_url + '"]');
expect(this.item.$el.find('.course-name')).toContainHtml(data.org); expect(this.item.$el.find('.course-name')).toContainHtml(data.org);
expect(this.item.$el.find('.course-name')).toContainHtml(data.content.number); expect(this.item.$el.find('.course-name')).toContainHtml(data.content.number);
...@@ -499,12 +507,26 @@ define([ ...@@ -499,12 +507,26 @@ define([
'templates/discovery/more_less_links' 'templates/discovery/more_less_links'
]); ]);
this.app = new App( DiscoveryFactory(
Collection, {
DiscoveryForm, org: {
ResultListView, name: 'Organization',
FiltersBarView, terms: {
SearchFacetView edX1: "edX_1"
}
},
modes: {
name: 'Course Type',
terms: {
honor: 'Honor',
verified: 'Verified'
}
},
language: {
en: 'English',
hr: 'Croatian'
}
}
); );
}); });
...@@ -587,9 +609,6 @@ define([ ...@@ -587,9 +609,6 @@ define([
expect($('.active-filter [data-value="edX1"]').length).toBe(1); expect($('.active-filter [data-value="edX1"]').length).toBe(1);
expect($('.active-filter [data-value="edX1"]').text().trim()).toBe("edX_1"); expect($('.active-filter [data-value="edX1"]').text().trim()).toBe("edX_1");
}); });
}); });
});
}); });
...@@ -84,9 +84,7 @@ ...@@ -84,9 +84,7 @@
'js/ccx/schedule': 'js/ccx/schedule', 'js/ccx/schedule': 'js/ccx/schedule',
// edxnotes // edxnotes
'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min', 'annotator_1.2.9': 'xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min'
'course_discovery_meanings': 'js/spec/discovery/course_discovery_meanings'
}, },
shim: { shim: {
'gettext': { 'gettext': {
......
...@@ -13,8 +13,8 @@ define([ ...@@ -13,8 +13,8 @@ define([
'js/search/dashboard/views/search_form', 'js/search/dashboard/views/search_form',
'js/search/course/views/search_results_view', 'js/search/course/views/search_results_view',
'js/search/dashboard/views/search_results_view', 'js/search/dashboard/views/search_results_view',
'js/search/course/search_app', 'js/search/course/course_search_factory',
'js/search/dashboard/search_app' 'js/search/dashboard/dashboard_search_factory'
], function( ], function(
$, $,
Sinon, Sinon,
...@@ -30,8 +30,8 @@ define([ ...@@ -30,8 +30,8 @@ define([
DashSearchForm, DashSearchForm,
CourseSearchResultsView, CourseSearchResultsView,
DashSearchResultsView, DashSearchResultsView,
CourseSearchApp, CourseSearchFactory,
DashSearchApp DashboardSearchFactory
) { ) {
'use strict'; 'use strict';
...@@ -681,13 +681,7 @@ define([ ...@@ -681,13 +681,7 @@ define([
this.server = Sinon.fakeServer.create(); this.server = Sinon.fakeServer.create();
var courseId = 'a/b/c'; var courseId = 'a/b/c';
this.app = new CourseSearchApp( CourseSearchFactory(courseId);
courseId,
SearchRouter,
CourseSearchForm,
SearchCollection,
CourseSearchResultsView
);
spyOn(Backbone.history, 'navigate'); spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#course-content'); this.$contentElement = $('#course-content');
this.$searchResults = $('#courseware-search-results'); this.$searchResults = $('#courseware-search-results');
...@@ -718,12 +712,7 @@ define([ ...@@ -718,12 +712,7 @@ define([
loadTemplates.call(this); loadTemplates.call(this);
this.server = Sinon.fakeServer.create(); this.server = Sinon.fakeServer.create();
this.app = new DashSearchApp( DashboardSearchFactory();
SearchRouter,
DashSearchForm,
SearchCollection,
DashSearchResultsView
);
spyOn(Backbone.history, 'navigate'); spyOn(Backbone.history, 'navigate');
this.$contentElement = $('#my-courses'); this.$contentElement = $('#my-courses');
......
...@@ -18,7 +18,10 @@ ...@@ -18,7 +18,10 @@
* done. * done.
*/ */
modules: getModulesList([ modules: getModulesList([
'js/discovery/discovery_factory',
'js/groups/views/cohorts_dashboard_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/account_settings_factory',
'js/student_account/views/finish_auth_factory', 'js/student_account/views/finish_auth_factory',
'js/student_profile/views/learner_profile_factory', 'js/student_profile/views/learner_profile_factory',
...@@ -57,7 +60,7 @@ ...@@ -57,7 +60,7 @@
'underscore': 'empty:', 'underscore': 'empty:',
'logger': 'empty:', 'logger': 'empty:',
'utility': 'empty:', 'utility': 'empty:',
'URI': 'empty:' 'URI': 'empty:',
}, },
/** /**
......
...@@ -2,33 +2,27 @@ ...@@ -2,33 +2,27 @@
import json import json
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from microsite_configuration import microsite from microsite_configuration import microsite
from openedx.core.lib.json_utils import EscapedEdxJSONEncoder
%> %>
<%inherit file="../main.html" /> <%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%block name="header_extras"> <%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"]: % 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"> <script type="text/template" id="${template_name}-tpl">
<%static:include path="discovery/${template_name}.underscore" /> <%static:include path="discovery/${template_name}.underscore" />
</script> </script>
% endfor % endfor
<script type="text/javascript">;(function (define) {{ <%static:require_module module_name="js/discovery/discovery_factory" class_name="DiscoveryFactory">
define('course_discovery_meanings', function() {{ DiscoveryFactory(
'use strict'; ${json.dumps(course_discovery_meanings, cls=EscapedEdxJSONEncoder)},
return ${json.dumps(course_discovery_meanings)}; getParameterByName('search_query')
}}); );
}})(define || RequireJS.define); </%static:require_module>
</script>
% endif
</%block>
<%block name="js_extra">
% if settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'):
<%static:js group='discovery'/>
% endif
</%block> </%block>
% endif
<%block name="pagetitle">${_("Courses")}</%block> <%block name="pagetitle">${_("Courses")}</%block>
<% <%
......
...@@ -66,7 +66,10 @@ ${page_title_breadcrumbs(course_name())} ...@@ -66,7 +66,10 @@ ${page_title_breadcrumbs(course_name())}
<%static:js group='courseware'/> <%static:js group='courseware'/>
<%static:js group='discussion'/> <%static:js group='discussion'/>
% if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'): % 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 % endif
<%include file="../discussion/_js_body_dependencies.html" /> <%include file="../discussion/_js_body_dependencies.html" />
......
...@@ -45,7 +45,9 @@ from django.core.urlresolvers import reverse ...@@ -45,7 +45,9 @@ from django.core.urlresolvers import reverse
}); });
</script> </script>
% if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'): % 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 % endif
</%block> </%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