Skip to content

Commit

Permalink
Reapply the XBlock RequireJS -> Webpack changes
Browse files Browse the repository at this point in the history
This reverts commit 105db2c, reversing
changes made to 4474575.
  • Loading branch information
cpennington committed Jun 28, 2018
1 parent 9375bda commit 07a15c6
Show file tree
Hide file tree
Showing 162 changed files with 7,347 additions and 6,724 deletions.
16 changes: 16 additions & 0 deletions cms/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,19 @@ def _django_clear_site_cache():
with what has been working for us so far.
"""
pass


@pytest.fixture(autouse=True)
def no_webpack_loader(monkeypatch):
"""
Monkeypatch webpack_loader to make sure that webpack assets don't need to be
compiled before unit tests are run.
"""
monkeypatch.setattr(
"webpack_loader.templatetags.webpack_loader.render_bundle",
lambda entry, extension=None, config='DEFAULT', attrs='': ''
)
monkeypatch.setattr(
"webpack_loader.utils.get_as_tags",
lambda entry, extension=None, config='DEFAULT', attrs='': []
)
31 changes: 20 additions & 11 deletions cms/djangoapps/contentstore/features/advanced_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@
@step('I select the Advanced Settings$')
def i_select_advanced_settings(step):

world.click_course_settings()

# The click handlers are set up so that if you click <body>
# the menu disappears. This means that if we're even a *little*
# bit off on the last item ('Advanced Settings'), the menu
# will close and the test will fail.
# For this reason, we retrieve the link and visit it directly
# This is what the browser *should* be doing, since it's just a native
# link with no JavaScript involved.
link_css = 'li.nav-course-settings-advanced a'
world.wait_for_visible(link_css)
world.wait_for_js_to_load() # pylint: disable=no-member
world.wait_for_js_variable_truthy('window.studioNavMenuActive') # pylint: disable=no-member

for _ in range(5):
world.click_course_settings() # pylint: disable=no-member

# The click handlers are set up so that if you click <body>
# the menu disappears. This means that if we're even a *little*
# bit off on the last item ('Advanced Settings'), the menu
# will close and the test will fail.
# For this reason, we retrieve the link and visit it directly
# This is what the browser *should* be doing, since it's just a native
# link with no JavaScript involved.
link_css = 'li.nav-course-settings-advanced a'
try:
world.wait_for_visible(link_css) # pylint: disable=no-member
break
except AssertionError:
continue

link = world.css_find(link_css).first['href']
world.visit(link)

Expand Down
1 change: 0 additions & 1 deletion cms/djangoapps/contentstore/features/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def create_unit_from_course_outline():
world.css_click(selector)

world.wait_for_mathjax()
world.wait_for_xmodule()
world.wait_for_loading()

assert world.is_css_present('ul.new-component-type')
Expand Down
5 changes: 0 additions & 5 deletions cms/djangoapps/contentstore/features/html-editor.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ Feature: CMS.HTML Editor
Then I can modify the display name
And my display name change is persisted on save

Scenario: Edit High Level source is available for LaTeX html
Given I have created an E-text Written in LaTeX
When I edit and select Settings
Then Edit High Level Source is visible

Scenario: TinyMCE image plugin sets urls correctly
Given I have created a Blank HTML Page
When I edit the page
Expand Down
15 changes: 0 additions & 15 deletions cms/djangoapps/contentstore/features/problem-editor.feature
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,7 @@ Feature: CMS.Problem Editor
And I can modify the display name
Then If I press Cancel my changes are not persisted

Scenario: Edit High Level source is available for LaTeX problem
Given I have created a LaTeX Problem
When I edit and select Settings
Then Edit High Level Source is visible

Scenario: Cheat sheet visible on toggle
Given I have created a Blank Common Problem
And I can edit the problem
Then I can see cheatsheet

Scenario: Reply on Annotation and Return to Annotation link works for Annotation problem
Given I have created a unit with advanced module "annotatable"
And I have created an advanced component "Annotation" of type "annotatable"
And I have created an advanced problem of type "Blank Advanced Problem"
And I edit first blank advanced problem for annotation response
When I mouseover on "annotatable-span"
Then I can see Reply to Annotation link
And I see that page has scrolled "down" when I click on "annotatable-reply" link
And I see that page has scrolled "up" when I click on "annotation-return" link
12 changes: 11 additions & 1 deletion cms/djangoapps/contentstore/views/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
from xmodule.partitions.partitions_service import PartitionService
from xmodule.services import SettingsService
from xmodule.studio_editable import has_author_view
from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem
from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem, XModule, XModuleDescriptor
import webpack_loader.utils

from .helpers import render_from_lms
from .session_kv_store import SessionKeyValueStore
Expand Down Expand Up @@ -298,6 +299,15 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False):
'language': getattr(course, 'language', None)
}

if isinstance(xblock, (XModule, XModuleDescriptor)):
# Add the webpackified asset tags
class_name = getattr(xblock.__class__, 'unmixed_class', xblock.__class__).__name__
for tag in webpack_loader.utils.get_as_tags(class_name):
frag.add_resource(tag, mimetype='text/html', placement='head')

for tag in webpack_loader.utils.get_as_tags("js/factories/xblock_validation"):
frag.add_resource(tag, mimetype='text/html', placement='head')

html = render_to_string('studio_xblock_wrapper.html', template_context)
frag = wrap_fragment(frag, html)
return frag
Expand Down
60 changes: 60 additions & 0 deletions cms/djangoapps/pipeline_js/js/xmodule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This file is designed to load all the XModule Javascript files in one wad
// using requirejs. It is passed through the Mako template system, which
// populates the `urls` variable with a list of paths to XModule JS files.
// These files assume that several libraries are available and bound to
// variables in the global context, so we load those libraries with requirejs
// and attach them to the global context manually.
define(
[
'jquery', 'underscore', 'codemirror', 'tinymce', 'scriptjs',
'jquery.tinymce', 'jquery.qtip', 'jquery.scrollTo', 'jquery.flot',
'jquery.cookie',
'utility'
],
function($, _, CodeMirror, tinymce, $script) {
'use strict';

window.$ = $;
window._ = _;
$script(
'//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js' +
'?config=TeX-MML-AM_SVG&delayStartupUntil=configured',
'mathjax'
);
window.CodeMirror = CodeMirror;
window.RequireJS = {
requirejs: {}, // This is never used by current xmodules
require: $script, // $script([deps], callback) acts approximately like the require function
define: define
};
/**
* Loads all modules one-by-one in exact order.
* The module should be used until we'll use RequireJS for XModules.
* @param {Array} modules A list of urls.
* @return {jQuery Promise}
**/
function requireQueue(modules) {
var deferred = $.Deferred();
function loadScript(queue) {
$script.ready('mathjax', function() {
// Loads the next script if queue is not empty.
if (queue.length) {
$script([queue.shift()], function() {
loadScript(queue);
});
} else {
deferred.resolve();
}
});
}

loadScript(modules.concat());
return deferred.promise();
}

// if (!window.xmoduleUrls) {
// throw Error('window.xmoduleUrls must be defined');
// }
return requireQueue([]);
}
);
45 changes: 0 additions & 45 deletions cms/djangoapps/pipeline_js/templates/xmodule.js

This file was deleted.

10 changes: 0 additions & 10 deletions cms/djangoapps/pipeline_js/urls.py

This file was deleted.

18 changes: 18 additions & 0 deletions cms/djangoapps/pipeline_js/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Utilities for returning XModule JS (used by requirejs)
"""

