Skip to content

Commit

Permalink
Fix part of oppia#6732: Migrate value_generators to webpack (oppia#6900)
Browse files Browse the repository at this point in the history
* migrate value_generators to webpack

* fix backend tests
  • Loading branch information
vojtechjelinek authored and seanlip committed Jun 11, 2019
1 parent 95dad90 commit bd95914
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 45 deletions.
5 changes: 0 additions & 5 deletions core/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from core import jobs_registry
from core.controllers import acl_decorators
from core.controllers import base
from core.controllers import editor
from core.domain import collection_services
from core.domain import config_domain
from core.domain import config_services
Expand All @@ -40,8 +39,6 @@
import feconf
import utils

import jinja2

current_user_services = models.Registry.import_current_user_services()


Expand Down Expand Up @@ -97,8 +94,6 @@ def get(self):
'one_off_job_specs': one_off_job_specs,
'recent_job_data': recent_job_data,
'unfinished_job_data': unfinished_job_data,
'value_generators_js': jinja2.utils.Markup(
editor.get_value_generators_js()),
'updatable_roles': {
role: role_services.HUMAN_READABLE_ROLES[role]
for role in role_services.UPDATABLE_ROLES
Expand Down
13 changes: 0 additions & 13 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from core.domain import stats_domain
from core.domain import stats_services
from core.domain import user_services
from core.domain import value_generators_domain
from core.domain import visualization_registry
from core.platform import models
import feconf
Expand All @@ -60,16 +59,6 @@
'platform for teaching and learning!'))


def get_value_generators_js():
"""Return a string that concatenates the JS for all value generators."""
all_value_generators = (
value_generators_domain.Registry.get_all_generator_classes())
value_generators_js = ''
for _, generator_cls in all_value_generators.iteritems():
value_generators_js += generator_cls.get_js_template()
return value_generators_js


def _require_valid_version(version_from_payload, exploration_version):
"""Check that the payload version matches the given exploration version."""
if version_from_payload is None:
Expand Down Expand Up @@ -148,8 +137,6 @@ def get(self, exploration_id):
'interaction_templates': jinja2.utils.Markup(
interaction_templates),
'meta_description': feconf.CREATE_PAGE_DESCRIPTION,
'value_generators_js': jinja2.utils.Markup(
get_value_generators_js()),
'visualizations_html': jinja2.utils.Markup(visualizations_html),
'INVALID_PARAMETER_NAMES': feconf.INVALID_PARAMETER_NAMES,
'SHOW_TRAINABLE_UNRESOLVED_ANSWERS': (
Expand Down
15 changes: 0 additions & 15 deletions core/domain/value_generators_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ def get_html_template(cls):
os.getcwd(), feconf.VALUE_GENERATORS_DIR, 'templates',
'%s.html' % cls.__name__))

@classmethod
def get_js_template(cls):
"""Returns the JavaScript template for the class.
Returns:
str. The JS template corresponding to the class.
"""

# NB: These generators should use only Angular templating. The
# variables they have access to are generatorId, initArgs,
# customizationArgs and objType.
return utils.get_file_contents(os.path.join(
os.getcwd(), feconf.VALUE_GENERATORS_DIR_FOR_JS, 'templates',
'%sDirective.js' % cls.__name__))

def generate_value(self, *args, **kwargs):
"""Generates a new value, using the given customization args.
Expand Down
1 change: 1 addition & 0 deletions core/templates/dev/head/pages/admin/AdminPageDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ require('pages/admin/config_tab/AdminConfigTabDirective.ts');
require('pages/admin/jobs_tab/AdminJobsTabDirective.ts');
require('pages/admin/misc_tab/AdminMiscTabDirective.ts');
require('pages/admin/roles_tab/AdminRolesTabDirective.ts');
require('value_generators/valueGeneratorsRequires.ts');

require('domain/objects/NumberWithUnitsObjectFactory.ts');
require('domain/utilities/UrlInterpolationService.ts');
Expand Down
4 changes: 0 additions & 4 deletions core/templates/dev/head/pages/admin/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@
</head>

<body>

<admin-page></admin-page>

@require('../footer_js_libs.html')
<script>
{{ value_generators_js }}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ require(
require('pages/exploration_player/ConversationSkinDirective.ts');
require('pages/exploration_player/ExplorationFooterDirective.ts');
require('pages/exploration_player/PlayerConstants.ts');
require('value_generators/valueGeneratorsRequires.ts');

require('domain/exploration/ParamChangesObjectFactory.ts');
require('domain/exploration/ParamSpecsObjectFactory.ts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
<script src="/third_party/static/d3js-3.4.11/d3.min.js"></script>
<script src="/templates/dev/head/mathjaxConfig.js"></script>
<script src="/third_party/static/MathJax-2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
{{ value_generators_js }}
</script>

<script src="/extensions/objects/templates/BooleanEditorDirective.js"></script>
<script src="/extensions/objects/templates/CodeStringEditorDirective.js"></script>
Expand Down
4 changes: 0 additions & 4 deletions extensions/value_generators/models/generators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def test_copier(self):
self.assertIn(
'init-args="initArgs" value="customizationArgs.value"',
generator.get_html_template())
self.assertIn(
'oppia.directive(\'copier\'', generator.get_js_template())

def test_random_selector(self):
generator = generators.RandomSelector()
Expand All @@ -46,5 +44,3 @@ def test_random_selector(self):
'schema="SCHEMA" '
'local-value="$parent.$parent.customizationArgs.list_of_values"',
generator.get_html_template())
self.assertIn(
'oppia.directive(\'randomSelector\'', generator.get_js_template())
20 changes: 20 additions & 0 deletions extensions/value_generators/valueGeneratorsRequires.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Requires for all the value generators directives.
*/

require('value_generators/templates/CopierDirective.ts');
require('value_generators/templates/RandomSelectorDirective.ts');
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"extensions/classifiers",
"extensions/interactions",
"extensions/objects",
"extensions/value_generators",
"extensions/visualizations",
"typings"
]
Expand Down

0 comments on commit bd95914

Please sign in to comment.