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) {
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
var facetsTypes = meanings;
......@@ -66,6 +68,6 @@ define(['backbone', 'course_discovery_meanings'], function(Backbone, meanings) {
};
});
});
})(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) {
return function (courseId) {
var router = new SearchRouter();
var form = new SearchForm();
var form = new CourseSearchForm();
var collection = new SearchCollection([], { courseId: courseId });
var results = new SearchListView({ collection: collection });
var results = new SearchResultsView({ collection: collection });
var dispatcher = _.clone(Backbone.Events);
dispatcher.listenTo(router, 'search', function (query) {
......@@ -45,6 +47,6 @@ define(['backbone'], function(Backbone) {
};
});
});
})(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) {
return function () {
var router = new SearchRouter();
var form = new SearchForm();
......@@ -49,6 +51,6 @@ define(['backbone'], function(Backbone) {
};
});
});
})(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([
'logger',
'common/js/spec_helpers/ajax_helpers',
'common/js/spec_helpers/template_helpers',
'js/discovery/app',
'js/discovery/discovery_factory',
'js/discovery/collection',
'js/discovery/form',
'js/discovery/result',
......@@ -14,16 +14,14 @@ define([
'js/discovery/filters',
'js/discovery/filter_bar_view',
'js/discovery/filter_view',
'js/discovery/search_facets_view',
'js/discovery/facet_view',
'js/discovery/facets_view'
'js/discovery/search_facets_view'
], function(
$,
Backbone,
Logger,
AjaxHelpers,
TemplateHelpers,
App,
DiscoveryFactory,
Collection,
DiscoveryForm,
ResultItem,
......@@ -33,9 +31,7 @@ define([
FiltersCollection,
FiltersBarView,
FilterView,
SearchFacetView,
FacetView,
FacetsView
SearchFacetView
) {
'use strict';
......@@ -113,6 +109,8 @@ define([
var SEARCH_FILTER = {"type": "search_string", "query": "search3"};
describe('Course Discovery', function () {
describe('Collection', function () {
beforeEach(function () {
......@@ -222,6 +220,16 @@ define([
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([
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('a[href="/courses/' + data.course + '/info"]');
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);
......@@ -499,12 +507,26 @@ define([
'templates/discovery/more_less_links'
]);
this.app = new App(
Collection,
DiscoveryForm,
ResultListView,
FiltersBarView,
SearchFacetView
DiscoveryFactory(
{
org: {
name: 'Organization',
terms: {
edX1: "edX_1"
}
},
modes: {
name: 'Course Type',
terms: {
honor: 'Honor',
verified: 'Verified'
}
},
language: {
en: 'English',
hr: 'Croatian'
}
}
);
});
......@@ -587,9 +609,6 @@ define([
expect($('.active-filter [data-value="edX1"]').length).toBe(1);
expect($('.active-filter [data-value="edX1"]').text().trim()).toBe("edX_1");
});
});
});
});
......@@ -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