from django.conf import settings
from django.contrib.staticfiles.storage import staticfiles_storage


def get_xmodule_urls():
"""
Returns a list of the URLs to hit to grab all the XModule JS
"""
pipeline_js_settings = settings.PIPELINE_JS["module-js"]
if settings.DEBUG:
paths = [path.replace(".coffee", ".js") for path in pipeline_js_settings["source_filenames"]]
else:
paths = [pipeline_js_settings["output_filename"]]
return [staticfiles_storage.url(path) for path in paths]
44 changes: 0 additions & 44 deletions cms/djangoapps/pipeline_js/views.py

This file was deleted.

4 changes: 0 additions & 4 deletions cms/envs/acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ def seed():
# We do not yet understand why this occurs. Setting this to true is a stopgap measure
USE_I18N = True

# Override the test stub webpack_loader that is installed in test.py.
INSTALLED_APPS = [app for app in INSTALLED_APPS if app != 'openedx.tests.util.webpack_loader']
INSTALLED_APPS.append('webpack_loader')

# Include the lettuce app for acceptance testing, including the 'harvest' django-admin command
# django.contrib.staticfiles used to be loaded by lettuce, now we must add it ourselves
# django.contrib.staticfiles is not added to lms as there is a ^/static$ route built in to the app
Expand Down
3 changes: 3 additions & 0 deletions cms/envs/bok_choy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
# Needed to enable licensing on video modules
XBLOCK_SETTINGS.update({'VideoDescriptor': {'licensing_enabled': True}})

# Capture the console log via template includes, until webdriver supports log capture again
CAPTURE_CONSOLE_LOG = True

############################ STATIC FILES #############################

# Enable debug so that static assets are served by Django
Expand Down
6 changes: 6 additions & 0 deletions cms/envs/bok_choy_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
}

LOGGING['loggers']['tracking']['handlers'] = ['console']

# Point the URL used to test YouTube availability to our stub YouTube server
BOK_CHOY_HOST = os.environ['BOK_CHOY_HOSTNAME']
YOUTUBE['API'] = "http://{}:{}/get_youtube_api/".format(BOK_CHOY_HOST, YOUTUBE_PORT)
YOUTUBE['METADATA_URL'] = "http://{}:{}/test_youtube/".format(BOK_CHOY_HOST, YOUTUBE_PORT)
YOUTUBE['TEXT_API']['url'] = "{}:{}/test_transcripts_youtube/".format(BOK_CHOY_HOST, YOUTUBE_PORT)
2 changes: 0 additions & 2 deletions cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

# Want static files in the same dir for running on jenkins.
STATIC_ROOT = TEST_ROOT / "staticfiles"
INSTALLED_APPS = [app for app in INSTALLED_APPS if app != 'webpack_loader']
INSTALLED_APPS.append('openedx.tests.util.webpack_loader')
WEBPACK_LOADER['DEFAULT']['STATS_FILE'] = STATIC_ROOT / "webpack-stats.json"

GITHUB_REPO_ROOT = TEST_ROOT / "data"
Expand Down
7 changes: 1 addition & 6 deletions cms/static/cms/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,19 @@
modules: getModulesList([
'js/factories/asset_index',
'js/factories/base',
'js/factories/container',
'js/factories/course_create_rerun',
'js/factories/course_info',
'js/factories/edit_tabs',
'js/factories/export',
'js/factories/group_configurations',
'js/certificates/factories/certificates_page_factory',
'js/factories/index',
'js/factories/library',
'js/factories/manage_users',
'js/factories/outline',
'js/factories/register',
'js/factories/settings',
'js/factories/settings_advanced',
'js/factories/settings_graders',
'js/factories/textbooks',
'js/factories/videos_index',
'js/factories/xblock_validation'
'js/factories/videos_index'
]),
/**
* By default all the configuration for optimization happens from the command
Expand Down
Loading

0 comments on commit 07a15c6

Please sign in to comment.