2016-07-21 19:11:15 +08:00
|
|
|
class ProtocolsController < ApplicationController
|
|
|
|
include RenamingUtil
|
2019-05-09 15:40:40 +08:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ApplicationHelper
|
2017-01-04 22:04:12 +08:00
|
|
|
include InputSanitizeHelper
|
2017-11-17 03:03:44 +08:00
|
|
|
include ProtocolsIoHelper
|
2018-08-28 20:48:23 +08:00
|
|
|
include TeamsHelper
|
2019-06-04 20:40:21 +08:00
|
|
|
include CommentHelper
|
2022-06-10 16:18:55 +08:00
|
|
|
include ProtocolsExporterV2
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2017-09-26 19:17:00 +08:00
|
|
|
before_action :check_create_permissions, only: %i(
|
|
|
|
create
|
|
|
|
)
|
|
|
|
before_action :check_clone_permissions, only: [:clone]
|
|
|
|
before_action :check_view_permissions, only: %i(
|
2022-05-27 18:49:10 +08:00
|
|
|
show
|
2023-01-20 21:29:25 +08:00
|
|
|
versions_modal
|
2017-09-26 19:17:00 +08:00
|
|
|
protocol_status_bar
|
|
|
|
linked_children
|
|
|
|
linked_children_datatable
|
2022-12-06 22:54:50 +08:00
|
|
|
permissions
|
2017-09-26 19:17:00 +08:00
|
|
|
)
|
2022-12-19 20:18:24 +08:00
|
|
|
before_action :switch_team_with_param, only: %i(index protocolsio_index)
|
2017-09-26 19:17:00 +08:00
|
|
|
before_action :check_view_all_permissions, only: %i(
|
|
|
|
index
|
2022-12-19 20:18:24 +08:00
|
|
|
protocolsio_index
|
2017-09-26 19:17:00 +08:00
|
|
|
datatable
|
|
|
|
)
|
2018-02-02 01:41:28 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(
|
2017-09-26 19:17:00 +08:00
|
|
|
update_keywords
|
2019-04-24 19:34:56 +08:00
|
|
|
update_description
|
2023-01-26 19:39:11 +08:00
|
|
|
update_version_comment
|
2019-11-12 18:26:18 +08:00
|
|
|
update_name
|
|
|
|
update_authors
|
2017-09-26 19:17:00 +08:00
|
|
|
unlink
|
|
|
|
unlink_modal
|
2023-04-25 22:00:20 +08:00
|
|
|
delete_steps
|
|
|
|
)
|
|
|
|
|
|
|
|
before_action :check_manage_with_read_protocol_permissions, only: %i(
|
2017-09-26 19:17:00 +08:00
|
|
|
revert
|
|
|
|
revert_modal
|
2018-02-02 01:41:28 +08:00
|
|
|
update_from_parent
|
|
|
|
update_from_parent_modal
|
2017-09-26 19:17:00 +08:00
|
|
|
)
|
2018-02-19 21:47:36 +08:00
|
|
|
before_action :check_restore_all_in_repository_permissions, only: :restore
|
2023-02-17 01:03:11 +08:00
|
|
|
before_action :check_archive_all_in_repository_permissions, only: :archive
|
2017-09-26 19:17:00 +08:00
|
|
|
before_action :check_load_from_repository_views_permissions, only: %i(
|
|
|
|
load_from_repository_modal
|
|
|
|
load_from_repository_datatable
|
|
|
|
)
|
2016-07-21 19:11:15 +08:00
|
|
|
before_action :check_load_from_repository_permissions, only: [
|
|
|
|
:load_from_repository
|
|
|
|
]
|
|
|
|
before_action :check_load_from_file_permissions, only: [
|
|
|
|
:load_from_file
|
|
|
|
]
|
2017-09-26 19:17:00 +08:00
|
|
|
before_action :check_copy_to_repository_permissions, only: %i(
|
|
|
|
copy_to_repository
|
|
|
|
)
|
2023-02-13 16:50:39 +08:00
|
|
|
|
2023-04-11 18:50:14 +08:00
|
|
|
before_action :check_publish_permission, only: %i(publish version_comment update_version_comment)
|
2018-03-19 23:10:28 +08:00
|
|
|
before_action :check_import_permissions, only: :import
|
|
|
|
before_action :check_export_permissions, only: :export
|
2023-02-22 21:59:48 +08:00
|
|
|
before_action :check_delete_draft_permissions, only: :destroy_draft
|
|
|
|
before_action :check_save_as_draft_permissions, only: :save_as_draft
|
2018-03-19 23:10:28 +08:00
|
|
|
|
2018-03-26 19:07:00 +08:00
|
|
|
before_action :check_protocolsio_import_permissions,
|
|
|
|
only: %i(protocolsio_import_create protocolsio_import_save)
|
2017-09-26 19:17:00 +08:00
|
|
|
|
2022-06-10 16:18:55 +08:00
|
|
|
before_action :set_importer, only: %i(load_from_file import)
|
2023-01-05 18:42:59 +08:00
|
|
|
before_action :set_inline_name_editing, only: :show
|
2023-04-19 16:53:39 +08:00
|
|
|
before_action :set_breadcrumbs_items, only: %i(index show)
|
2023-01-05 18:42:59 +08:00
|
|
|
|
2022-07-26 19:52:40 +08:00
|
|
|
layout 'fluid'
|
|
|
|
|
2017-09-26 19:17:00 +08:00
|
|
|
def index; end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
|
|
def datatable
|
|
|
|
respond_to do |format|
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: ::ProtocolsDatatable.new(
|
|
|
|
view_context,
|
2017-01-24 23:57:14 +08:00
|
|
|
@current_team,
|
2016-07-21 19:11:15 +08:00
|
|
|
@type,
|
|
|
|
current_user
|
|
|
|
)
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-20 21:29:25 +08:00
|
|
|
def versions_modal
|
2023-03-02 23:10:28 +08:00
|
|
|
return render_403 unless @protocol.in_repository_published_original? || @protocol.initial_draft?
|
2023-01-20 21:29:25 +08:00
|
|
|
|
2023-03-01 22:04:53 +08:00
|
|
|
@published_versions = @protocol.published_versions_with_original.order(version_number: :desc)
|
2023-01-20 21:29:25 +08:00
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string(partial: 'protocols/index/protocol_versions_modal')
|
2023-01-20 21:29:25 +08:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-12-01 18:16:45 +08:00
|
|
|
def print
|
|
|
|
@protocol = Protocol.find(params[:id])
|
|
|
|
render_403 && return unless @protocol.my_module.blank? || can_read_protocol_in_module?(@protocol)
|
2023-05-03 17:16:59 +08:00
|
|
|
|
2021-12-01 23:23:46 +08:00
|
|
|
render layout: 'protocols/print'
|
2021-12-01 18:16:45 +08:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def linked_children
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: {
|
|
|
|
title: I18n.t('protocols.index.linked_children.title',
|
|
|
|
protocol: escape_input(@protocol.name)),
|
|
|
|
html: render_to_string(partial: 'protocols/index/linked_children_modal_body',
|
|
|
|
locals: { protocol: @protocol })
|
|
|
|
}
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def linked_children_datatable
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: ::ProtocolLinkedChildrenDatatable.new(
|
|
|
|
view_context,
|
|
|
|
@protocol,
|
|
|
|
current_user,
|
|
|
|
self
|
|
|
|
)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def publish
|
2023-02-21 22:25:01 +08:00
|
|
|
Protocol.transaction do
|
|
|
|
@protocol.update!(
|
|
|
|
published_by: current_user,
|
|
|
|
published_on: DateTime.now,
|
|
|
|
version_comment: params[:version_comment] || @protocol.version_comment,
|
|
|
|
protocol_type: (@protocol.parent_id.nil? ? :in_repository_published_original : :in_repository_published_version)
|
|
|
|
)
|
|
|
|
log_activity(:protocol_template_published,
|
|
|
|
nil,
|
|
|
|
protocol: @protocol.id,
|
|
|
|
version_number: @protocol.version_number)
|
2023-03-02 23:10:28 +08:00
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
2023-04-13 21:34:36 +08:00
|
|
|
flash[:error] = @protocol.errors&.map(&:message)&.join(',')
|
2023-03-03 22:33:08 +08:00
|
|
|
Rails.logger.error e.message
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
rescue StandardError => e
|
|
|
|
flash[:error] = I18n.t('errors.general')
|
2023-03-02 23:10:28 +08:00
|
|
|
Rails.logger.error e.message
|
2023-02-21 22:25:01 +08:00
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
|
2023-02-13 16:50:39 +08:00
|
|
|
if params[:view] == 'show'
|
|
|
|
redirect_to protocol_path(@protocol)
|
|
|
|
else
|
|
|
|
redirect_to protocols_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_draft
|
2023-02-21 22:25:01 +08:00
|
|
|
Protocol.transaction do
|
|
|
|
parent = @protocol.parent
|
|
|
|
@protocol.destroy!
|
|
|
|
@protocol = parent
|
|
|
|
log_activity(:protocol_template_draft_deleted,
|
|
|
|
nil,
|
|
|
|
protocol: @protocol.id)
|
2023-05-03 17:16:59 +08:00
|
|
|
|
|
|
|
flash[:success] = I18n.t('protocols.delete_draft_modal.success')
|
2023-02-24 23:17:36 +08:00
|
|
|
redirect_to protocols_path
|
|
|
|
rescue ActiveRecord::RecordNotDestroyed => e
|
|
|
|
Rails.logger.error e.message
|
2023-03-03 22:33:08 +08:00
|
|
|
render json: { message: e.message }, status: :unprocessable_entity
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
rescue StandardError => e
|
|
|
|
render json: { message: I18n.t('errors.general') }, status: :unprocessable_entity
|
|
|
|
Rails.logger.error e.message
|
2023-02-24 23:17:36 +08:00
|
|
|
raise ActiveRecord::Rollback
|
2023-02-21 22:25:01 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def archive
|
2023-03-23 22:32:22 +08:00
|
|
|
move_protocols('archive')
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def restore
|
2023-03-23 22:32:22 +08:00
|
|
|
move_protocols('restore')
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2018-08-28 20:48:23 +08:00
|
|
|
def edit
|
2022-12-01 21:55:23 +08:00
|
|
|
render :show
|
2018-08-28 20:48:23 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2022-05-27 18:49:10 +08:00
|
|
|
def show
|
2023-06-21 20:13:20 +08:00
|
|
|
render json: @protocol, serializer: ProtocolSerializer, user: current_user
|
2022-05-27 18:49:10 +08:00
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def update_keywords
|
|
|
|
respond_to do |format|
|
2023-03-01 22:19:34 +08:00
|
|
|
if @protocol.update_keywords(params[:keywords], current_user)
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2019-03-29 22:09:20 +08:00
|
|
|
log_activity(:edit_keywords_in_protocol_repository, nil, protocol: @protocol.id)
|
2022-06-06 19:56:22 +08:00
|
|
|
render json: @protocol, serializer: ProtocolSerializer, user: current_user
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2023-03-03 22:33:08 +08:00
|
|
|
format.json { render json: I18n.t('errors.general'), status: :unprocessable_entity }
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-12 18:26:18 +08:00
|
|
|
def update_authors
|
2023-03-01 22:19:34 +08:00
|
|
|
if @protocol.update(authors: params.require(:protocol)[:authors], last_modified_by: current_user)
|
2019-11-13 20:57:04 +08:00
|
|
|
log_activity(:edit_authors_in_protocol_repository, nil, protocol: @protocol.id)
|
2022-06-06 19:56:22 +08:00
|
|
|
render json: @protocol, serializer: ProtocolSerializer, user: current_user
|
2019-11-12 18:26:18 +08:00
|
|
|
else
|
|
|
|
render json: @protocol.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_name
|
2023-03-01 22:19:34 +08:00
|
|
|
if @protocol.update(name: params.require(:protocol)[:name], last_modified_by: current_user)
|
2022-08-11 20:09:01 +08:00
|
|
|
log_activity(:edit_protocol_name_in_repository, nil, protocol: @protocol.id)
|
2019-11-12 18:26:18 +08:00
|
|
|
render json: {}, status: :ok
|
|
|
|
else
|
|
|
|
render json: @protocol.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-24 19:34:56 +08:00
|
|
|
def update_description
|
2021-03-20 00:11:19 +08:00
|
|
|
old_description = @protocol.description
|
2019-04-24 19:34:56 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2023-03-01 22:19:34 +08:00
|
|
|
if @protocol.update(description: params.require(:protocol)[:description], last_modified_by: current_user)
|
2019-11-13 20:57:04 +08:00
|
|
|
log_activity(:edit_description_in_protocol_repository, nil, protocol: @protocol.id)
|
2019-08-09 15:47:07 +08:00
|
|
|
TinyMceAsset.update_images(@protocol, params[:tiny_mce_images], current_user)
|
2021-03-20 00:11:19 +08:00
|
|
|
protocol_annotation_notification(old_description)
|
2022-08-10 19:46:50 +08:00
|
|
|
render json: @protocol, serializer: ProtocolSerializer, user: current_user
|
2019-04-24 19:34:56 +08:00
|
|
|
else
|
|
|
|
render json: @protocol.errors, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def create
|
2023-02-17 21:27:20 +08:00
|
|
|
@protocol = Protocol.new(create_params)
|
2016-07-21 19:11:15 +08:00
|
|
|
ts = Time.now
|
2023-02-17 21:27:20 +08:00
|
|
|
@protocol.team = current_team
|
|
|
|
@protocol.protocol_type = :in_repository_draft
|
|
|
|
@protocol.added_by = current_user
|
2016-07-21 19:11:15 +08:00
|
|
|
@protocol.record_timestamps = false
|
|
|
|
@protocol.created_at = ts
|
|
|
|
@protocol.updated_at = ts
|
2023-03-01 22:19:34 +08:00
|
|
|
@protocol.last_modified_by = current_user
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2022-06-03 21:10:05 +08:00
|
|
|
if @protocol.save
|
|
|
|
log_activity(:create_protocol_in_repository, nil, protocol: @protocol.id)
|
|
|
|
redirect_to protocol_path(@protocol)
|
|
|
|
else
|
2023-03-07 02:31:45 +08:00
|
|
|
render json: { error: @protocol.errors.messages.map { |_k, v| v }.join(', ') }, status: :unprocessable_entity
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-06-24 17:21:47 +08:00
|
|
|
def delete_steps
|
2023-01-10 16:25:52 +08:00
|
|
|
@protocol.with_lock do
|
2022-06-24 17:21:47 +08:00
|
|
|
team = @protocol.team
|
|
|
|
previous_size = 0
|
|
|
|
@protocol.steps.each do |step|
|
|
|
|
previous_size += step.space_taken
|
2022-07-05 03:13:15 +08:00
|
|
|
|
|
|
|
if @protocol.in_module?
|
|
|
|
log_activity(:destroy_step, @protocol.my_module.experiment.project,
|
|
|
|
my_module: @protocol.my_module.id,
|
|
|
|
step: step.id,
|
|
|
|
step_position: { id: step.id, value_for: 'position_plus_one' })
|
|
|
|
else
|
|
|
|
log_activity(:delete_step_in_protocol_repository, nil, step: step.id,
|
|
|
|
step_position: { id: step.id, value_for: 'position_plus_one' })
|
|
|
|
end
|
|
|
|
|
2022-08-10 18:05:24 +08:00
|
|
|
# skip adjusting positions after destroy as this is a bulk delete
|
|
|
|
step.skip_position_adjust = true
|
2022-06-24 17:21:47 +08:00
|
|
|
step.destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
team.release_space(previous_size)
|
2022-07-05 03:13:15 +08:00
|
|
|
team.save!
|
2022-06-24 17:21:47 +08:00
|
|
|
render json: { status: 'ok' }
|
|
|
|
rescue ActiveRecord::RecordNotDestroyed
|
|
|
|
render json: { status: 'error' }, status: :unprocessable_entity
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def clone
|
|
|
|
cloned = nil
|
|
|
|
Protocol.transaction do
|
2023-02-18 16:09:33 +08:00
|
|
|
cloned = @original.deep_clone_repository(current_user)
|
|
|
|
rescue StandardError
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2023-02-18 16:09:33 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
respond_to do |format|
|
2023-02-18 16:09:33 +08:00
|
|
|
format.json do
|
|
|
|
if cloned.present?
|
|
|
|
render json: { message: t('protocols.index.clone.success_flash', original: @original.name, new: cloned.name) }
|
|
|
|
else
|
|
|
|
render json: { message: t('protocols.index.clone.error_flash', original: @original.name) },
|
|
|
|
status: :bad_request
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_to_repository
|
|
|
|
respond_to do |format|
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2023-03-31 20:48:23 +08:00
|
|
|
@new_protocol = @protocol.copy_to_repository(Protocol.new(create_params), current_user)
|
|
|
|
log_activity(:task_protocol_save_to_template, @my_module.experiment.project, protocol: @new_protocol.id)
|
2022-07-06 17:45:04 +08:00
|
|
|
rescue StandardError => e
|
2019-09-30 16:25:11 +08:00
|
|
|
transaction_error = true
|
2022-07-06 17:45:04 +08:00
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2023-02-17 21:27:20 +08:00
|
|
|
format.json do
|
|
|
|
if transaction_error
|
|
|
|
# Bad request error
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: {
|
2017-09-26 19:17:00 +08:00
|
|
|
message: t('my_modules.protocols.copy_to_repository_modal.error_400')
|
2016-07-21 19:11:15 +08:00
|
|
|
},
|
|
|
|
status: :bad_request
|
2023-03-31 20:48:23 +08:00
|
|
|
elsif @new_protocol.invalid?
|
2023-04-11 23:19:26 +08:00
|
|
|
render json: { error: @new_protocol.errors.messages.map { |_, value| value }.join(' ') }, status: :unprocessable_entity
|
2023-02-17 21:27:20 +08:00
|
|
|
else
|
|
|
|
# Everything good, render 200
|
|
|
|
render json: { message: t('my_modules.protocols.copy_to_repository_modal.success_message') }
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-22 21:59:48 +08:00
|
|
|
def save_as_draft
|
|
|
|
Protocol.transaction do
|
|
|
|
draft = @protocol.save_as_draft(current_user)
|
|
|
|
|
|
|
|
if draft.invalid?
|
|
|
|
flash[:error] = draft.errors.full_messages.join(', ')
|
|
|
|
redirect_to protocols_path
|
|
|
|
else
|
2023-03-07 21:45:52 +08:00
|
|
|
log_activity(:protocol_template_draft_created, nil, protocol: @protocol.id)
|
2023-02-22 21:59:48 +08:00
|
|
|
redirect_to protocol_path(draft)
|
|
|
|
end
|
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
2023-03-03 22:33:08 +08:00
|
|
|
flash[:error] = I18n.t('errors.general')
|
|
|
|
redirect_to protocols_path
|
2023-02-22 21:59:48 +08:00
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def unlink
|
|
|
|
respond_to do |format|
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
|
|
|
begin
|
|
|
|
@protocol.unlink
|
2023-03-07 16:58:36 +08:00
|
|
|
rescue StandardError
|
2016-07-21 19:11:15 +08:00
|
|
|
transaction_error = true
|
2020-09-29 18:59:02 +08:00
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if transaction_error
|
|
|
|
# Bad request error
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: {
|
2017-09-26 19:17:00 +08:00
|
|
|
message: t('my_modules.protocols.unlink_error')
|
2016-07-21 19:11:15 +08:00
|
|
|
},
|
|
|
|
status: :bad_request
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
|
|
|
# Everything good, display flash & render 200
|
|
|
|
flash[:success] = t(
|
2017-09-26 19:17:00 +08:00
|
|
|
'my_modules.protocols.unlink_flash'
|
2016-07-21 19:11:15 +08:00
|
|
|
)
|
|
|
|
flash.keep(:success)
|
|
|
|
format.json { render json: {}, status: :ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def revert
|
|
|
|
respond_to do |format|
|
2016-10-06 22:13:35 +08:00
|
|
|
if @protocol.can_destroy?
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2020-09-29 18:59:02 +08:00
|
|
|
# Revert is basically update from parent
|
2023-02-28 21:17:34 +08:00
|
|
|
@protocol.update_from_parent(current_user, @protocol.parent)
|
2020-09-29 18:59:02 +08:00
|
|
|
rescue StandardError
|
|
|
|
transaction_error = true
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2016-10-06 22:13:35 +08:00
|
|
|
if transaction_error
|
|
|
|
# Bad request error
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
message: t('my_modules.protocols.revert_error')
|
|
|
|
},
|
|
|
|
status: :bad_request
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# Everything good, display flash & render 200
|
2019-03-21 04:34:47 +08:00
|
|
|
log_activity(:update_protocol_in_task_from_repository,
|
|
|
|
@protocol.my_module.experiment.project,
|
2019-03-29 22:09:20 +08:00
|
|
|
my_module: @protocol.my_module.id,
|
2019-03-21 04:34:47 +08:00
|
|
|
protocol_repository: @protocol.parent.id)
|
2016-10-06 22:13:35 +08:00
|
|
|
flash[:success] = t(
|
|
|
|
'my_modules.protocols.revert_flash'
|
|
|
|
)
|
|
|
|
flash.keep(:success)
|
|
|
|
format.json { render json: {}, status: :ok }
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2016-10-06 22:13:35 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
message: t('my_modules.protocols.revert_error_locked')
|
|
|
|
}, status: :bad_request
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_from_parent
|
2023-02-28 21:17:34 +08:00
|
|
|
protocol_can_destroy = @protocol.can_destroy?
|
2016-07-21 19:11:15 +08:00
|
|
|
respond_to do |format|
|
2023-02-28 21:17:34 +08:00
|
|
|
if protocol_can_destroy
|
2016-10-06 22:13:35 +08:00
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2023-02-28 21:17:34 +08:00
|
|
|
# Find original published protocol template
|
|
|
|
source_parent = if @protocol.parent.in_repository_published_original?
|
|
|
|
@protocol.parent
|
|
|
|
else
|
|
|
|
@protocol.parent.parent
|
|
|
|
end
|
2023-03-06 17:53:01 +08:00
|
|
|
@protocol.update_from_parent(current_user, source_parent.latest_published_version_or_self)
|
2020-09-29 18:59:02 +08:00
|
|
|
rescue StandardError
|
|
|
|
transaction_error = true
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2023-02-28 21:17:34 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2023-02-28 21:17:34 +08:00
|
|
|
format.json do
|
|
|
|
if !protocol_can_destroy
|
|
|
|
render json: { message: t('my_modules.protocols.update_from_parent_error_locked') }, status: :bad_request
|
|
|
|
elsif transaction_error
|
|
|
|
render json: { message: t('my_modules.protocols.update_from_parent_error') }, status: :bad_request
|
2016-10-06 22:13:35 +08:00
|
|
|
else
|
2019-03-21 04:34:47 +08:00
|
|
|
log_activity(:update_protocol_in_task_from_repository,
|
|
|
|
@protocol.my_module.experiment.project,
|
2019-04-03 15:18:18 +08:00
|
|
|
my_module: @protocol.my_module.id,
|
2019-03-21 04:34:47 +08:00
|
|
|
protocol_repository: @protocol.parent.id)
|
2023-02-28 21:17:34 +08:00
|
|
|
|
|
|
|
flash[:success] = t('my_modules.protocols.update_from_parent_flash')
|
2016-10-06 22:13:35 +08:00
|
|
|
flash.keep(:success)
|
2023-02-28 21:17:34 +08:00
|
|
|
render json: {}, status: :ok
|
2016-10-06 22:13:35 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_from_repository
|
|
|
|
respond_to do |format|
|
2016-10-06 22:13:35 +08:00
|
|
|
if @protocol.can_destroy?
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2020-09-29 18:59:02 +08:00
|
|
|
@protocol.load_from_repository(@source, current_user)
|
|
|
|
rescue StandardError
|
|
|
|
transaction_error = true
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2016-10-06 22:13:35 +08:00
|
|
|
if transaction_error
|
|
|
|
# Bad request error
|
2016-12-21 23:52:15 +08:00
|
|
|
format.json do
|
2016-10-06 22:13:35 +08:00
|
|
|
render json: {
|
2016-12-21 23:52:15 +08:00
|
|
|
message: t('my_modules.protocols.load_from_repository_error')
|
2016-10-06 22:13:35 +08:00
|
|
|
},
|
|
|
|
status: :bad_request
|
2016-12-21 23:52:15 +08:00
|
|
|
end
|
2016-10-06 22:13:35 +08:00
|
|
|
else
|
2017-01-03 23:35:25 +08:00
|
|
|
# Everything good, record activity, display flash & render 200
|
2019-03-21 04:34:47 +08:00
|
|
|
log_activity(:load_protocol_to_task_from_repository,
|
|
|
|
@protocol.my_module.experiment.project,
|
2019-03-29 22:09:20 +08:00
|
|
|
my_module: @protocol.my_module.id,
|
2019-03-21 04:34:47 +08:00
|
|
|
protocol_repository: @protocol.parent.id)
|
2016-12-21 23:52:15 +08:00
|
|
|
flash[:success] = t('my_modules.protocols.load_from_repository_flash')
|
2016-10-06 22:13:35 +08:00
|
|
|
flash.keep(:success)
|
|
|
|
format.json { render json: {}, status: :ok }
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2016-10-06 22:13:35 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
message: t('my_modules.protocols.load_from_repository_error_locked')
|
|
|
|
}, status: :bad_request
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_from_file
|
|
|
|
# This is actually very similar to import
|
|
|
|
respond_to do |format|
|
2016-10-06 22:13:35 +08:00
|
|
|
if @protocol.can_destroy?
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2022-06-10 16:18:55 +08:00
|
|
|
@importer.import_into_existing(
|
|
|
|
@protocol, @protocol_json
|
|
|
|
)
|
|
|
|
rescue StandardError => e
|
|
|
|
transaction_error = true
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2016-10-06 22:13:35 +08:00
|
|
|
if transaction_error
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-10-06 22:13:35 +08:00
|
|
|
render json: { status: :error }, status: :bad_request
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-10-06 22:13:35 +08:00
|
|
|
else
|
2017-01-03 23:35:25 +08:00
|
|
|
# Everything good, record activity, display flash & render 200
|
2019-03-21 04:34:47 +08:00
|
|
|
log_activity(:load_protocol_to_task_from_file,
|
2019-03-29 22:09:20 +08:00
|
|
|
@protocol.my_module.experiment.project,
|
|
|
|
my_module: @my_module.id)
|
2016-10-06 22:13:35 +08:00
|
|
|
flash[:success] = t(
|
2017-09-26 19:17:00 +08:00
|
|
|
'my_modules.protocols.load_from_file_flash'
|
2016-10-06 22:13:35 +08:00
|
|
|
)
|
|
|
|
flash.keep(:success)
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-10-06 22:13:35 +08:00
|
|
|
render json: { status: :ok }, status: :ok
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-10-06 22:13:35 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2016-10-06 22:13:35 +08:00
|
|
|
format.json do
|
|
|
|
render json: { status: :locked }, status: :bad_request
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-21 18:03:06 +08:00
|
|
|
def protocolsio_index
|
|
|
|
render json: {
|
2023-06-21 20:13:20 +08:00
|
|
|
html: render_to_string({ partial: 'protocols/index/protocolsio_modal_body' })
|
2023-02-21 18:03:06 +08:00
|
|
|
}
|
|
|
|
end
|
2022-12-19 20:18:24 +08:00
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def import
|
|
|
|
protocol = nil
|
|
|
|
respond_to do |format|
|
|
|
|
transaction_error = false
|
|
|
|
Protocol.transaction do
|
2023-02-27 20:22:01 +08:00
|
|
|
protocol = @importer.import_new_protocol(@protocol_json)
|
2022-06-10 16:18:55 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error e.backtrace.join("\n")
|
|
|
|
transaction_error = true
|
|
|
|
raise ActiveRecord::Rollback
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if transaction_error
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2023-02-27 20:22:01 +08:00
|
|
|
render json: { status: :bad_request }, status: :bad_request
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2019-03-15 17:30:51 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: :import_protocol_in_repository,
|
|
|
|
owner: current_user,
|
|
|
|
subject: protocol,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: protocol.team,
|
2019-03-15 17:30:51 +08:00
|
|
|
message_items: {
|
|
|
|
protocol: protocol.id
|
|
|
|
})
|
2019-03-08 17:57:09 +08:00
|
|
|
|
2019-03-15 17:30:51 +08:00
|
|
|
format.json do
|
2023-02-27 20:22:01 +08:00
|
|
|
render json: { status: :ok }, status: :ok
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-09-22 22:02:56 +08:00
|
|
|
|
2017-09-25 19:53:32 +08:00
|
|
|
def protocolsio_import_create
|
2018-11-26 20:43:05 +08:00
|
|
|
@protocolsio_too_big = false
|
|
|
|
@protocolsio_invalid_file = false
|
|
|
|
@protocolsio_no_file = false
|
|
|
|
if params[:json_file].nil?
|
|
|
|
@protocolsio_no_file = true
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
2018-11-24 03:47:48 +08:00
|
|
|
end
|
2018-11-26 20:43:05 +08:00
|
|
|
return 0 # return 0 stops the rest of the controller code from executing
|
|
|
|
end
|
|
|
|
extension = File.extname(params[:json_file].path)
|
|
|
|
file_size = File.size(params[:json_file].path)
|
|
|
|
if extension != '.txt' && extension != '.json'
|
|
|
|
@protocolsio_invalid_file = true
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {}
|
2018-11-24 03:47:48 +08:00
|
|
|
end
|
2018-11-26 20:43:05 +08:00
|
|
|
return 0 # return 0 stops the rest of the controller code from executing
|
|
|
|
end
|
|
|
|
if file_size > Rails.configuration.x.file_max_size_mb.megabytes
|
|
|
|
@protocolsio_too_big = true
|
2017-09-25 19:53:32 +08:00
|
|
|
respond_to do |format|
|
2018-11-26 20:43:05 +08:00
|
|
|
format.js {}
|
|
|
|
# if file is too big, default to the js.erb file,
|
|
|
|
# named the same as this controller
|
|
|
|
# where a javascript alert is called
|
2017-09-25 19:53:32 +08:00
|
|
|
end
|
2018-11-26 20:43:05 +08:00
|
|
|
return 0 # return 0 stops the rest of the controller code from executing
|
|
|
|
end
|
|
|
|
json_file_contents = File.read(params[:json_file].path)
|
|
|
|
json_file_contents.gsub! '\"', "'"
|
|
|
|
# escaped double quotes too stressfull, html works with single quotes too
|
|
|
|
# json double quotes dont get escaped since they dont match \"
|
|
|
|
unless valid_protocol_json(json_file_contents)
|
|
|
|
@protocolsio_invalid_file = true
|
2017-11-14 19:02:17 +08:00
|
|
|
respond_to do |format|
|
2018-11-26 20:43:05 +08:00
|
|
|
format.js {}
|
2017-11-14 19:02:17 +08:00
|
|
|
end
|
2018-11-26 20:43:05 +08:00
|
|
|
return 0 # return 0 stops the rest of the controller code from executing
|
|
|
|
end
|
|
|
|
@json_object = JSON.parse(json_file_contents)
|
|
|
|
unless step_hash_null?(@json_object['steps'])
|
|
|
|
@json_object['steps'] = protocols_io_guid_reorder_step_json(
|
|
|
|
@json_object['steps']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
@protocol = Protocol.new
|
|
|
|
respond_to do |format|
|
|
|
|
format.js {} # go to the js.erb file named the same as this controller,
|
|
|
|
# where a preview modal is rendered,
|
|
|
|
# and some modals get closed and opened
|
|
|
|
end
|
2018-11-26 20:52:01 +08:00
|
|
|
rescue StandardError => e
|
2022-06-10 16:18:55 +08:00
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
2018-11-26 20:43:05 +08:00
|
|
|
@protocolsio_general_error = true
|
|
|
|
respond_to do |format|
|
2018-11-26 20:52:01 +08:00
|
|
|
format.js {}
|
2017-09-22 17:56:50 +08:00
|
|
|
end
|
|
|
|
end
|
2017-09-25 19:53:32 +08:00
|
|
|
|
|
|
|
def protocolsio_import_save
|
|
|
|
@json_object = JSON.parse(params['json_object'])
|
2017-09-26 19:17:00 +08:00
|
|
|
@db_json = {}
|
2017-11-17 09:43:32 +08:00
|
|
|
@toolong = false
|
|
|
|
@db_json['name'] = pio_eval_title_len(
|
2023-03-14 01:00:30 +08:00
|
|
|
escape_input(not_null(params['protocol']['name']))
|
2017-11-17 09:43:32 +08:00
|
|
|
)
|
2017-09-25 19:53:32 +08:00
|
|
|
# since scinote only has description field, and protocols.io has many others
|
|
|
|
# ,here i am putting everything important from protocols.io into description
|
2017-11-17 09:43:32 +08:00
|
|
|
@db_json['authors'] = pio_eval_title_len(
|
2023-03-14 01:00:30 +08:00
|
|
|
escape_input(not_null(params['protocol']['authors']))
|
2017-11-17 09:43:32 +08:00
|
|
|
)
|
|
|
|
@db_json['created_at'] = pio_eval_title_len(
|
2023-03-14 01:00:30 +08:00
|
|
|
escape_input(not_null(params['protocol']['created_at']))
|
2017-11-17 09:43:32 +08:00
|
|
|
)
|
|
|
|
@db_json['updated_at'] = pio_eval_title_len(
|
2023-03-14 01:00:30 +08:00
|
|
|
escape_input(not_null(params['protocol']['last_modified']))
|
2017-11-17 09:43:32 +08:00
|
|
|
)
|
2017-10-25 01:24:53 +08:00
|
|
|
@db_json['steps'] = {}
|
2018-02-21 23:17:53 +08:00
|
|
|
|
|
|
|
unless step_hash_null?(@json_object['steps'])
|
|
|
|
@db_json['steps'] = protocols_io_fill_step(
|
|
|
|
@json_object, @db_json['steps']
|
|
|
|
)
|
|
|
|
end
|
2017-09-26 19:17:00 +08:00
|
|
|
protocol = nil
|
|
|
|
respond_to do |format|
|
|
|
|
transaction_error = false
|
|
|
|
@protocolsio_general_error = false
|
|
|
|
Protocol.transaction do
|
|
|
|
begin
|
2023-02-27 20:22:01 +08:00
|
|
|
protocol = @importer.import_new_protocol(@db_json)
|
2023-03-07 16:58:36 +08:00
|
|
|
rescue StandardError
|
2017-09-26 19:17:00 +08:00
|
|
|
transaction_error = true
|
2023-03-07 16:58:36 +08:00
|
|
|
raise ActiveRecord::Rollback
|
2017-09-25 19:53:32 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2017-09-26 19:17:00 +08:00
|
|
|
p_name =
|
2017-10-08 04:13:31 +08:00
|
|
|
if @db_json['name'].present?
|
2017-09-26 19:17:00 +08:00
|
|
|
escape_input(@db_json['name'])
|
|
|
|
else
|
|
|
|
t('protocols.index.no_protocol_name')
|
2017-09-25 19:53:32 +08:00
|
|
|
end
|
2017-09-26 19:17:00 +08:00
|
|
|
if transaction_error
|
|
|
|
@protocolsio_general_error = true
|
2017-10-08 04:13:31 +08:00
|
|
|
# General something went wrong, upload to db failed error
|
2017-09-26 19:17:00 +08:00
|
|
|
# format.json {
|
|
|
|
# render json: { name: p_name, status: :bad_request },
|
|
|
|
# status: :bad_request
|
|
|
|
# }
|
2017-09-19 21:02:16 +08:00
|
|
|
else
|
2017-09-26 19:17:00 +08:00
|
|
|
@protocolsio_general_error = false
|
|
|
|
format.json do
|
|
|
|
render json:
|
2017-11-17 09:43:32 +08:00
|
|
|
{ name: @db_json['name'], new_name: @db_json['name'], status: :ok },
|
2017-09-26 19:17:00 +08:00
|
|
|
status: :ok
|
|
|
|
end
|
2017-09-19 21:02:16 +08:00
|
|
|
end
|
2017-09-26 19:17:00 +08:00
|
|
|
format.js {}
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def export
|
2016-12-09 06:21:13 +08:00
|
|
|
# Make a zip output stream and send it to the client
|
2016-07-21 19:11:15 +08:00
|
|
|
respond_to do |format|
|
2016-12-12 22:33:21 +08:00
|
|
|
format.html do
|
2016-12-09 06:21:13 +08:00
|
|
|
z_output_stream = Zip::OutputStream.write_buffer do |ostream|
|
2016-12-12 22:33:21 +08:00
|
|
|
ostream.put_next_entry('scinote.xml')
|
|
|
|
ostream.print(generate_envelope_xml(@protocols))
|
|
|
|
ostream.put_next_entry('scinote.xsd')
|
2016-12-09 06:21:13 +08:00
|
|
|
ostream.print(generate_envelope_xsd)
|
2016-12-12 22:33:21 +08:00
|
|
|
ostream.put_next_entry('eln.xsd')
|
2016-12-09 06:21:13 +08:00
|
|
|
ostream.print(generate_eln_xsd)
|
2016-12-12 22:33:21 +08:00
|
|
|
|
|
|
|
# Create folder and xml file for each protocol and populate it
|
|
|
|
@protocols.each do |protocol|
|
2023-03-06 17:53:01 +08:00
|
|
|
protocol = protocol.latest_published_version_or_self
|
2016-12-12 22:33:21 +08:00
|
|
|
protocol_dir = get_guid(protocol.id).to_s
|
|
|
|
ostream.put_next_entry("#{protocol_dir}/eln.xml")
|
|
|
|
ostream.print(generate_protocol_xml(protocol))
|
2019-04-19 20:44:40 +08:00
|
|
|
ostream = protocol.tiny_mce_assets.save_to_eln(ostream, protocol_dir)
|
2016-12-12 22:33:21 +08:00
|
|
|
# Add assets to protocol folder
|
2017-01-09 23:19:44 +08:00
|
|
|
next if protocol.steps.count <= 0
|
|
|
|
protocol.steps.order(:id).each do |step|
|
|
|
|
step_guid = get_guid(step.id)
|
|
|
|
step_dir = "#{protocol_dir}/#{step_guid}"
|
2017-11-21 23:30:48 +08:00
|
|
|
if step.assets.exists?
|
|
|
|
step.assets.order(:id).each do |asset|
|
2019-07-09 16:28:15 +08:00
|
|
|
next unless asset.file.attached?
|
2017-11-21 23:30:48 +08:00
|
|
|
asset_guid = get_guid(asset.id)
|
2019-07-09 16:28:15 +08:00
|
|
|
asset_file_name = asset_guid.to_s + File.extname(asset.file_name).to_s
|
2017-11-21 23:30:48 +08:00
|
|
|
ostream.put_next_entry("#{step_dir}/#{asset_file_name}")
|
2019-07-09 16:28:15 +08:00
|
|
|
ostream.print(asset.file.download)
|
2017-11-21 23:30:48 +08:00
|
|
|
end
|
|
|
|
end
|
2019-04-19 20:44:40 +08:00
|
|
|
ostream = step.tiny_mce_assets.save_to_eln(ostream, step_dir)
|
2022-06-10 16:18:55 +08:00
|
|
|
|
|
|
|
step.step_texts.each do |step_text|
|
|
|
|
ostream = step_text.tiny_mce_assets.save_to_eln(ostream, step_dir)
|
|
|
|
end
|
2016-12-12 22:33:21 +08:00
|
|
|
end
|
|
|
|
end
|
2016-12-09 06:21:13 +08:00
|
|
|
end
|
|
|
|
z_output_stream.rewind
|
2016-12-12 22:33:21 +08:00
|
|
|
|
|
|
|
protocol_name = get_protocol_name(@protocols[0])
|
|
|
|
|
|
|
|
# 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?
|
2017-01-09 23:19:44 +08:00
|
|
|
escaped_name = protocol_name.gsub(/[^0-9a-zA-Z\-.,_]/i, '_')
|
|
|
|
.downcase[0..Constants::NAME_MAX_LENGTH]
|
2021-07-23 17:56:28 +08:00
|
|
|
file_name = escaped_name + '.eln' unless escaped_name.blank?
|
2016-12-12 22:33:21 +08:00
|
|
|
end
|
|
|
|
elsif @protocols.length > 1
|
|
|
|
file_name = 'protocols.eln'
|
|
|
|
end
|
2019-03-08 17:57:09 +08:00
|
|
|
|
2022-11-24 22:19:17 +08:00
|
|
|
@protocols.each do |protocol|
|
2019-04-02 17:50:37 +08:00
|
|
|
if params[:my_module_id]
|
2019-04-04 16:45:35 +08:00
|
|
|
my_module = MyModule.find(params[:my_module_id])
|
2019-04-02 17:50:37 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: :export_protocol_from_task,
|
|
|
|
owner: current_user,
|
2022-11-24 22:19:17 +08:00
|
|
|
project: my_module.project,
|
2019-04-04 16:45:35 +08:00
|
|
|
subject: my_module,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: my_module.team,
|
2019-04-02 17:50:37 +08:00
|
|
|
message_items: {
|
|
|
|
my_module: params[:my_module_id].to_i
|
|
|
|
})
|
|
|
|
else
|
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: :export_protocol_in_repository,
|
|
|
|
owner: current_user,
|
2022-11-24 22:19:17 +08:00
|
|
|
subject: protocol,
|
|
|
|
team: protocol.team,
|
2019-04-02 17:50:37 +08:00
|
|
|
message_items: {
|
2022-11-24 22:19:17 +08:00
|
|
|
protocol: protocol.id
|
2019-04-02 17:50:37 +08:00
|
|
|
})
|
|
|
|
end
|
2019-03-08 17:57:09 +08:00
|
|
|
end
|
|
|
|
|
2016-12-12 22:33:21 +08:00
|
|
|
send_data(z_output_stream.read, filename: file_name)
|
2016-12-09 06:21:13 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unlink_modal
|
|
|
|
respond_to do |format|
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: {
|
2017-09-26 19:17:00 +08:00
|
|
|
title: t('my_modules.protocols.confirm_link_update_modal.unlink_title'),
|
|
|
|
message: t('my_modules.protocols.confirm_link_update_modal.unlink_message'),
|
|
|
|
btn_text: t('my_modules.protocols.confirm_link_update_modal.unlink_btn_text'),
|
2016-07-21 19:11:15 +08:00
|
|
|
url: unlink_protocol_path(@protocol)
|
|
|
|
}
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def revert_modal
|
|
|
|
respond_to do |format|
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: {
|
2017-09-26 19:17:00 +08:00
|
|
|
title: t('my_modules.protocols.confirm_link_update_modal.revert_title'),
|
|
|
|
message: t('my_modules.protocols.confirm_link_update_modal.revert_message'),
|
|
|
|
btn_text: t('my_modules.protocols.confirm_link_update_modal.revert_btn_text'),
|
2016-07-21 19:11:15 +08:00
|
|
|
url: revert_protocol_path(@protocol)
|
|
|
|
}
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_from_parent_modal
|
|
|
|
respond_to do |format|
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: {
|
2017-09-26 19:17:00 +08:00
|
|
|
title: t('my_modules.protocols.confirm_link_update_modal.update_self_title'),
|
|
|
|
message: t('my_modules.protocols.confirm_link_update_modal.update_self_message'),
|
2023-02-28 21:17:34 +08:00
|
|
|
btn_text: t('my_modules.protocols.confirm_link_update_modal.update_self_btn_text'),
|
2016-07-21 19:11:15 +08:00
|
|
|
url: update_from_parent_protocol_path(@protocol)
|
|
|
|
}
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_from_repository_datatable
|
|
|
|
@protocol = Protocol.find_by_id(params[:id])
|
|
|
|
respond_to do |format|
|
2017-09-26 19:17:00 +08:00
|
|
|
format.json do
|
2016-07-21 19:11:15 +08:00
|
|
|
render json: ::LoadFromRepositoryProtocolsDatatable.new(
|
|
|
|
view_context,
|
2017-01-24 23:57:14 +08:00
|
|
|
@protocol.team,
|
2016-07-21 19:11:15 +08:00
|
|
|
current_user
|
|
|
|
)
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_from_repository_modal
|
2023-07-05 18:43:23 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'my_modules/protocols/load_from_repository_modal_body', formats: :html)
|
|
|
|
}
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def protocol_status_bar
|
2023-07-05 18:43:23 +08:00
|
|
|
render json: {
|
|
|
|
html: render_to_string(partial: 'my_modules/protocols/protocol_status_bar', formats: :html)
|
|
|
|
}
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2023-04-11 18:50:14 +08:00
|
|
|
def version_comment
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: { version_comment: @protocol.version_comment }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-26 19:39:11 +08:00
|
|
|
def update_version_comment
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
if @protocol.update(version_comment: params.require(:protocol)[:version_comment])
|
2023-02-21 22:25:01 +08:00
|
|
|
log_activity(:protocol_template_revision_notes_updated,
|
|
|
|
nil,
|
|
|
|
protocol: @protocol.id)
|
2023-01-26 19:39:11 +08:00
|
|
|
render json: { version_comment: @protocol.version_comment }
|
|
|
|
else
|
2023-04-14 21:10:35 +08:00
|
|
|
render json: { errors: @protocol.errors }, status: :unprocessable_entity
|
2023-01-26 19:39:11 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-06 22:54:50 +08:00
|
|
|
def permissions
|
2023-03-24 18:52:48 +08:00
|
|
|
if stale?([@protocol, @protocol.team.user_assignments])
|
2022-12-06 22:54:50 +08:00
|
|
|
render json: {
|
|
|
|
copyable: can_clone_protocol_in_repository?(@protocol),
|
2023-02-17 01:03:11 +08:00
|
|
|
archivable: can_archive_protocol_in_repository?(@protocol),
|
2023-05-16 16:29:00 +08:00
|
|
|
restorable: can_restore_protocol_in_repository?(@protocol),
|
|
|
|
readable: can_read_protocol_in_repository?(@protocol)
|
2022-12-06 22:54:50 +08:00
|
|
|
}
|
2023-01-26 22:41:41 +08:00
|
|
|
end
|
2022-12-06 22:54:50 +08:00
|
|
|
end
|
|
|
|
|
2023-05-17 20:12:40 +08:00
|
|
|
def actions_toolbar
|
|
|
|
render json: {
|
|
|
|
actions:
|
|
|
|
Toolbars::ProtocolsService.new(
|
|
|
|
current_user,
|
|
|
|
protocol_ids: params[:protocol_ids].split(',')
|
|
|
|
).actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
private
|
|
|
|
|
2022-06-10 16:18:55 +08:00
|
|
|
def set_importer
|
|
|
|
case params.dig('protocol', 'elnVersion')
|
|
|
|
when '1.0'
|
|
|
|
@importer = ProtocolsImporter.new(current_user, current_team)
|
|
|
|
when '1.1'
|
|
|
|
@importer = ProtocolsImporterV2.new(current_user, current_team)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-14 19:02:17 +08:00
|
|
|
def valid_protocol_json(json)
|
|
|
|
JSON.parse(json)
|
|
|
|
return true
|
|
|
|
rescue JSON::ParserError => e
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2023-03-23 22:32:22 +08:00
|
|
|
def move_protocols(action)
|
|
|
|
Protocol.transaction do
|
|
|
|
@protocols.find_each do |protocol|
|
|
|
|
protocol = protocol.parent if protocol.parent_id
|
|
|
|
unless protocol.method(action).call(current_user)
|
|
|
|
raise StandardError, protocol.errors&.messages&.values&.join(' ') || I18n.t('errors.general')
|
2017-09-26 19:17:00 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
2023-03-23 22:32:22 +08:00
|
|
|
render json: { message: t("protocols.index.#{action}_flash_html", count: @protocols.size) }
|
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
|
|
|
render json: { message: e.message }, status: :unprocessable_entity
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2023-01-05 18:42:59 +08:00
|
|
|
|
|
|
|
def set_inline_name_editing
|
2023-03-02 20:50:47 +08:00
|
|
|
return unless @protocol.initial_draft?
|
2023-03-14 16:12:54 +08:00
|
|
|
return unless can_manage_protocol_draft_in_repository?(@protocol)
|
2023-01-05 18:42:59 +08:00
|
|
|
|
|
|
|
@inline_editable_title_config = {
|
|
|
|
name: 'title',
|
|
|
|
params_group: 'protocol',
|
|
|
|
item_id: @protocol.id,
|
|
|
|
field_to_udpate: 'name',
|
|
|
|
path_to_update: name_protocol_path(@protocol)
|
|
|
|
}
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2017-01-24 23:57:14 +08:00
|
|
|
def load_team_and_type
|
|
|
|
@current_team = current_team
|
2016-07-21 19:11:15 +08:00
|
|
|
# :public, :private or :archive
|
2022-12-09 19:44:41 +08:00
|
|
|
@type = (params[:type] || 'active').to_sym
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_view_all_permissions
|
2017-01-24 23:57:14 +08:00
|
|
|
load_team_and_type
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2017-11-27 18:24:41 +08:00
|
|
|
render_403 unless can_read_team?(@current_team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_view_permissions
|
2023-02-22 21:59:48 +08:00
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
2022-12-01 21:55:23 +08:00
|
|
|
current_team_switch(@protocol.team) if current_team != @protocol.team
|
2018-02-02 01:41:28 +08:00
|
|
|
unless @protocol.present? &&
|
|
|
|
(can_read_protocol_in_module?(@protocol) ||
|
2023-05-16 16:29:00 +08:00
|
|
|
can_read_protocol_in_repository?(@protocol) ||
|
|
|
|
(@protocol.in_repository? && can_manage_team?(@protocol.team)))
|
2023-03-02 22:05:50 +08:00
|
|
|
render_403
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_create_permissions
|
2017-01-24 23:57:14 +08:00
|
|
|
load_team_and_type
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2018-01-05 22:15:50 +08:00
|
|
|
if !can_create_protocols_in_repository?(@current_team) || @type == :archive
|
2016-07-21 19:11:15 +08:00
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_clone_permissions
|
2017-01-24 23:57:14 +08:00
|
|
|
load_team_and_type
|
2023-05-31 15:38:24 +08:00
|
|
|
protocol = Protocol.find_by(id: params[:protocol_ids])
|
2023-03-06 17:53:01 +08:00
|
|
|
@original = protocol.latest_published_version_or_self
|
2016-07-21 19:11:15 +08:00
|
|
|
|
|
|
|
if @original.blank? ||
|
2018-02-02 01:41:28 +08:00
|
|
|
!can_clone_protocol_in_repository?(@original) || @type == :archive
|
2016-07-21 19:11:15 +08:00
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
def check_manage_permissions
|
2023-02-22 21:59:48 +08:00
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
2018-02-16 01:46:29 +08:00
|
|
|
render_403 unless @protocol.present? &&
|
2018-02-19 21:47:36 +08:00
|
|
|
(can_manage_protocol_in_module?(@protocol) ||
|
2023-03-24 17:55:17 +08:00
|
|
|
can_manage_protocol_draft_in_repository?(@protocol))
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2023-04-25 22:00:20 +08:00
|
|
|
def check_manage_with_read_protocol_permissions
|
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
|
|
|
render_403 unless @protocol.present? && @protocol.parent.present? &&
|
|
|
|
(can_manage_protocol_in_module?(@protocol) &&
|
|
|
|
can_read_protocol_in_repository?(@protocol.parent))
|
|
|
|
end
|
|
|
|
|
2023-02-22 21:59:48 +08:00
|
|
|
def check_save_as_draft_permissions
|
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
2023-03-21 17:59:31 +08:00
|
|
|
render_403 unless @protocol.present? && can_save_protocol_version_as_draft?(@protocol)
|
2023-02-22 21:59:48 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_delete_draft_permissions
|
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
|
|
|
render_403 unless @protocol.present? &&
|
|
|
|
can_delete_protocol_draft_in_repository?(@protocol)
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2023-02-17 01:03:11 +08:00
|
|
|
def check_archive_all_in_repository_permissions
|
|
|
|
@protocols = Protocol.where(id: params[:protocol_ids])
|
|
|
|
@protocols.find_each do |protocol|
|
|
|
|
unless can_archive_protocol_in_repository?(protocol)
|
|
|
|
respond_to { |f| f.json { render json: {}, status: :unauthorized } }
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-19 21:47:36 +08:00
|
|
|
def check_restore_all_in_repository_permissions
|
2018-02-16 19:03:44 +08:00
|
|
|
@protocols = Protocol.where(id: params[:protocol_ids])
|
|
|
|
@protocols.find_each do |protocol|
|
2018-02-19 21:47:36 +08:00
|
|
|
unless can_restore_protocol_in_repository?(protocol)
|
2018-02-16 19:03:44 +08:00
|
|
|
respond_to { |f| f.json { render json: {}, status: :unauthorized } }
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_load_from_repository_views_permissions
|
|
|
|
@protocol = Protocol.find_by_id(params[:id])
|
|
|
|
|
2018-02-02 01:41:28 +08:00
|
|
|
render_403 if @protocol.blank? || !can_read_protocol_in_module?(@protocol)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
2023-02-13 16:50:39 +08:00
|
|
|
def check_publish_permission
|
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
|
|
|
|
|
|
|
render_403 if @protocol.blank? || !can_publish_protocol_in_repository?(@protocol)
|
|
|
|
end
|
|
|
|
|
2016-07-21 19:11:15 +08:00
|
|
|
def check_load_from_repository_permissions
|
2023-02-14 20:19:24 +08:00
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
2023-03-06 17:53:01 +08:00
|
|
|
@source = Protocol.find_by(id: params[:source_id])&.latest_published_version_or_self
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2018-02-02 01:41:28 +08:00
|
|
|
render_403 unless @protocol.present? && @source.present? &&
|
2020-09-08 21:42:30 +08:00
|
|
|
(can_manage_protocol_in_module?(@protocol) &&
|
2018-02-02 01:41:28 +08:00
|
|
|
can_read_protocol_in_repository?(@source))
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_load_from_file_permissions
|
|
|
|
@protocol_json = params[:protocol]
|
|
|
|
@protocol = Protocol.find_by_id(params[:id])
|
|
|
|
@my_module = @protocol.my_module
|
|
|
|
|
|
|
|
if @protocol_json.blank? ||
|
2017-09-26 19:17:00 +08:00
|
|
|
@protocol.blank? ||
|
|
|
|
@my_module.blank? ||
|
2018-02-02 01:41:28 +08:00
|
|
|
!can_manage_protocol_in_module?(@protocol)
|
2016-07-21 19:11:15 +08:00
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_copy_to_repository_permissions
|
2023-02-17 21:27:20 +08:00
|
|
|
@protocol = Protocol.find_by(id: params[:id])
|
2016-07-21 19:11:15 +08:00
|
|
|
@my_module = @protocol.my_module
|
|
|
|
|
2018-02-02 01:41:28 +08:00
|
|
|
render_403 unless @my_module.present? &&
|
2018-02-06 01:55:37 +08:00
|
|
|
(can_read_protocol_in_module?(@protocol) ||
|
|
|
|
can_create_protocols_in_repository?(@protocol.team))
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_import_permissions
|
|
|
|
@protocol_json = params[:protocol]
|
2017-01-25 00:06:51 +08:00
|
|
|
@team = Team.find(params[:team_id])
|
2023-02-27 20:22:01 +08:00
|
|
|
render_403 unless @protocol_json.present? && @team.present? && can_create_protocols_in_repository?(@team)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_export_permissions
|
|
|
|
@protocols = Protocol.where(id: params[:protocol_ids])
|
2017-12-06 02:51:44 +08:00
|
|
|
render_403 if @protocols.blank?
|
|
|
|
@protocols.each do |p|
|
2018-02-02 01:41:28 +08:00
|
|
|
render_403 unless can_read_protocol_in_module?(p) ||
|
|
|
|
can_read_protocol_in_repository?(p)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_to_repository_params
|
|
|
|
params.require(:protocol).permit(:name, :protocol_type)
|
|
|
|
end
|
|
|
|
|
2023-02-17 21:27:20 +08:00
|
|
|
def create_params
|
|
|
|
params.require(:protocol).permit(:name, :default_public_user_role_id, :visibility)
|
|
|
|
end
|
|
|
|
|
2018-03-26 19:07:00 +08:00
|
|
|
def check_protocolsio_import_permissions
|
2018-03-19 23:10:28 +08:00
|
|
|
render_403 unless can_create_protocols_in_repository?(current_team)
|
|
|
|
end
|
2019-03-08 17:57:09 +08:00
|
|
|
|
2019-03-21 04:34:47 +08:00
|
|
|
def log_activity(type_of, project = nil, message_items = {})
|
2019-04-02 17:50:37 +08:00
|
|
|
message_items = { protocol: @protocol&.id }.merge(message_items)
|
2019-03-19 23:12:07 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
|
|
|
subject: @protocol,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: @protocol.team,
|
2019-03-21 04:34:47 +08:00
|
|
|
project: project,
|
|
|
|
message_items: message_items)
|
2019-03-19 23:12:07 +08:00
|
|
|
end
|
2021-03-20 00:11:19 +08:00
|
|
|
|
|
|
|
def protocol_annotation_notification(old_text)
|
|
|
|
smart_annotation_notification(
|
|
|
|
old_text: old_text,
|
|
|
|
new_text: @protocol.description,
|
|
|
|
title: t('notifications.protocol_description_annotation_title',
|
|
|
|
user: current_user.full_name,
|
|
|
|
protocol: @protocol.name),
|
|
|
|
message: t('notifications.protocol_description_annotation_message_html',
|
2022-12-01 21:55:23 +08:00
|
|
|
protocol: link_to(@protocol.name, protocol_url(@protocol)))
|
2021-03-20 00:11:19 +08:00
|
|
|
)
|
|
|
|
end
|
2023-04-19 16:53:39 +08:00
|
|
|
|
|
|
|
def set_breadcrumbs_items
|
|
|
|
@breadcrumbs_items = []
|
2023-06-01 20:28:47 +08:00
|
|
|
archived_branch = params[:type] == 'archived' || @protocol&.archived?
|
2023-04-19 16:53:39 +08:00
|
|
|
|
2023-06-13 15:25:14 +08:00
|
|
|
@breadcrumbs_items.push({
|
|
|
|
label: t('breadcrumbs.templates'),
|
|
|
|
url: archived_branch ? protocols_path(type: :archived) : protocols_path,
|
|
|
|
archived: archived_branch
|
|
|
|
})
|
|
|
|
|
2023-04-19 16:53:39 +08:00
|
|
|
@breadcrumbs_items.push({
|
|
|
|
label: t('breadcrumbs.protocols'),
|
2023-06-01 20:28:47 +08:00
|
|
|
url: archived_branch ? protocols_path(type: :archived) : protocols_path,
|
|
|
|
archived: archived_branch
|
2023-04-19 16:53:39 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
if @protocol
|
|
|
|
@breadcrumbs_items.push({
|
|
|
|
label: @protocol.name,
|
|
|
|
url: protocol_path(@protocol),
|
2023-06-01 20:28:47 +08:00
|
|
|
archived: archived_branch
|
2023-04-19 16:53:39 +08:00
|
|
|
})
|
|
|
|
end
|
2023-05-24 06:52:26 +08:00
|
|
|
|
2023-06-01 17:31:54 +08:00
|
|
|
@breadcrumbs_items.each do |item|
|
|
|
|
item[:label] = "(A) #{item[:label]}" if item[:archived]
|
2023-05-24 06:52:26 +08:00
|
|
|
end
|
2023-04-19 16:53:39 +08:00
|
|
|
end
|
2016-08-12 22:31:40 +08:00
|
|
|
end
|