From 939466b9bb7e0b4f3fdb8bf094da9c0ac351fad5 Mon Sep 17 00:00:00 2001 From: dasari810 Date: Tue, 27 Oct 2020 12:48:08 +0530 Subject: [PATCH 1/5] allow only supported file formats --- .../components/ImageUploader/ImageUploader.spec.js | 6 ++++++ webapp/components/ImageUploader/ImageUploader.vue | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/webapp/components/ImageUploader/ImageUploader.spec.js b/webapp/components/ImageUploader/ImageUploader.spec.js index ed3ecb1f9..29d6d9468 100644 --- a/webapp/components/ImageUploader/ImageUploader.spec.js +++ b/webapp/components/ImageUploader/ImageUploader.spec.js @@ -27,11 +27,17 @@ describe('ImageUploader.vue', () => { beforeEach(() => jest.useFakeTimers()) const message = 'File upload failed' const fileError = { status: 'error' } + const unSupportedFileMessage = + 'Please upload an image of file format : jpg , jpeg , png or gif' it('shows an error toaster when verror is called', () => { wrapper.vm.onDropzoneError(fileError, message) expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message) }) + it('shows an error toaster when unSupported file is uploaded', () => { + wrapper.vm.onUnSupportedFormat(fileError.status, unSupportedFileMessage) + expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, unSupportedFileMessage) + }) }) }) }) diff --git a/webapp/components/ImageUploader/ImageUploader.vue b/webapp/components/ImageUploader/ImageUploader.vue index b3ea5aa49..37c0fcc18 100644 --- a/webapp/components/ImageUploader/ImageUploader.vue +++ b/webapp/components/ImageUploader/ImageUploader.vue @@ -62,6 +62,7 @@ export default { url: () => '', maxFilesize: 5.0, previewTemplate: '', + acceptedFiles: '.png,.jpg,.jpeg,.gif', }, cropper: null, file: null, @@ -73,7 +74,20 @@ export default { onDropzoneError(file, message) { this.$toast.error(file.status, message) }, + + onUnSupportedFormat(status, message) { + this.$toast.error(status, message) + }, initCropper(file) { + const supportedFormats = ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] + + if (supportedFormats.indexOf(file.type) < 0) { + this.onUnSupportedFormat( + 'error', + 'Please upload an image of file format : jpg , jpeg , png or gif', + ) + return + } this.showCropper = true this.file = file From 1a6a2bd8c81ce59aa154744d79933608645ef18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Mon, 2 Nov 2020 12:53:47 +0100 Subject: [PATCH 2/5] Inserted empty line for nicer formating --- webapp/components/ImageUploader/ImageUploader.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/components/ImageUploader/ImageUploader.spec.js b/webapp/components/ImageUploader/ImageUploader.spec.js index 29d6d9468..600e489e0 100644 --- a/webapp/components/ImageUploader/ImageUploader.spec.js +++ b/webapp/components/ImageUploader/ImageUploader.spec.js @@ -34,6 +34,7 @@ describe('ImageUploader.vue', () => { wrapper.vm.onDropzoneError(fileError, message) expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, message) }) + it('shows an error toaster when unSupported file is uploaded', () => { wrapper.vm.onUnSupportedFormat(fileError.status, unSupportedFileMessage) expect(mocks.$toast.error).toHaveBeenCalledWith(fileError.status, unSupportedFileMessage) From cd7e519d4bc3d59ad30c645d6597bccfa22c58ef Mon Sep 17 00:00:00 2001 From: dasari810 Date: Tue, 3 Nov 2020 01:04:28 +0530 Subject: [PATCH 3/5] implemented requested changes --- webapp/components/ImageUploader/ImageUploader.spec.js | 2 +- webapp/components/ImageUploader/ImageUploader.vue | 2 +- webapp/locales/en.json | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/components/ImageUploader/ImageUploader.spec.js b/webapp/components/ImageUploader/ImageUploader.spec.js index 600e489e0..537febac3 100644 --- a/webapp/components/ImageUploader/ImageUploader.spec.js +++ b/webapp/components/ImageUploader/ImageUploader.spec.js @@ -28,7 +28,7 @@ describe('ImageUploader.vue', () => { const message = 'File upload failed' const fileError = { status: 'error' } const unSupportedFileMessage = - 'Please upload an image of file format : jpg , jpeg , png or gif' + 'Please upload an image of file format : JPG , JPEG , PNG or GIF' it('shows an error toaster when verror is called', () => { wrapper.vm.onDropzoneError(fileError, message) diff --git a/webapp/components/ImageUploader/ImageUploader.vue b/webapp/components/ImageUploader/ImageUploader.vue index e1d85207a..d4f402e02 100644 --- a/webapp/components/ImageUploader/ImageUploader.vue +++ b/webapp/components/ImageUploader/ImageUploader.vue @@ -87,7 +87,7 @@ export default { if (supportedFormats.indexOf(file.type) < 0) { this.onUnSupportedFormat( 'error', - 'Please upload an image of file format : jpg , jpeg , png or gif', + this.$t('contribution.teaserImage.errors.unSupported-file-format'), ) return } diff --git a/webapp/locales/en.json b/webapp/locales/en.json index d25a41b40..a2d1e686c 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -259,7 +259,10 @@ "success": "Saved!", "teaserImage": { "cropperConfirm": "Confirm", - "supportedFormats": "Insert a picture of file format JPG , PNG or GIF" + "supportedFormats": "Insert a picture of file format JPG , PNG or GIF", + "errors" : { + "unSupported-file-format" : "Please upload an image of file format : JPG , JPEG , PNG or GIF" + } }, "title": "Title" }, From 66f1758c2de26f2f49f84b4699b8f43f326064b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 3 Nov 2020 15:10:20 +0100 Subject: [PATCH 4/5] Add German language - Correct some spacing and punctuation. --- webapp/locales/de.json | 5 ++++- webapp/locales/en.json | 4 ++-- webapp/locales/es.json | 2 +- webapp/locales/fr.json | 2 +- webapp/locales/it.json | 2 +- webapp/locales/nl.json | 2 +- webapp/locales/pl.json | 2 +- webapp/locales/pt.json | 2 +- webapp/locales/ru.json | 2 +- 9 files changed, 13 insertions(+), 10 deletions(-) diff --git a/webapp/locales/de.json b/webapp/locales/de.json index ac5320cfd..a28289f68 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -259,7 +259,10 @@ "success": "Gespeichert!", "teaserImage": { "cropperConfirm": "Bestätigen", - "supportedFormats": "Füge ein Bild im Dateiformat JPG, PNG oder GIF ein" + "supportedFormats": "Füge ein Bild im Dateiformat JPG, PNG oder GIF ein", + "errors" : { + "unSupported-file-format" : "Bitte lade ein Bild in den folgenden Formaten hoch: JPG, JPEG, PNG or GIF!" + } }, "title": "Titel" }, diff --git a/webapp/locales/en.json b/webapp/locales/en.json index a2d1e686c..f929a804b 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -259,9 +259,9 @@ "success": "Saved!", "teaserImage": { "cropperConfirm": "Confirm", - "supportedFormats": "Insert a picture of file format JPG , PNG or GIF", + "supportedFormats": "Insert a picture of file format JPG, PNG or GIF", "errors" : { - "unSupported-file-format" : "Please upload an image of file format : JPG , JPEG , PNG or GIF" + "unSupported-file-format" : "Please upload an image of file format: JPG, JPEG, PNG or GIF!" } }, "title": "Title" diff --git a/webapp/locales/es.json b/webapp/locales/es.json index 68c197ffe..6a510ae97 100644 --- a/webapp/locales/es.json +++ b/webapp/locales/es.json @@ -257,7 +257,7 @@ "success": "¡Guardado!", "teaserImage": { "cropperConfirm": "Confirmar", - "supportedFormats": "Insertar una imagen de formato de archivo JPG, PNG o GIF" + "supportedFormats": "Insertar una imagen de formato de archivo JPG, PNG o GIF!" }, "title": "Título" }, diff --git a/webapp/locales/fr.json b/webapp/locales/fr.json index 04f0a80c8..410e95f36 100644 --- a/webapp/locales/fr.json +++ b/webapp/locales/fr.json @@ -257,7 +257,7 @@ "success": "Enregistré!", "teaserImage": { "cropperConfirm": "Confirmer", - "supportedFormats": "Insérer une image au format de fichier JPG, PNG ou GIF" + "supportedFormats": "Insérer une image au format de fichier JPG, PNG ou GIF!" }, "title": "Titre" }, diff --git a/webapp/locales/it.json b/webapp/locales/it.json index 075bd89da..b18f1742a 100644 --- a/webapp/locales/it.json +++ b/webapp/locales/it.json @@ -262,7 +262,7 @@ "success": "", "teaserImage": { "cropperConfirm": "Confermare", - "supportedFormats": "Inserisci un'immagine in formato file JPG, PNG o GIF" + "supportedFormats": "Inserisci un'immagine in formato file JPG, PNG o GIF!" }, "title": "" }, diff --git a/webapp/locales/nl.json b/webapp/locales/nl.json index ef6bc9c8e..2d00a1561 100644 --- a/webapp/locales/nl.json +++ b/webapp/locales/nl.json @@ -69,7 +69,7 @@ "edit": "Bijdrage bewerken", "teaserImage": { "cropperConfirm": "Bevestigen", - "supportedFormats": "Voeg een afbeelding in met het bestandsformaat JPG, PNG of GIF" + "supportedFormats": "Voeg een afbeelding in met het bestandsformaat JPG, PNG of GIF!" } }, "disable": { diff --git a/webapp/locales/pl.json b/webapp/locales/pl.json index 578d64914..ae6b927e3 100644 --- a/webapp/locales/pl.json +++ b/webapp/locales/pl.json @@ -120,7 +120,7 @@ "success": "Zapisano!", "teaserImage": { "cropperConfirm": "Potwierdzać", - "supportedFormats": "Wstaw zdjęcie w formacie pliku JPG, PNG lub GIF" + "supportedFormats": "Wstaw zdjęcie w formacie pliku JPG, PNG lub GIF!" } }, "delete": { diff --git a/webapp/locales/pt.json b/webapp/locales/pt.json index cf0eaba2a..74f1365c6 100644 --- a/webapp/locales/pt.json +++ b/webapp/locales/pt.json @@ -253,7 +253,7 @@ "success": "Salvo!", "teaserImage": { "cropperConfirm": "Confirmar", - "supportedFormats": "Insira uma imagem do formato JPG, PNG ou GIF" + "supportedFormats": "Insira uma imagem do formato JPG, PNG ou GIF!" }, "title": "Título" }, diff --git a/webapp/locales/ru.json b/webapp/locales/ru.json index 0a1b21823..e57f4f125 100644 --- a/webapp/locales/ru.json +++ b/webapp/locales/ru.json @@ -257,7 +257,7 @@ "success": "Сохранено!", "teaserImage": { "cropperConfirm": "Подтвердить", - "supportedFormats": "Вставьте изображение файла формата JPG, PNG или GIF" + "supportedFormats": "Вставьте изображение файла формата JPG, PNG или GIF!" }, "title": "Заголовок" }, From 04a53f43b5af6032caca2f2768cb832a771b99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfgang=20Hu=C3=9F?= Date: Tue, 3 Nov 2020 15:36:50 +0100 Subject: [PATCH 5/5] Fix locales --- webapp/locales/de.json | 8 ++++---- webapp/locales/en.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/webapp/locales/de.json b/webapp/locales/de.json index a28289f68..44a819db0 100644 --- a/webapp/locales/de.json +++ b/webapp/locales/de.json @@ -259,10 +259,10 @@ "success": "Gespeichert!", "teaserImage": { "cropperConfirm": "Bestätigen", - "supportedFormats": "Füge ein Bild im Dateiformat JPG, PNG oder GIF ein", - "errors" : { - "unSupported-file-format" : "Bitte lade ein Bild in den folgenden Formaten hoch: JPG, JPEG, PNG or GIF!" - } + "errors": { + "unSupported-file-format": "Bitte lade ein Bild in den folgenden Formaten hoch: JPG, JPEG, PNG or GIF!" + }, + "supportedFormats": "Füge ein Bild im Dateiformat JPG, PNG oder GIF ein" }, "title": "Titel" }, diff --git a/webapp/locales/en.json b/webapp/locales/en.json index f929a804b..e9c4ecba6 100644 --- a/webapp/locales/en.json +++ b/webapp/locales/en.json @@ -259,10 +259,10 @@ "success": "Saved!", "teaserImage": { "cropperConfirm": "Confirm", - "supportedFormats": "Insert a picture of file format JPG, PNG or GIF", - "errors" : { - "unSupported-file-format" : "Please upload an image of file format: JPG, JPEG, PNG or GIF!" - } + "errors": { + "unSupported-file-format": "Please upload an image of file format: JPG, JPEG, PNG or GIF!" + }, + "supportedFormats": "Insert a picture of file format JPG, PNG or GIF" }, "title": "Title" },