From ba4470f1559ea4d1cfcd2ee4147c6a56d2ab9786 Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Thu, 22 Feb 2018 11:35:34 +0100 Subject: [PATCH] Closes #177: import document from EML file (UI done) --- README.md | 3 +- .../src/app/docs/controller/ModalImport.js | 53 +++++++++++++++++++ .../app/docs/controller/document/Document.js | 22 +++++++- .../docs/controller/document/DocumentEdit.js | 2 +- docs-web/src/main/webapp/src/index.html | 1 + docs-web/src/main/webapp/src/locale/en.json | 6 +++ docs-web/src/main/webapp/src/locale/fr.json | 6 +++ .../src/main/webapp/src/locale/zh_CN.json | 9 +++- .../src/main/webapp/src/locale/zh_TW.json | 9 +++- .../webapp/src/partial/docs/document.html | 16 ++++-- .../main/webapp/src/partial/docs/import.html | 10 ++++ 11 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 docs-web/src/main/webapp/src/app/docs/controller/ModalImport.js create mode 100644 docs-web/src/main/webapp/src/partial/docs/import.html diff --git a/README.md b/README.md index b4f574ab..bb1dbec1 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,15 @@ Features -------- - Responsive user interface -- Workflow system ![New!](https://www.sismics.com/public/img/new.png) - Optical character recognition - Support image, PDF, ODT and DOCX files - Flexible search engine - Full text search in all supported files - All [Dublin Core](http://dublincore.org/) metadata +- Workflow system ![New!](https://www.sismics.com/public/img/new.png) - 256-bit AES encryption of stored files - Tag system with nesting +- Import document from email (EML format) ![New!](https://www.sismics.com/public/img/new.png) - User/group permission system - 2-factor authentication - Hierarchical groups diff --git a/docs-web/src/main/webapp/src/app/docs/controller/ModalImport.js b/docs-web/src/main/webapp/src/app/docs/controller/ModalImport.js new file mode 100644 index 00000000..8e3c18ff --- /dev/null +++ b/docs-web/src/main/webapp/src/app/docs/controller/ModalImport.js @@ -0,0 +1,53 @@ +'use strict'; + +/** + * Modal import controller. + */ +angular.module('docs').controller('ModalImport', function ($scope, $uibModalInstance, file, $q, $timeout) { + // Payload + var formData = new FormData(); + formData.append('file', file, file.name); + + // Send the file + var deferred = $q.defer(); + var getProgressListener = function(deferred) { + return function(event) { + deferred.notify(event); + }; + }; + + $.ajax({ + type: 'PUT', + url: '../api/document/eml', + data: formData, + cache: false, + contentType: false, + processData: false, + success: function(response) { + deferred.resolve(response); + }, + error: function(jqXHR) { + deferred.reject(jqXHR); + }, + xhr: function() { + var myXhr = $.ajaxSettings.xhr(); + myXhr.upload.addEventListener( + 'progress', getProgressListener(deferred), false); + return myXhr; + } + }); + + deferred.promise.then(function(data) { + $uibModalInstance.close(data); + }, function(data) { + $scope.errorQuota = data.responseJSON && data.responseJSON.type === 'QuotaReached'; + if (!$scope.errorQuota) { + $scope.errorGeneral = true; + } + $timeout(function () { + $uibModalInstance.close(null); + }, 3000); + }, function(e) { + $scope.progress = e.loaded / e.total; + }); +}); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js b/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js index 0e8aa7e3..f63be117 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/document/Document.js @@ -3,7 +3,7 @@ /** * Document controller. */ -angular.module('docs').controller('Document', function ($scope, $rootScope, $timeout, $state, Restangular, $q, $filter) { +angular.module('docs').controller('Document', function ($scope, $rootScope, $timeout, $state, Restangular, $q, $filter, $uibModal) { /** * Scope variables. */ @@ -209,4 +209,24 @@ angular.module('docs').controller('Document', function ($scope, $rootScope, $tim $scope.search = ''; $scope.searchOpened = false; }; + + $scope.importEml = function (file) { + // Open the import modal + $uibModal.open({ + templateUrl: 'partial/docs/import.html', + controller: 'ModalImport', + resolve: { + file: function () { + return file; + } + } + }).result.then(function (data) { + if (data === null) { + return; + } + + $scope.viewDocument(data.id); + $scope.loadDocuments(); + }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js index de41440c..4789d4b3 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/document/DocumentEdit.js @@ -185,7 +185,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $ $scope.alerts.unshift({ type: 'danger', msg: $translate.instant('document.edit.document_' + ($scope.isEdit() ? 'edited' : 'added') + '_with_errors') - + (data.responseJSON.type === 'QuotaReached' ? (' - ' + $translate.instant('document.edit.quota_reached')) : '') + + (data.responseJSON && data.responseJSON.type === 'QuotaReached' ? (' - ' + $translate.instant('document.edit.quota_reached')) : '') }); // Reset view and title diff --git a/docs-web/src/main/webapp/src/index.html b/docs-web/src/main/webapp/src/index.html index 08f8b1b7..a8798e1d 100644 --- a/docs-web/src/main/webapp/src/index.html +++ b/docs-web/src/main/webapp/src/index.html @@ -50,6 +50,7 @@ + diff --git a/docs-web/src/main/webapp/src/locale/en.json b/docs-web/src/main/webapp/src/locale/en.json index 1d2e487b..92d7c81c 100644 --- a/docs-web/src/main/webapp/src/locale/en.json +++ b/docs-web/src/main/webapp/src/locale/en.json @@ -49,6 +49,7 @@ "search_clear": "Clear", "any_language": "Any language", "add_document": "Add a document", + "import_eml": "Import from an email (EML format)", "tags": "Tags", "no_tags": "No tags", "no_documents": "No document in the database", @@ -390,6 +391,11 @@ "sent_title": "Feedback sent", "sent_message": "Thank you for your feedback! It will help us make Sismics Docs even better." }, + "import": { + "title": "Importing", + "error_quota": "Quota limit reached, contact your administrator to increase your quota", + "error_general": "An error occurred while trying to import your file, please make sure it is a valid EML file" + }, "app_share": { "main": "Ask a shared document link to access it", "403": { diff --git a/docs-web/src/main/webapp/src/locale/fr.json b/docs-web/src/main/webapp/src/locale/fr.json index 91be90cb..b684e403 100644 --- a/docs-web/src/main/webapp/src/locale/fr.json +++ b/docs-web/src/main/webapp/src/locale/fr.json @@ -49,6 +49,7 @@ "search_clear": "Vider", "any_language": "Toutes les langues", "add_document": "Ajouter un document", + "import_eml": "Importer depuis un email (format EML)", "tags": "Tags", "no_tags": "Aucun tag", "no_documents": "Aucun document dans la base de données", @@ -390,6 +391,11 @@ "sent_title": "Avis envoyé", "sent_message": "Merci pour votre avis ! Cela nous aidera à améliorer Sismics Docs." }, + "import": { + "title": "Import en cours", + "error_quota": "Limite de quota atteinte, contactez votre administrateur pour augmenter votre quota", + "error_general": "Une erreur est survenue lors de la tentative d'importation de votre fichier, assurez-vous qu'il s'agit bien d'un fichier EML valide" + }, "app_share": { "main": "Demandez un lien de partage d'un document pour y accéder", "403": { diff --git a/docs-web/src/main/webapp/src/locale/zh_CN.json b/docs-web/src/main/webapp/src/locale/zh_CN.json index a4fbac57..d7d798ee 100644 --- a/docs-web/src/main/webapp/src/locale/zh_CN.json +++ b/docs-web/src/main/webapp/src/locale/zh_CN.json @@ -49,6 +49,7 @@ "search_clear": "清除", "any_language": "所有语言", "add_document": "添加一个文档", + "import_eml": "从电子邮件导入(EML格式)", "tags": "标签", "no_tags": "无标签", "no_documents": "数据库中无该文档", @@ -390,6 +391,11 @@ "sent_title": "反馈意见已发送", "sent_message": "非常感谢您的反馈意见!这将帮我们进一步改进Sismics Docs从而更好的为您提供服务。" }, + "import": { + "title": "输入", + "error_quota": "已达到配额限制,请联系您的管理员以增加配额", + "error_general": "尝试导入文件时发生错误,请确保它是有效的EML文件" + }, "app_share": { "main": "请求获取文档权限的链接", "403": { @@ -415,7 +421,8 @@ "Group": "组", "Tag": "标签", "User": "用户", - "RouteModel": "工作流程" + "RouteModel": "工作流程", + "Route": "工作流程" }, "selectrelation": { "typeahead": "请输入一个文档名称" diff --git a/docs-web/src/main/webapp/src/locale/zh_TW.json b/docs-web/src/main/webapp/src/locale/zh_TW.json index cfc9f4d7..acb07432 100644 --- a/docs-web/src/main/webapp/src/locale/zh_TW.json +++ b/docs-web/src/main/webapp/src/locale/zh_TW.json @@ -49,6 +49,7 @@ "search_clear": "清除", "any_language": "任何語言", "add_document": "添加一個文檔", + "import_eml": "從電子郵件導入(EML格式)", "tags": "標籤", "no_tags": "無標籤", "no_documents": "數據庫中無該文檔", @@ -390,6 +391,11 @@ "sent_title": "反饋已發送", "sent_message": "感謝您的反饋意見!這將幫助我們進一步優化Sismics Docs文檔管理系統以便更好的為您提供服務。" }, + "import": { + "title": "輸入", + "error_quota": "已達到配額限制,請聯繫您的管理員以增加配額", + "error_general": "嘗試導入文件時發生錯誤,請確保它是有效的EML文件" + }, "app_share": { "main": "請求一個共享的文檔鏈接來訪問該文檔", "403": { @@ -415,7 +421,8 @@ "Group": "組", "Tag": "標籤", "User": "用戶", - "RouteModel": "工作流程" + "RouteModel": "工作流程", + "Route": "工作流程" }, "selectrelation": { "typeahead": "請輸入文檔名稱" diff --git a/docs-web/src/main/webapp/src/partial/docs/document.html b/docs-web/src/main/webapp/src/partial/docs/document.html index e98d9bd8..53b51f58 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.html @@ -1,9 +1,19 @@
-

- {{ 'document.add_document' | translate }} -

+
diff --git a/docs-web/src/main/webapp/src/partial/docs/import.html b/docs-web/src/main/webapp/src/partial/docs/import.html new file mode 100644 index 00000000..dd215a81 --- /dev/null +++ b/docs-web/src/main/webapp/src/partial/docs/import.html @@ -0,0 +1,10 @@ +
+ + +
\ No newline at end of file