-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Added block previews #1677
Conversation
dir_contents = self._listdir_omit_ignored(component_dir) | ||
self.assertLessEqual(len(dir_contents), 5) | ||
self.assertLessEqual(len(dir_contents), 6) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Current coverage is
|
@@ -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 |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I don't think 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
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 = '' |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@seanlip Yup! I will not be able to take a good look until this weekend due to midterms again, is that fine? |
Yep, this weekend is fine. Thanks @AllanYangZhou! |
Hi @kahkhang, @AllanYangZhou -- just following up on this! Also, @kahkhang, did you see my additional comments? |
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. 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 |
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... |
@seanlip I think its a good idea to prevent unexpected errors from arising due to erroneous interpolations. I'll add that in. Thanks! |
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!) |
Yep! Sorry it slipped my mind. Thanks! |
if (componentDefn.previewUrlTemplate) { | ||
var interpolatedUrl = $interpolate( | ||
componentDefn.previewUrlTemplate, false, null, true)( | ||
angular.extend(customizationArgsDict, |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks, @kahkhang! Just a few more comments/questions. |
…ertRtetoHtml and convertHtmlToRte
@@ -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] + '/>'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks, @kahkhang. One more comment, and it's good to go! |
@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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@kahkhang -- still one more comment (about your commit), sorry! |
LGTM. Thanks @kahkhang! |
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.