mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 15:13:21 +08:00
Merge pull request #5685 from G-Chubinidze/gc_SCI_8693
Parsing (import) protocols - Notifications update [SCI-8693]
This commit is contained in:
commit
940ca1f096
2 changed files with 45 additions and 15 deletions
|
@ -591,7 +591,7 @@ class ProtocolsController < ApplicationController
|
||||||
message_items: {
|
message_items: {
|
||||||
protocol: protocol.id
|
protocol: protocol.id
|
||||||
})
|
})
|
||||||
|
generate_import_protocol_notification(current_user, protocol)
|
||||||
format.json do
|
format.json do
|
||||||
render json: { status: :ok }, status: :ok
|
render json: { status: :ok }, status: :ok
|
||||||
end
|
end
|
||||||
|
@ -766,20 +766,7 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
z_output_stream.rewind
|
z_output_stream.rewind
|
||||||
|
|
||||||
protocol_name = get_protocol_name(@protocols[0])
|
file_name = export_protocol_file_name(@protocols)
|
||||||
|
|
||||||
# Now generate filename of the archive and send file to user
|
|
||||||
if @protocols.count == 1
|
|
||||||
# Try to construct an OS-safe file name
|
|
||||||
file_name = 'protocol.eln'
|
|
||||||
unless protocol_name.nil?
|
|
||||||
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
|
|
||||||
.downcase[0..Constants::NAME_MAX_LENGTH]
|
|
||||||
file_name = escaped_name + '.eln' unless escaped_name.blank?
|
|
||||||
end
|
|
||||||
elsif @protocols.length > 1
|
|
||||||
file_name = 'protocols.eln'
|
|
||||||
end
|
|
||||||
|
|
||||||
@protocols.each do |protocol|
|
@protocols.each do |protocol|
|
||||||
if params[:my_module_id]
|
if params[:my_module_id]
|
||||||
|
@ -942,6 +929,46 @@ class ProtocolsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_import_protocol_notification(user, protocol)
|
||||||
|
protocol_download_link = "<a data-id='#{protocol.id}' " \
|
||||||
|
"data-turbolinks='false' " \
|
||||||
|
"href='#{Rails.application
|
||||||
|
.routes
|
||||||
|
.url_helpers
|
||||||
|
.export_protocols_path(protocol_ids: [protocol.id])}'>" \
|
||||||
|
"#{export_protocol_file_name([protocol])}</a>"
|
||||||
|
|
||||||
|
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')} <a data-id='#{protocol.id}' " \
|
||||||
|
"data-turbolinks='false' " \
|
||||||
|
"href='#{Rails.application
|
||||||
|
.routes
|
||||||
|
.url_helpers
|
||||||
|
.protocol_path(protocol)}'>" \
|
||||||
|
"#{protocol.name}</a>"
|
||||||
|
)
|
||||||
|
|
||||||
|
UserNotification.create(notification: notification, user: user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def export_protocol_file_name(protocols)
|
||||||
|
protocol_name = get_protocol_name(protocols[0])
|
||||||
|
|
||||||
|
if protocols.count == 1
|
||||||
|
file_name = 'protocol.eln'
|
||||||
|
unless protocol_name.nil?
|
||||||
|
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
|
||||||
|
.downcase[0..Constants::NAME_MAX_LENGTH]
|
||||||
|
file_name = escaped_name + '.eln' unless escaped_name.blank?
|
||||||
|
end
|
||||||
|
elsif protocols.length > 1
|
||||||
|
file_name = 'protocols.eln'
|
||||||
|
end
|
||||||
|
file_name
|
||||||
|
end
|
||||||
|
|
||||||
def valid_protocol_json(json)
|
def valid_protocol_json(json)
|
||||||
JSON.parse(json)
|
JSON.parse(json)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -2775,6 +2775,9 @@ en:
|
||||||
import_to_team_protocols_label: "Import to Team Protocols"
|
import_to_team_protocols_label: "Import to Team Protocols"
|
||||||
import_to_private_protocols_label: "Import to My Protocols"
|
import_to_private_protocols_label: "Import to My Protocols"
|
||||||
import_protocols_label: "Import"
|
import_protocols_label: "Import"
|
||||||
|
import_protocol_notification:
|
||||||
|
title: "The import process has been successfully completed. You can download original file here: %{link}"
|
||||||
|
message: "Protocol template:"
|
||||||
export:
|
export:
|
||||||
export_results:
|
export_results:
|
||||||
title: "Export results"
|
title: "Export results"
|
||||||
|
|
Loading…
Reference in a new issue