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

Added block previews #1677

Merged
merged 8 commits into from
Apr 11, 2016
Merged

Added block previews #1677

merged 8 commits into from
Apr 11, 2016

Conversation

kahkhang
Copy link
Contributor

@kahkhang kahkhang commented Apr 3, 2016

Renders Tabs, Collapsible, Image, Video RTE components as bigger blocks in the rich text editor. For Image component, the actual image is rendered, and for the Video component, a Youtube thumbnail is rendered. Addresses #909.

dir_contents = self._listdir_omit_ignored(component_dir)
self.assertLessEqual(len(dir_contents), 5)
self.assertLessEqual(len(dir_contents), 6)
Copy link
Member

Choose a reason for hiding this comment

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

Should probably add some additional checks in the lines below to enforce naming conventions.

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

@codecov-io
Copy link

Current coverage is 44.00%

Merging #1677 into develop will decrease coverage by -26.97% as of 64819c8

@@            develop   #1677   diff @@
=======================================
  Files           374     185     -189
  Stmts         37633   15058   -22575
  Branches       2405    2412       +7
  Methods           0       0         
=======================================
- Hit           26711    6626   -20085
- Partial         584     592       +8
+ Missed        10338    7840    -2498

Review entire Coverage Diff as of 64819c8

Powered by Codecov. Updated on successful CI builds.

@@ -49,6 +49,12 @@ class BaseRichTextComponent(object):
# Whether the component requires the filesystem in some way that
# prevents it from being used by unauthorized users.
requires_fs = False
# Whether the component should be displayed as a block component
is_block = False
Copy link
Member

Choose a reason for hiding this comment

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

is_block_element is a better name, I think -- one says that a div is a "block element", not a "block".

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

@seanlip
Copy link
Member

seanlip commented Apr 3, 2016

I don't think scripts/run_presubmit_checks.sh should be changed. Can the changes be reverted?

Also, @AllanYangZhou, could you take a look at this PR too (especially with regards to user-facing functionality)? Thanks!

* upstream/develop:
  Add Deselect All option in categories and languages selector in search bar
@kahkhang
Copy link
Contributor Author

kahkhang commented Apr 3, 2016

I've reverted changes to scripts/run_presubmit_checks.sh. Thanks!

# URL template of the component, such that when interpolated with the
# customization arugment dictionary, points to an image which will be
# rendered in the RTE preview. explorationId may be used as well.
preview_url_template = ''
Copy link
Member

Choose a reason for hiding this comment

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

The way this is handled is still a bit convoluted, and it would be nicer to encapsulate all the "is there an image file? if so, do this, if not do that" stuff within here. So, how about making this a @property instead?

    @property
    def preview_url_template(self):
        return os.path.join(...)

