Drag 'n Drop Inline Images Frontend
Review Request #6510 — Created Oct. 26, 2014 and discarded
Adding support for dragging and dropping images into the markdown editor. Instead of having upload their image first and then link to that image, users can simply drag-and-drop their image file into the markdown editor. This will upload the image to reviewboard and insert a link to that image in the editor.
These changes focus on the frontend work and include:
- Extending the DnDUploaderView to support multiple overlays on the page. Multiple DropTargets can be registered with the DnDOverlay instance.
- Extending the TextEditorView to support dragging and dropping images
- Adding a resource for UserFileAttachments
Tested in Chrome 38.0.2125.122, Firefox 32.0.2, Safari 8.0, Internet Explorer 11.0.9600
All existing unit tests pass.
- Added tests for the changes done to the TextEditorView (testing the appendText method and the Drag and Drop functionality).
- Added tests for serialization and parsing of the UserFileAttachment resource.
- Added tests for the DnDUploader functionality.
Description | From | Last Updated |
---|---|---|
It might be better to use the / / multi line comments here |
ML mloyzer | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Variable definitions should all be the first thing in the method. |
david | |
Can you leave this as-is? |
david | |
I'd suggest defining a $window as the first thing, and then using that for both. That way it doesn't have … |
david | |
Wrap to 80 column. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Wrap to 80 columns. |
david | |
Nit - let's put these in the same order as the function args. |
mike_conley | |
Might as well throw bmp, tiff and svg in there too. |
mike_conley | |
This can be: return imageExtensions.some(function(extension) { return file.name.match(new RegExp("\\." + extension + "$", "i")); }); That'll work in IE9 and … |
mike_conley | |
Nit "and" -> "an" |
mike_conley | |
Even though this is supposed to be a very cheap request, synchronous XHR is best to be avoided, since it … |
mike_conley | |
We probably need some error handling here in case things go wrong with the upload. |
mike_conley | |
Where are these magic 6's coming from? |
mike_conley | |
Ah - is there were the magic 6 comes from? Can we apply an attribute or class on the element … |
mike_conley | |
Might be good to get this stuff in CSS instead - perhaps a class for the window overlay. Or a … |
mike_conley | |
This seems like it wants to be a model but doesn't want to adhere to model conventions. Models work with … |
chipx86 | |
This doesn't buy us anything that new already gives us. It's actually nicer to pass in the arguments as a … |
chipx86 | |
Blank line between these. |
chipx86 | |
And here. |
chipx86 | |
Two blank lines. |
chipx86 | |
Blank line between these. |
chipx86 | |
Most of these can go inline below, saving some lines of code. |
chipx86 | |
This can break down the road if styles are changed. Instead, use outerWidth() and outerHeight(), which account for the border. |
chipx86 | |
This should be a single .css({ ... }) statement. |
chipx86 | |
The var should go at the top of the file. |
chipx86 | |
Same comments here as above. |
chipx86 | |
No blank line here. |
chipx86 | |
Two blank lines. |
chipx86 | |
Not every page will need this. Is it not sufficient to create an instance in ReviewRequestEditorView, or any other pages … |
chipx86 |
- Change Summary:
-
Adding group 'students' to reviewers
- Groups:
- Commit:
-
28140039d5a18152303a4f29aaef66f82ac01af6
- Diff:
-
Revision 2 (+299 -9)
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/models/userFileModel.js reviewboard/static/rb/js/resources/models/apiTokenModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/views/markdownEditorView.js Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/models/userFileModel.js reviewboard/static/rb/js/resources/models/apiTokenModel.js reviewboard/static/rb/js/views/commentDialogView.js reviewboard/static/rb/js/views/markdownEditorView.js
- Change Summary:
-
Working toward allowing a user to drag and drop onto multiple areas of the window.
- Diff:
-
Revision 3 (+338 -39)
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/models/userFileModel.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/pages/views/pageView.js reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/resources/models/apiTokenModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/models/userFileModel.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/pages/views/pageView.js reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/resources/models/apiTokenModel.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js
- Change Summary:
-
More work on the DnDUploader view. Added many tests and updated description and testing done.
- Summary:
-
[WIP] Drag 'n Drop Inline Images FrontendDrag 'n Drop Inline Images Frontend
- Description:
-
Adding support for dragging and dropping images into the markdown editor. Instead of having upload their image first and then link to that image, users can simply drag-and-drop their image file into the markdown editor. This will upload the image to reviewboard and insert a link to that image in the editor.
These changes focus on the frontend work and include:
~ - Extending the Markdown Editor View to support dragging and dropping images
~ ~ Still a work in progress.
~ - Extending the DnDUploaderView to support multiple overlays on the page. Multiple DropTargets can be registered with the DnDOverlay instance.
~ - Extending the TextEditorView to support dragging and dropping images
~ - Adding a resource for UserFileAttachments
- Testing Done:
-
~ WIP
~ Tested in Chrome 38.0.2125.122, Firefox 32.0.2, Safari 8.0
+ + All existing unit tests pass.
+ + - Added tests for the changes done to the TextEditorView (testing the appendText method and the Drag and Drop functionality).
+ - Added tests for serialization and parsing of the UserFileAttachment resource.
+ - Added tests for the DnDUploader functionality.
- Diff:
-
Revision 4 (+567 -37)
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
- Change Summary:
-
Review request changes. Mostly line wrapping and also making sure the jquery selector is not run an unnecessary amount of times in dndUploaderView.js
- Diff:
-
Revision 5 (+590 -36)
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
- Change Summary:
-
Tested in Internet Explorer
- Testing Done:
-
~ Tested in Chrome 38.0.2125.122, Firefox 32.0.2, Safari 8.0
~ Tested in Chrome 38.0.2125.122, Firefox 32.0.2, Safari 8.0, Internet Explorer 11.0.9600
All existing unit tests pass.
- Added tests for the changes done to the TextEditorView (testing the appendText method and the Drag and Drop functionality).
- Added tests for serialization and parsing of the UserFileAttachment resource.
- Added tests for the DnDUploader functionality.
-
-
-
-
This can be:
return imageExtensions.some(function(extension) { return file.name.match(new RegExp("\\." + extension + "$", "i")); });
That'll work in IE9 and up.
-
-
Even though this is supposed to be a very cheap request, synchronous XHR is best to be avoided, since it 100% blocks JS execution. If there are network problems (say, our DNS server is flaking out on us), this can absolutely lock up everything in the user's tab (or their entire browser).
Is there a way of doing this asynchronously, and passing in a callback to do the upload of the whole file? Also, what happens if that first save fails?
-
-
-
Ah - is there were the magic 6 comes from?
Can we apply an attribute or class on the element instead, and have a selector to apply the border? Putting non-positional styling in JS should be avoided if possible.
-
Might be good to get this stuff in CSS instead - perhaps a class for the window overlay. Or a separate class for the text input overlays.
- Change Summary:
-
Moving the dnd-overlay styling into less file. Making the initial save for userFileAttachment run async. + Misc changes from code review.
- Diff:
-
Revision 6 (+578 -37)
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
- Change Summary:
-
Showing an alert() when the file attachment upload fails.
- Diff:
-
Revision 7 (+585 -37)
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
-
Looking good. Got some things to fix up that are largely stylistic or JavaScript/jQuery/Backbone-isms that will help reduce code and logic.
-
This seems like it wants to be a model but doesn't want to adhere to model conventions.
Models work with attributes instead of direct properties (like
target
). It also usesdefaults
for any default options.You probably want to fill
defaults
with default values fortarget
,dropAction
,context
, andactive
. You can then remove theinitialize
call.Consumers will then need to access this data using
get()
.This is also missing documentation.
-
This doesn't buy us anything that
new
already gives us. It's actually nicer to pass in the arguments as a dictionary instead of positional, since it's more self-documenting. -
-
-
-
-
-
This can break down the road if styles are changed. Instead, use
outerWidth()
andouterHeight()
, which account for the border. -
-
-
-
-
-
Not every page will need this. Is it not sufficient to create an instance in
ReviewRequestEditorView
, or any other pages that need this?
- Change Summary:
-
Updating DnDDropTarget model to follow Backbonejs model conventions. Some formatting changes.
- Diff:
-
Revision 8 (+618 -38)
-
Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/pages/views/tests/reviewablePageViewTests.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/pages/views/tests/reviewablePageViewTests.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js
- Change Summary:
-
Disable the drag 'n drop overlay when the comment dialog has been closed.
- Diff:
-
Revision 9 (+629 -39)
-
Tool: Pyflakes Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/pages/views/tests/reviewablePageViewTests.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js Tool: PEP8 Style Checker Processed Files: reviewboard/staticbundles.py Ignored Files: reviewboard/static/rb/js/models/dndDropTarget.js reviewboard/static/rb/css/ui/dnd-uploader.less reviewboard/static/rb/js/views/tests/dndUploaderViewTests.js reviewboard/static/rb/js/resources/models/userFileAttachmentModel.js reviewboard/static/rb/js/views/dndUploaderView.js reviewboard/static/rb/js/pages/views/tests/reviewablePageViewTests.js reviewboard/static/rb/js/resources/models/tests/userFileAttachmentModelTests.js reviewboard/static/rb/js/ui/views/tests/textEditorViewTests.js reviewboard/static/rb/css/common.less reviewboard/static/rb/js/ui/views/textEditorView.js reviewboard/static/rb/js/views/reviewRequestEditorView.js reviewboard/static/rb/js/pages/views/reviewablePageView.js