Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #2575: RTCs refactor second milestone #4017

Merged
merged 5 commits into from
Oct 26, 2017

Conversation

vojtechjelinek
Copy link
Contributor

  • Moved information about RTCs from Component.py files to specs.js file.
  • Loading specs.js directly from frontend and backend.
  • specs.js file validity checked in tests.

@codecov-io
Copy link

codecov-io commented Oct 23, 2017

Codecov Report

Merging #4017 into develop will decrease coverage by 0.02%.
The diff coverage is 81.81%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4017      +/-   ##
===========================================
- Coverage    45.87%   45.85%   -0.03%     
===========================================
  Files          300      300              
  Lines        21169    21196      +27     
  Branches      3327     3329       +2     
===========================================
+ Hits          9712     9719       +7     
- Misses       11457    11477      +20
Impacted Files Coverage Δ
...dev/head/services/SpeechSynthesisChunkerService.js 22.53% <ø> (+1.4%) ⬆️
core/templates/dev/head/app.js 44.69% <81.81%> (+0.02%) ⬆️
...ploration_player/AudioTranslationManagerService.js 44.73% <0%> (-1.54%) ⬇️
...ev/head/pages/exploration_editor/EditorServices.js 34.37% <0%> (-0.31%) ⬇️
core/templates/dev/head/pages/splash/Splash.js 4.76% <0%> (-0.24%) ⬇️
...head/pages/exploration_editor/ExplorationEditor.js 5.03% <0%> (-0.04%) ⬇️
...ges/exploration_editor/settings_tab/SettingsTab.js 0.64% <0%> (-0.01%) ⬇️
...ev/head/pages/exploration_player/PlayerServices.js 1.04% <0%> (ø) ⬆️
...tes/dev/head/services/explorationContextService.js 70.21% <0%> (+2.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57da863...9e65481. Read the comment docs.

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @vojtechjelinek! I think this looks great. I just have a few minor comments.

@@ -0,0 +1,231 @@
/* eslint-disable */
/* Don't modify anything outside the {} brackets.
* Insides of the {} brackets should be formatted as a JSON object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contents of the {} brackets should ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* JSON rules:
* 1. All keys and string values must be enclosed in double quotes.
* 2. Each key/value pair should be on a new line.
* 3. All values and keys must be constant, you can't use any Javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaScript

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
},
"default_value": "You have opened the collapsible block."
}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deindent by 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


# Check that the component directory exists.
component_dir = os.path.join(
feconf.RTE_EXTENSIONS_DIR, component_id)
feconf.RTE_EXTENSIONS_DIR, component_name)
self.assertTrue(os.path.isdir(component_dir))

# In this directory there should be a config .py file, an
# html file, a JS file, an icon .png file and a protractor.js file,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this sentence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# Check that the component id is valid.
self.assertTrue(self._is_camel_cased(component_id))
self.assertTrue(self._is_camel_cased(component_name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we keep it as component_id? ID implies uniqueness.

Perhaps we should rename backend_name to backend_id as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be id.

For the backend_name I was trying to be consistent with frontend_name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'm fine with changing both to id, if you like, but up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -72,8 +72,7 @@ oppia.constant('EVENT_ACTIVE_CARD_CHANGED', 'activeCardChanged');
// The conditioning on window.GLOBALS.RTE_COMPONENT_SPECS is because, in the
// Karma tests, this value is undefined.
oppia.constant(
'RTE_COMPONENT_SPECS',
window.GLOBALS.RTE_COMPONENT_SPECS ? window.GLOBALS.RTE_COMPONENT_SPECS : {});
'RTE_COMPONENT_SPECS', richTextComponents ? richTextComponents : {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we specify this in karma-globals then can we get rid of the ternary operator conditioning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -517,7 +517,9 @@ oppia.factory('rteHelperService', [
},
createToolbarIcon: function(componentDefn) {
var el = $('<img/>');
el.attr('src', componentDefn.iconDataUrl);
el.attr('src',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break after '(' if contents of (...) span multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var interpolatedUrl = $interpolate(
componentDefn.previewUrlTemplate, false, null, true)(
customizationArgsDict);
var componentPreviewUrl = componentDefn.previewUrlTemplate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be called componentPreviewUrlTemplate? A URL template != URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry -- noticed a few more things!

if 'BaseRichTextComponent' in ancestor_names:
cls._rte_components[clazz.__name__] = clazz()
with open(feconf.RTE_EXTENSIONS_SPECS_PATH, 'r') as f:
cls._rte_components = constants.parse_json_from_js(f)

@classmethod
def get_all_rte_components(cls):
"""Get a list of instances of all custom RTE components."""
if len(cls._rte_components) == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading correctly, the data looks like a dict, but the docstring here and the use of len() indicate a list. Is this a mistake? If so let's fix this to say something like "if not cls._rte_components" and change the docstring to "Get a dict mapping RTE component IDs to their definitions." or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

componentDefn.previewUrlTemplate, false, null, true)(
customizationArgsDict);
var componentPreviewUrlTemplate = componentDefn.previewUrlTemplate;
if (componentDefn.previewUrlTemplate.startsWith(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try indexOf() === 0 here; startsWith is less browser-compatible. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,231 @@
/* eslint-disable */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I just realized, if this is going in assets, should we pull protractor.js out of extensions/rich_text_components as well and move it to somewhere in core/tests? Then delete extensions/rich_text_components altogether?

On the other hand, if extensions/rich_text_components is staying, then shouldn't this file go in it (like rule_templates.json goes in extensions/interactions)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need extensions/rich_text_components because there are other files we use. I would have to create new rule for this file in app.yaml in order to serve it from extensions/rich_text_components

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. How does extensions/interactions/rule_templates.json do it?

Copy link
Contributor Author

@vojtechjelinek vojtechjelinek Oct 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That file is not directly loaded from the frontend.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, OK. In that case, let's keep it in assets/ and put a README.md file in extensions/rich_text_components that points to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,6 @@
Steps to successfully add new Rich Text Component:
1. Create folder in _extensions/rich_text_components_ with all the files
2. Create new record in JSON in _asseets/rich_text_components_specs.js_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: assets is misspelled.

2. Create new record in JSON in _asseets/rich_text_components_specs.js_
3. Add script-imports into _core/templates/dev/head/components/rich_text_components.html_

[More in Wiki](https://github.com/oppia/oppia/wiki/Rich-Text-Editor-%28RTE%29-Overview)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest linking more specifically, to this: https://github.com/oppia/oppia/wiki/Rich-Text-Editor-%28RTE%29-Overview#rich-text-components

Please also update the wiki page. Thanks!

Copy link
Member

@seanlip seanlip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small issues but otherwise LGTM; please feel free to submit after addressing them. Thanks!

@seanlip seanlip merged commit 65745a1 into oppia:develop Oct 26, 2017
@vojtechjelinek vojtechjelinek deleted the RTCs-refactor2 branch June 22, 2018 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants