From 4a8582ebc8bee1bc7fe224d1ed653312edf880b7 Mon Sep 17 00:00:00 2001
From: artoscinote <85488244+artoscinote@users.noreply.github.com>
Date: Tue, 11 Jul 2023 09:27:15 +0200
Subject: [PATCH] Initial implementation of protocol processing modal
[SCI-8661] (#5683)
* Initial implementation of protocol processing modal [SCI-8661]
* Prepare placeholder jobs and integrate notifications [SCI-8661]
---
app/assets/javascripts/protocols/index.js | 45 ++++----
app/controllers/protocols_controller.rb | 30 +----
.../packs/vue/protocol_file_import_modal.js | 18 +++
.../vue/protocol_import/file_import_modal.vue | 105 ++++++++++++++++++
app/jobs/protocols/docx_import_job.rb | 9 ++
.../protocol_importers/docx_service.rb | 43 +++++++
app/views/protocols/index.html.erb | 5 +
.../protocols/index/_general_toolbar.html.erb | 2 +-
config/locales/en.yml | 18 ++-
config/routes.rb | 1 +
config/webpack/webpack.config.js | 3 +-
11 files changed, 231 insertions(+), 48 deletions(-)
create mode 100644 app/javascript/packs/vue/protocol_file_import_modal.js
create mode 100644 app/javascript/vue/protocol_import/file_import_modal.vue
create mode 100644 app/jobs/protocols/docx_import_job.rb
create mode 100644 app/services/protocol_importers/docx_service.rb
diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js
index 444148cf8..2d6bf7cfd 100644
--- a/app/assets/javascripts/protocols/index.js
+++ b/app/assets/javascripts/protocols/index.js
@@ -667,28 +667,33 @@ var ProtocolsIndex = (function() {
var importUrl = fileInput.attr('data-import-url');
var teamId = fileInput.attr('data-team-id');
var type = fileInput.attr('data-type');
- importProtocolFromFile(
- ev.target.files[0],
- importUrl,
- { team_id: teamId, type: type },
- false,
- function(datas) {
- var nrSuccessful = 0;
- _.each(datas, function(data) {
- if (data.status === 'ok') {
- nrSuccessful += 1;
- }
- });
- animateSpinner(null, false);
- if (nrSuccessful) {
- HelperModule.flashAlertMsg(I18n.t('protocols.index.import_results.message_ok_html', { count: nrSuccessful }), 'success');
- reloadTable();
- } else {
- HelperModule.flashAlertMsg(I18n.t('protocols.index.import_results.message_failed'), 'danger');
+ if(ev.target.files[0].name.split('.').pop() === 'eln') {
+ importProtocolFromFile(
+ ev.target.files[0],
+ importUrl,
+ { team_id: teamId, type: type },
+ false,
+ function(datas) {
+ var nrSuccessful = 0;
+ _.each(datas, function(data) {
+ if (data.status === 'ok') {
+ nrSuccessful += 1;
+ }
+ });
+ animateSpinner(null, false);
+
+ if (nrSuccessful) {
+ HelperModule.flashAlertMsg(I18n.t('protocols.index.import_results.message_ok_html', { count: nrSuccessful }), 'success');
+ reloadTable();
+ } else {
+ HelperModule.flashAlertMsg(I18n.t('protocols.index.import_results.message_failed'), 'danger');
+ }
}
- }
- );
+ );
+ } else {
+ protocolFileImportModal.init(ev.target.files, reloadTable);
+ }
$(this).val('');
});
}
diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb
index 7cab925e7..3dbdc0c09 100644
--- a/app/controllers/protocols_controller.rb
+++ b/app/controllers/protocols_controller.rb
@@ -591,7 +591,6 @@ class ProtocolsController < ApplicationController
message_items: {
protocol: protocol.id
})
- generate_import_protocol_notification(current_user, protocol)
format.json do
render json: { status: :ok }, status: :ok
end
@@ -918,6 +917,11 @@ class ProtocolsController < ApplicationController
}
end
+ def import_docx
+ @job = Protocols::DocxImportJob.perform_later(params[:files], current_user)
+ render json: { job_id: @job.job_id }
+ end
+
private
def set_importer
@@ -929,30 +933,6 @@ class ProtocolsController < ApplicationController
end
end
- def generate_import_protocol_notification(user, protocol)
- protocol_download_link = "" \
- "#{export_protocol_file_name([protocol])}"
-
- notification = Notification.create(
- type_of: :deliver,
- title: I18n.t('protocols.import_export.import_protocol_notification.title', link: protocol_download_link),
- message: "#{I18n.t('protocols.import_export.import_protocol_notification.message')} " \
- "#{protocol.name}"
- )
-
- UserNotification.create(notification: notification, user: user)
- end
-
def export_protocol_file_name(protocols)
protocol_name = get_protocol_name(protocols[0])
diff --git a/app/javascript/packs/vue/protocol_file_import_modal.js b/app/javascript/packs/vue/protocol_file_import_modal.js
new file mode 100644
index 000000000..8e7acc245
--- /dev/null
+++ b/app/javascript/packs/vue/protocol_file_import_modal.js
@@ -0,0 +1,18 @@
+import TurbolinksAdapter from 'vue-turbolinks';
+import Vue from 'vue/dist/vue.esm';
+import ProtocolFileImportModal from '../../vue/protocol_import/file_import_modal.vue';
+
+
+Vue.use(TurbolinksAdapter);
+Vue.prototype.i18n = window.I18n;
+
+window.initProtocolFileImportModalComponent = () => {
+ new Vue({
+ el: '#protocolFileImportModal',
+ components: {
+ 'protocol-file-import-modal': ProtocolFileImportModal
+ }
+ });
+};
+
+initProtocolFileImportModalComponent();
diff --git a/app/javascript/vue/protocol_import/file_import_modal.vue b/app/javascript/vue/protocol_import/file_import_modal.vue
new file mode 100644
index 000000000..28f3f8324
--- /dev/null
+++ b/app/javascript/vue/protocol_import/file_import_modal.vue
@@ -0,0 +1,105 @@
+
+