From c462869cc16044fd87880ee38fbb084acb5201bb Mon Sep 17 00:00:00 2001
From: Tamara Steinwender <tamara.steinwender@tugraz.at>
Date: Tue, 20 Jul 2021 11:01:41 +0200
Subject: [PATCH] Add a notification to file-handling if a file extension isn't
 supported

---
 packages/file-handling/src/file-source.js           | 11 +++++++++--
 packages/file-handling/src/i18n/de/translation.json |  4 +++-
 packages/file-handling/src/i18n/en/translation.json |  4 +++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index dbac845f..f9ee42a3 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -3,7 +3,7 @@ import {css, html} from 'lit-element';
 import {ScopedElementsMixin} from '@open-wc/scoped-elements';
 import * as commonUtils from "@dbp-toolkit/common/utils";
 import {Icon, MiniSpinner} from '@dbp-toolkit/common';
-import {send as notify} from '@dbp-toolkit/common/notification';
+import {send} from "@dbp-toolkit/common/notification";
 import * as commonStyles from '@dbp-toolkit/common/styles';
 import {NextcloudFilePicker} from "./nextcloud-file-picker";
 import {classMap} from 'lit-html/directives/class-map.js';
@@ -262,6 +262,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
     }
 
     checkFileType(file) {
+        const i18n = this._i18n;
         // check if file is allowed
         const [fileMainType, fileSubType] = file.type.split('/');
         const mimeTypes = this.allowedMimeTypes.split(',');
@@ -274,6 +275,12 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
 
         if (deny) {
             console.log(`mime type ${file.type} of file '${file.name}' is not compatible with ${this.allowedMimeTypes}`);
+            send({
+                "summary": i18n.t('file-source.mime-type-title'),
+                "body": i18n.t('file-source.mime-type-body'),
+                "type": "danger",
+                "timeout": 5,
+            });
             return false;
         }
         return true;
@@ -335,7 +342,7 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
             const i18n = this._i18n;
             console.error('ZIP file does not contain any files of ' + this.allowedMimeTypes);
             //throw new Error('ZIP file does not contain any files of ' + this.allowedMimeTypes);
-            notify({
+            send({
                 "summary": i18n.t('file-source.no-usable-files-in-zip'),
                 "body": i18n.t('file-source.no-usable-files-hint') + this.allowedMimeTypes,
                 "type": 'danger',
diff --git a/packages/file-handling/src/i18n/de/translation.json b/packages/file-handling/src/i18n/de/translation.json
index 62374158..90c6a65b 100644
--- a/packages/file-handling/src/i18n/de/translation.json
+++ b/packages/file-handling/src/i18n/de/translation.json
@@ -17,7 +17,9 @@
     "nav-local": "Lokaler Computer",
     "no-usable-files-in-zip": "ZIP Datei enthält keine verwendbaren Dateien",
     "no-usable-files-hint": "Laden Sie eine ZIP Datei mit Dateien von folgendem Typ hoch: ",
-    "clipboard": "Zwischenablage"
+    "clipboard": "Zwischenablage",
+    "mime-type-title": "Nicht unterstützes Dateiformat",
+    "mime-type-body": "Das Dateiformat wird von dieser Applikation nicht unterstützt."
   },
   "file-sink": {
     "local-intro": "{{count}} Datei herunterladen",
diff --git a/packages/file-handling/src/i18n/en/translation.json b/packages/file-handling/src/i18n/en/translation.json
index f3f1bb29..129e6cf5 100644
--- a/packages/file-handling/src/i18n/en/translation.json
+++ b/packages/file-handling/src/i18n/en/translation.json
@@ -21,7 +21,9 @@
     "clipboard-body": "Here you can choose from the previously temporarily cached files.",
     "clipboard-select-btn": "Select",
     "clipboard-no-files": "There are currently no files in the clipboard.",
-    "clipboard": "Clipboard"
+    "clipboard": "Clipboard",
+    "mime-type-title": "Unsupported file format",
+    "mime-type-body": "The file format is not supported by this application."
   },
   "file-sink": {
     "local-intro": "Download {{count}} file",
-- 
GitLab