Commit c67ee94d by Toby Lawrence Committed by GitHub

Merge pull request #13996 from edx/PERF-321

[PERF-321] Move heavy JS files for WordCloud out of lms-modules.js
parents f7727fe7 a4922766
......@@ -15,6 +15,7 @@ from xmodule.editing_module import MetadataOnlyEditingDescriptor
from xmodule.x_module import XModule
from xblock.fields import Scope, Dict, Boolean, List, Integer, String
from xblock.fragment import Fragment
log = logging.getLogger(__name__)
......@@ -93,10 +94,6 @@ class WordCloudModule(WordCloudFields, XModule):
js = {
'js': [
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/word_cloud/d3.min.js'),
resource_string(__name__, 'js/src/word_cloud/d3.layout.cloud.js'),
resource_string(__name__, 'js/src/word_cloud/word_cloud.js'),
resource_string(__name__, 'js/src/word_cloud/word_cloud_main.js'),
],
}
css = {'scss': [resource_string(__name__, 'css/word_cloud/display.scss')]}
......@@ -237,9 +234,13 @@ class WordCloudModule(WordCloudFields, XModule):
'error': 'Unknown Command!'
})
def get_html(self):
"""Template rendering."""
context = {
def student_view(self, context):
"""
Renders the output that a student will see.
"""
fragment = Fragment()
fragment.add_content(self.system.render_template('word_cloud.html', {
'ajax_url': self.system.ajax_url,
'display_name': self.display_name,
'instructions': self.instructions,
......@@ -247,13 +248,24 @@ class WordCloudModule(WordCloudFields, XModule):
'element_id': self.location.html_id(),
'num_inputs': self.num_inputs,
'submitted': self.submitted,
}
self.content = self.system.render_template('word_cloud.html', context)
return self.content
}))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/d3.min.js'))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/d3.layout.cloud.js'))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/word_cloud.js'))
fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/word_cloud_main.js'))
return fragment
def author_view(self, context):
"""
Renders the output that an author will see.
"""
return self.student_view(context)
class WordCloudDescriptor(WordCloudFields, MetadataOnlyEditingDescriptor, EmptyDataRawDescriptor):
"""Descriptor for WordCloud Xmodule."""
module_class = WordCloudModule
resources_dir = None
resources_dir = 'assets/word_cloud'
template_dir_name = 'word_cloud'
......@@ -14,6 +14,15 @@ class TestWordCloud(BaseTestXmodule):
"""Integration test for word cloud xmodule."""
CATEGORY = "word_cloud"
def _get_resource_url(self, item):
"""
Creates a resource URL for a given asset that is compatible with this old XModule testing stuff.
"""
display_name = self.item_descriptor.display_name.replace(' ', '_')
return "resource/i4x://{}/{}/word_cloud/{}/{}".format(
self.course.id.org, self.course.id.course, display_name, item
)
def _get_users_state(self):
"""Return current state for each user:
......@@ -241,7 +250,9 @@ class TestWordCloud(BaseTestXmodule):
)
def test_word_cloud_constructor(self):
"""Make sure that all parameters extracted correctly from xml"""
"""
Make sure that all parameters extracted correctly from xml.
"""
fragment = self.runtime.render(self.item_descriptor, STUDENT_VIEW)
expected_context = {
'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url,
......@@ -250,6 +261,7 @@ class TestWordCloud(BaseTestXmodule):
'element_class': self.item_descriptor.location.category,
'element_id': self.item_descriptor.location.html_id(),
'num_inputs': 5, # default value
'submitted': False, # default value
'submitted': False, # default value,
}
self.assertEqual(fragment.content, self.runtime.render_template('word_cloud.html', expected_context))
......@@ -6,7 +6,6 @@
class="${element_class}"
data-ajax-url="${ajax_url}"
>
% if display_name:
<h3 class="hd hd-3" id="word_cloud_${element_id}_heading">${display_name}</h3>
% endif
......
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