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

Widget upload feature for Easy Image #1483

Merged
merged 78 commits into from
Jan 29, 2018
Merged

Widget upload feature for Easy Image #1483

merged 78 commits into from
Jan 29, 2018

Conversation

mlewand
Copy link
Contributor

@mlewand mlewand commented Jan 22, 2018

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

This pull request adds a widget upload feature.

It can be hooked to any widget.

Allowed accepted file types can specified using supportedTypes property in widget definition (similarly as it is in uploadwidget).

Also allows for easy progress bar customization by progressReporterType property in widget definition.

It also fixes several other issues:

  • Misplaced progress bar (tp3350).
  • Misplaced balloon toolbar after initial image load.

I have targetted this PR into a upload widget feature branch, as it still needs undo integration before being merged into EI feature.

…e plugin.It's going to be extracted later. This type will be passed into Upload Widget Feature. The Idea is to have the ability to implement a different progress indicators for other widgets.
…ion of progress indicator with Easy Image itself.
…get upload feature.

Extracted custom progress indicators types and styles into a common files.
…g CIRCLE_THICKNESS const. Also removed stray CSS code.
There were also a couple minor code style corrections.
This is done as a temp workaround, as the objects that we're passing as definition to features, are copies of the original definition. In other words any modifications to definition done at runtime (by other features setUps or at a widget runtime) are not available in setUp function. Because of that definition.name was not available (because it's assigned by the widget system at a widget construction time).
@mlewand
Copy link
Contributor Author

mlewand commented Jan 25, 2018

Pushed a set of fixes that also brings:

  • Fixes requested in review summary/comments.
  • Support for pasting images from clipboard in IE11 tp#3390
  • Support for pasting a single image file in Firefox tp#3390
  • Support for converting any pasted base64 encoded image.
    • This also handles images pasted from Word.

This PR does not cover following cases:

  • No improved support for switching to source mode and back during upload, so that following is not yet satisfied:

    Switching to Source mode during upload also results in widget with not updated blob URL (previously it caused errors so it is an improvement).

  • No handing for cross editor copy and paste widget during upload to other editors (it will remain a blob reference).

These limitations will be addressed in future releases.

@mlewand mlewand requested a review from f1ames January 25, 2018 09:14
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Just few things to polish:

  1. Language files were not regenerated.

  2. As support for PFW was added, it would be nice to add some tests covering it (manual for sure, unit test maybe, WDYT?):

  • Support for converting any pasted base64 encoded image.
    • This also handles images pasted from Word.
  1. Small issue with circle progress reporter - as it creates some overlay over image during upload it is not possible to edit caption during upload.

  2. Direct image paste works funny on OS X, but I suppose it is an OS "feature":

jan-26-2018 11-58-12

@@ -4,3 +4,4 @@
altText = Label for button converting image to assign an alternative text.
fullImage = Label for button converting image to a full width.
sideImage = Label for button converting image to be a side image.
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be commands.altText, commands. fullImage , commands. sideImage?

Copy link
Contributor Author

@mlewand mlewand Jan 26, 2018

Choose a reason for hiding this comment

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

That's out of scope of this issue, but it is a good catch, please extract it.

@@ -8,5 +8,6 @@ CKEDITOR.plugins.setLang( 'easyimage', 'en', {
fullImage: 'Full Size Image',
sideImage: 'Side Image',
altText: 'Change image alternative text'
}
},
uploadFailed: 'Your image could not be downloaded due to network error.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Your image could not be downloaded due to network error

or rather

Your image could not be uploaded due to a network error

?

} );
}

function setImageWidth( widget, height ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It somehow a little less consistent, but from practical point of view makes much sense. Let's leave it as is 👍

* @param {String} blobUrl Blob URL of an image.
* @param {Boolean} [finalize=true] If `false` widget will not be automatically finalized (added to {@link CKEDITOR.plugins.widget.repository})
* but returned as a {@link CKEDITOR.dom.element} instance.
* @returns {CKEDITOR.plugins.widget/CKEDITOR.dom.element} The widget instance or {@link CKEDITOR.dom.element} of a widget wrapper if `finalize` was set to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

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

No docs for data param.

Copy link
Contributor

Choose a reason for hiding this comment

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

All other methods docs are public /**, only this one is private /*, is there any specific reason for this? (same for upload* events below)

/**
* Widget feature dedicated for handling seamless file uploads.
*
* This type serves solely as a mixing, and should be added using
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be

This type serves solely as a mixing, and should be...

?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think we should add @since tag here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for @since tag, I don't see much sense for that here as CKEDITOR.plugins.imagebase namespace is added in 4.9.0 so it seems natural to me that this info is not needed.

I'll report a feature request in Umberto to inherit/"cascade" since tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI: reported as cksource/umberto#466

*
* @private
* @param {CKEDITOR.editor} editor
* @param {Blob/String} fileOrData See {@link CKEDITOR.fileTools.fileLoader}.
Copy link
Contributor

Choose a reason for hiding this comment

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

The fileOrData docs param name doesn't match with the file param in the code.

updated: function() {},

/**
* To be called when the progress should be marked as complete.
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about making it more consistent (Method to be called versus To be called), but I think something like Marks the progress as complete. or Refreshes the progress. sounds better, WDYT?

Copy link
Contributor Author

@mlewand mlewand Jan 26, 2018

Choose a reason for hiding this comment

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

Great idea! It's simpler. The original text looks redundant compared to that.

* @param {CKEDITOR.editor} editor
* @param {Object} options
* @param {File[]} [options.files=[]] Files to be dropped.
* @param {Function} options.callback Function to be called after the paste event.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change order of options.files and options.callback so the required one is first.

* {@link CKEDITOR.plugins.imageBase.progressReporter}.
* @returns {Function}
*/
getProgressOverlapType: function( editor, ProgressReporter ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a mixed feelings about ProgressReporter instead of progressReporter, but I see what was the intention here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well we don't have an official and strict rule about this. My intention was to uppercase a local variable in case it stores a type. Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, it may be a good way to distinguish it 👍

/*
* Returns a type that implements a progress indicator that puts a
* circle-shaped progress bar.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing @param docs.

@mlewand
Copy link
Contributor Author

mlewand commented Jan 26, 2018

  1. Language files were not regenerated.

Good point, however our lang tool seems to be broken, as I'm adding easyimage plugin to list of plugins tracked by lang tools and it still doesn't work. I'll extract it to a separate ticket, especially that original entries need a fix too.

  1. As support for PFW was added, it would be nice to add some tests covering it (manual for sure, unit test maybe, WDYT?):
  • Support for converting any pasted base64 encoded image.
    • This also handles images pasted from Word.

As for manual test it's a good idea (added in 44e6f43).

As for unit test, TBH I don't find it necessary at this point. We have a good coverage with base64 encoded tests, and this is what our Paste form Word produces.

If we ever have some problem on integration between the two, we'll add a proper unit testing for integration.

  1. Small issue with circle progress reporter - as it creates some overlay over image during upload it is not possible to edit caption during upload.

This is used just for tests, it's purpose is just to visualize the flexibility of this feature. It looks good enough as it is.

We'd have to worry about that if it was our main progress reporter.

  1. Direct image paste works funny on OS X, but I suppose it is an OS "feature":

I don't have a Mac to check it at this point, but I suppose it transforms image into base64-encoded one, thus following feature apply:

Support for converting any pasted base64 encoded image.

Pushed fixes.

@f1ames f1ames self-requested a review January 26, 2018 16:15
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Looks good, nice work 👍


I don't have a Mac to check it at this point, but I suppose it transforms image into base64-encoded one, thus following feature apply:

Support for converting any pasted base64 encoded image.

Looks like works according to the feature. The image (I mean the icon) is properly uploaded to CS.

* {@link CKEDITOR.plugins.imageBase.progressReporter}.
* @returns {Function}
*/
getProgressOverlapType: function( editor, ProgressReporter ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, it may be a good way to distinguish it 👍

@f1ames f1ames merged commit d7d36f7 into t/932-3388 Jan 29, 2018
@f1ames f1ames deleted the t/932-3389 branch January 29, 2018 12:05
@mlewand mlewand mentioned this pull request Jan 29, 2018
2 tasks
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.

None yet

2 participants