Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Do not allow upload of invalid images to gallery
Browse files Browse the repository at this point in the history
no issue
- added `onUploadStart` action to `{{gh-uploader}}` that is triggered when individual files start uploading
  - will not be triggered for any files that fail client-side validation
- changed `{{koenig-card-gallery}}` to only add images to the local gallery display when the uploader starts an upload
  • Loading branch information
kevinansfield committed Aug 31, 2018
1 parent 7d80ac9 commit 4bbd5f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions app/components/gh-uploader.js
Expand Up @@ -70,6 +70,7 @@ export default Component.extend({
onComplete() {},
onFailed() {},
onStart() {},
onUploadStart() {},
onUploadFailure() {},
onUploadSuccess() {},

Expand Down Expand Up @@ -212,6 +213,8 @@ export default Component.extend({
let url = `${ghostPaths().apiRoot}${this.get('uploadUrl')}`;

try {
this.onUploadStart(file);

let response = yield ajax.post(url, {
data: formData,
processData: false,
Expand Down
21 changes: 9 additions & 12 deletions lib/koenig-editor/addon/components/koenig-card-gallery.js
Expand Up @@ -117,6 +117,15 @@ export default Component.extend({
},

actions: {
addImage(file) {
let count = this.images.length + 1;
let row = Math.ceil(count / MAX_PER_ROW) - 1;

let image = this._readDataFromImageFile(file);
image.row = row;
this.images.pushObject(image);
},

setImageSrc(uploadResult) {
let image = this.images.findBy('fileName', uploadResult.fileName);

Expand Down Expand Up @@ -212,18 +221,6 @@ export default Component.extend({
this.set('errorMessage', 'Galleries are limited to 9 images');
}
this.set('files', strippedFiles);

let count = this.images.length;
let row = Math.ceil(count / MAX_PER_ROW) - 1;

strippedFiles.forEach((file) => {
count = count + 1;
row = Math.ceil(count / MAX_PER_ROW) - 1;

let image = this._readDataFromImageFile(file);
image.row = row;
this.images.pushObject(image);
});
},

_readDataFromImageFile(file) {
Expand Down
Expand Up @@ -18,6 +18,7 @@
files=files
accept=imageMimeTypes
extensions=imageExtensions
onUploadStart=(action "addImage")
onUploadSuccess=(action "setImageSrc")
onUploadFailure=(action "uploadFailed")
as |uploader|
Expand Down

0 comments on commit 4bbd5f0

Please sign in to comment.