Then, overwrite this for Image and Video. In addition, create preview pngs for Link and Math (that are exactly the same as the toolbar icons). I think that would be cleaner and would simplify the logic below, as well as in the frontend (there shouldn't need to be an else condition).

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

@AllanYangZhou
Copy link
Contributor

@seanlip Yup! I will not be able to take a good look until this weekend due to midterms again, is that fine?

@seanlip
Copy link
Member

seanlip commented Apr 4, 2016

Yep, this weekend is fine. Thanks @AllanYangZhou!

@seanlip
Copy link
Member

seanlip commented Apr 9, 2016

Hi @kahkhang, @AllanYangZhou -- just following up on this!

Also, @kahkhang, did you see my additional comments?

@kahkhang
Copy link
Contributor Author

Yep! Sorry for the late reply, I've been working on this on and off, but I've been stuck on creating an RTE component in say the admin page. I've tried adding the following snippet to the admin page.
<schema-based-editor schema="{type: 'html'}" local-value="test"> </schema-based-editor>

An RTE component is embedded in the admin page, but complex RTE components don't seem to appear in the toolbar. I've tried to trace the disabling mechanism to lines 906 to 914, and it seems to be the case that rteHelperService.getRichTextComponents() returns an empty array in the admin page, but loads all the rich text components in the exploration page as anticipated. Any help would be appreciated in enabling these complex RTE components from showing in the toolbar. Thanks!

@seanlip
Copy link
Member

seanlip commented Apr 10, 2016

Ah, so sorry -- I took a look, and it seems like the admin page is unusual in that it has no RTE components defined. (There's no GLOBALS.RTE_COMPONENT_SPECS, so that object ends up being {} and no components are added.)

However, I actually found the answer to my question in this line of code -- i.e., we do already disable images in the RTE based on context. So that's all good!


I also had one other thought: should we use the allOrNothing mode for the call to $interpolate, and then detect if no result comes out? It strikes me that we probably want to fail really noisily in a case like that, instead of having $interpolate just use empty strings silently...

@AllanYangZhou
Copy link
Contributor

@kahkhang @seanlip Just played around with the block previews, didn't see anything functioning incorrectly, and it looks good! Out of curiosity, are we planning to address the resize handlers on the image placeholders as part of this PR or separately?

@kahkhang
Copy link
Contributor Author

@seanlip I think its a good idea to prevent unexpected errors from arising due to erroneous interpolations. I'll add that in. Thanks!

@seanlip
Copy link
Member

seanlip commented Apr 11, 2016

Hi @AllanYangZhou, thanks for checking it out! I think the resize handlers will need be addressed separately (in a fix to #914). The issue only happens in FF, right?

Also, @kahkhang, is this ready for final review? (If so, could you please make sure you've replied to all the comments in this thread, too? Thanks!)

@kahkhang
Copy link
Contributor Author

Yep! Sorry it slipped my mind. Thanks!

if (componentDefn.previewUrlTemplate) {
var interpolatedUrl = $interpolate(
componentDefn.previewUrlTemplate, false, null, true)(
angular.extend(customizationArgsDict,
Copy link
Member

Choose a reason for hiding this comment

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

Can we only do the extending only if explorationContextService.getPageContext() is editor/learner? (Maybe the cleanest way to do that is to add a boolean isInExplorationContext() method to the explorationContextService.)

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

@seanlip
Copy link
Member

seanlip commented Apr 11, 2016

Thanks, @kahkhang! Just a few more comments/questions.

@@ -650,7 +672,7 @@ oppia.factory('rteHelperService', [
elt.find(
'img.oppia-noninteractive-' + componentDefn.name
).replaceWith(function() {
var jQueryElt = $('<' + this.className + '/>');
var jQueryElt = $('<' + this.className.split(' ')[0] + '/>');
Copy link
Member

Choose a reason for hiding this comment

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

What's happening here? It might merit a comment.

If you're looking for the class name starting with oppia-noninteractive-*, then taking the first one is error-prone -- you don't know what might happen in the future. Instead I would suggest actually looking for the class name starting with oppia-noninteractive-*, and erroring noisily if you don't find exactly one.

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.

@seanlip
Copy link
Member

seanlip commented Apr 11, 2016

Thanks, @kahkhang. One more comment, and it's good to go!

@AllanYangZhou
Copy link
Contributor

@seanlip Just checked: the resize issue happens in IE 11 too. I've noted this in the issue thread.

But yeah, I agree that should be separate.

@@ -672,7 +672,13 @@ oppia.factory('rteHelperService', [
elt.find(
'img.oppia-noninteractive-' + componentDefn.name
).replaceWith(function() {
var jQueryElt = $('<' + this.className.split(' ')[0] + '/>');
// Look for a class name starting with oppia-noninteractive-*.
var tagNameMatch = /(^|\s)(oppia-noninteractive-\w+)/.exec(
Copy link
Member

Choose a reason for hiding this comment

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

One gotcha here: I think \w is incorrect, and should be replaced with something that means "lowercase chars and hyphens" -- otherwise this may break in the future for RTE components with multi-word names, and it will take a while to debug. Would something like [a-z\-]+ work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops missed that out, thanks!. Hmm just wondering, is there a possibility that uppercase characters or digits might be used too?

Copy link
Member

Choose a reason for hiding this comment

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

Uppercase chars -- no, not in an html tag or class name, I think. Digits -- possible but unlikely; on balance, I think we might as well include them.

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

@seanlip
Copy link
Member

seanlip commented Apr 11, 2016

@kahkhang -- still one more comment (about your commit), sorry!

@seanlip
Copy link
Member

seanlip commented Apr 11, 2016

LGTM. Thanks @kahkhang!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants