Browse Source

Merge branch 'master' into t/ckeditor5/456

Piotrek Koszuliński 8 năm trước cách đây
mục cha
commit
9d8a5b82b9

+ 2 - 1
packages/ckeditor5-upload/lang/contexts.json

@@ -1,3 +1,4 @@
 {
-	"Insert image": "Label for the insert image toolbar button."
+	"Insert image": "Label for the insert image toolbar button.",
+	"Upload failed": "Title of the notification displayed when upload fails."
 }

+ 5 - 5
packages/ckeditor5-upload/src/imageuploadcommand.js

@@ -10,7 +10,7 @@ import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 import ModelSelection from '@ckeditor/ckeditor5-engine/src/model/selection';
 import FileRepository from './filerepository';
 import { isImageType } from './utils';
-import Command from '@ckeditor/ckeditor5-core/src/command/command';
+import Command from '@ckeditor/ckeditor5-core/src/command';
 
 /**
  * @module upload/imageuploadcommand
@@ -19,19 +19,19 @@ import Command from '@ckeditor/ckeditor5-core/src/command/command';
 /**
  * Image upload command.
  *
- * @extends module:core/command/command~Command
+ * @extends module:core/command~Command
  */
 export default class ImageUploadCommand extends Command {
 	/**
-	 * Executes command.
+	 * Executes the command.
 	 *
-	 * @protected
+	 * @fires execute
 	 * @param {Object} options Options for executed command.
 	 * @param {File} options.file Image file to upload.
 	 * @param {module:engine/model/batch~Batch} [options.batch] Batch to collect all the change steps.
 	 * New batch will be created if this option is not set.
 	 */
-	_doExecute( options ) {
+	execute( options ) {
 		const editor = this.editor;
 		const doc = editor.document;
 		const batch = options.batch || doc.batch();

+ 6 - 2
packages/ckeditor5-upload/src/imageuploadengine.js

@@ -41,7 +41,7 @@ export default class ImageUploadEngine extends Plugin {
 		schema.requireAttributes( 'image', [ 'uploadId' ] );
 
 		// Register imageUpload command.
-		editor.commands.set( 'imageUpload', new ImageUploadCommand( editor ) );
+		editor.commands.add( 'imageUpload', new ImageUploadCommand( editor ) );
 
 		// Execute imageUpload command when image is dropped or pasted.
 		editor.editing.view.on( 'clipboardInput', ( evt, data ) => {
@@ -93,6 +93,7 @@ export default class ImageUploadEngine extends Plugin {
 	 */
 	load( loader, batch, imageElement ) {
 		const editor = this.editor;
+		const t = editor.locale.t;
 		const doc = editor.document;
 		const fileRepository = editor.plugins.get( FileRepository );
 		const notification = editor.plugins.get( Notification );
@@ -127,7 +128,10 @@ export default class ImageUploadEngine extends Plugin {
 			.catch( msg => {
 				// Might be 'aborted'.
 				if ( loader.status == 'error' ) {
-					notification.showWarning( msg, { namespace: 'upload' } );
+					notification.showWarning( msg, {
+						title: t( 'Upload failed' ),
+						namespace: 'upload'
+					} );
 				}
 
 				clean();

+ 8 - 8
packages/ckeditor5-upload/tests/imageuploadcommand.js

@@ -37,12 +37,12 @@ describe( 'ImageUploadCommand', () => {
 		} );
 	} );
 
-	describe( '_doExecute', () => {
+	describe( 'execute()', () => {
 		it( 'should insert image', () => {
 			const file = createNativeFileMock();
 			setModelData( document, '<paragraph>[]foo</paragraph>' );
 
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			const id = fileRepository.getLoader( file ).id;
 			expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );
@@ -52,7 +52,7 @@ describe( 'ImageUploadCommand', () => {
 			const file = createNativeFileMock();
 			setModelData( document, '<paragraph>foo[]</paragraph>' );
 
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			const id = fileRepository.getLoader( file ).id;
 			expect( getModelData( document ) ).to.equal( `<paragraph>foo</paragraph>[<image uploadId="${ id }"></image>]` );
@@ -62,7 +62,7 @@ describe( 'ImageUploadCommand', () => {
 			const file = createNativeFileMock();
 			setModelData( document, '<paragraph>f{}oo</paragraph>' );
 
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			const id = fileRepository.getLoader( file ).id;
 			expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );
@@ -72,7 +72,7 @@ describe( 'ImageUploadCommand', () => {
 			const file = createNativeFileMock();
 			setModelData( document, '[<image src="image.png"></image>]' );
 
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			const id = fileRepository.getLoader( file ).id;
 			expect( getModelData( document ) ).to.equal( `<image src="image.png"></image>[<image uploadId="${ id }"></image>]` );
@@ -88,7 +88,7 @@ describe( 'ImageUploadCommand', () => {
 
 			setModelData( document, '<other>[]</other>' );
 
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			expect( getModelData( document ) ).to.equal( '<other>[]</other>' );
 		} );
@@ -97,7 +97,7 @@ describe( 'ImageUploadCommand', () => {
 			const file = createNativeFileMock();
 			file.type = 'audio/mpeg3';
 			setModelData( document, '<paragraph>foo[]</paragraph>' );
-			command._doExecute( { file } );
+			command.execute( { file } );
 
 			expect( getModelData( document ) ).to.equal( '<paragraph>foo[]</paragraph>' );
 		} );
@@ -109,7 +109,7 @@ describe( 'ImageUploadCommand', () => {
 
 			setModelData( document, '<paragraph>[]foo</paragraph>' );
 
-			command._doExecute( { batch, file } );
+			command.execute( { batch, file } );
 			const id = fileRepository.getLoader( file ).id;
 
 			expect( getModelData( document ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );

+ 1 - 0
packages/ckeditor5-upload/tests/imageuploadengine.js

@@ -150,6 +150,7 @@ describe( 'ImageUploadEngine', () => {
 
 		notification.on( 'show:warning', ( evt, data ) => {
 			expect( data.message ).to.equal( 'Reading error.' );
+			expect( data.title ).to.equal( 'Upload failed' );
 			evt.stop();
 
 			done();