2019-02-27 23:02:53 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalActivitiesHelper
|
|
|
|
include ActionView::Helpers::AssetTagHelper
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2021-03-09 18:02:52 +08:00
|
|
|
def generate_activity_content(activity, no_links: false, no_custom_links: false)
|
2019-02-27 23:02:53 +08:00
|
|
|
parameters = {}
|
2019-09-05 14:33:53 +08:00
|
|
|
activity.message_items.each do |key, value|
|
2019-02-27 23:02:53 +08:00
|
|
|
parameters[key] =
|
|
|
|
if value.is_a? String
|
|
|
|
value
|
2019-09-05 14:33:53 +08:00
|
|
|
elsif value['type'] == 'Time' # use saved date for printing
|
2021-02-18 20:55:03 +08:00
|
|
|
I18n.l(Time.zone.at(value['value']), format: :full)
|
2019-02-27 23:02:53 +08:00
|
|
|
else
|
2019-04-01 17:26:51 +08:00
|
|
|
no_links ? generate_name(value) : generate_link(value, activity)
|
2019-02-27 23:02:53 +08:00
|
|
|
end
|
2022-03-10 01:43:38 +08:00
|
|
|
|
|
|
|
if key == 'comment' && parameters[key].strip.present?
|
|
|
|
parameters[key] = '<i class="fas fa-comment"></i>' + parameters[key]
|
|
|
|
end
|
2019-02-27 23:02:53 +08:00
|
|
|
end
|
2021-02-25 14:43:04 +08:00
|
|
|
|
2021-03-09 18:02:52 +08:00
|
|
|
if no_custom_links
|
2021-02-25 14:43:04 +08:00
|
|
|
I18n.t("global_activities.content.#{activity.type_of}_html", parameters.symbolize_keys)
|
|
|
|
else
|
|
|
|
custom_auto_link(
|
|
|
|
I18n.t("global_activities.content.#{activity.type_of}_html", parameters.symbolize_keys),
|
|
|
|
team: activity.team
|
|
|
|
)
|
|
|
|
end
|
2019-09-05 14:33:53 +08:00
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error(e.message)
|
|
|
|
Rails.logger.error(e.backtrace.join("\n"))
|
2019-04-04 03:14:11 +08:00
|
|
|
I18n.t('global_activities.index.content_generation_error', activity_id: activity.id)
|
2019-02-27 23:02:53 +08:00
|
|
|
end
|
|
|
|
|
2019-03-19 20:33:32 +08:00
|
|
|
def generate_link(message_item, activity)
|
2021-01-22 18:24:08 +08:00
|
|
|
obj = if message_item['id']
|
|
|
|
message_item['type'].constantize.find_by(id: message_item['id'])
|
|
|
|
else
|
|
|
|
message_item['type'].constantize.new
|
|
|
|
end
|
|
|
|
|
2019-09-05 14:33:53 +08:00
|
|
|
return message_item['value'] unless obj
|
2019-02-27 23:02:53 +08:00
|
|
|
|
2019-04-01 17:26:51 +08:00
|
|
|
current_value = generate_name(message_item)
|
2019-03-28 21:56:34 +08:00
|
|
|
team = activity.team
|
|
|
|
path = ''
|
2019-02-27 23:02:53 +08:00
|
|
|
|
2019-03-28 20:43:50 +08:00
|
|
|
case obj
|
|
|
|
when User
|
2019-04-03 18:53:52 +08:00
|
|
|
return "[@#{obj.full_name}~#{obj.id.base62_encode}]"
|
2019-03-28 20:43:50 +08:00
|
|
|
when Tag
|
|
|
|
# Not link for now
|
2019-03-28 21:56:34 +08:00
|
|
|
return current_value
|
2019-03-28 20:43:50 +08:00
|
|
|
when Team
|
2020-04-23 18:40:43 +08:00
|
|
|
path = projects_path(team: obj.id)
|
2019-03-28 20:43:50 +08:00
|
|
|
when Repository
|
2020-04-23 22:02:36 +08:00
|
|
|
path = repository_path(obj, team: obj.team.id)
|
2019-03-28 20:43:50 +08:00
|
|
|
when RepositoryRow
|
2019-04-04 03:14:11 +08:00
|
|
|
return current_value unless obj.repository
|
2019-04-15 17:35:30 +08:00
|
|
|
|
2020-04-23 22:02:36 +08:00
|
|
|
path = repository_path(obj.repository, team: obj.repository.team.id)
|
2019-03-28 20:43:50 +08:00
|
|
|
when RepositoryColumn
|
2019-04-04 03:14:11 +08:00
|
|
|
return current_value unless obj.repository
|
2019-04-15 17:35:30 +08:00
|
|
|
|
2020-04-23 22:02:36 +08:00
|
|
|
path = repository_path(obj.repository, team: obj.repository.team.id)
|
2019-03-28 20:43:50 +08:00
|
|
|
when Project
|
|
|
|
path = obj.archived? ? projects_path : project_path(obj)
|
|
|
|
when Experiment
|
|
|
|
return current_value unless obj.navigable?
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2021-02-11 21:16:57 +08:00
|
|
|
path = obj.archived? ? project_path(obj.project, view_mode: :archived) : canvas_experiment_path(obj)
|
2019-03-28 20:43:50 +08:00
|
|
|
when MyModule
|
|
|
|
return current_value unless obj.navigable?
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2019-04-15 17:35:30 +08:00
|
|
|
path = if obj.archived?
|
|
|
|
module_archive_experiment_path(obj.experiment)
|
|
|
|
else
|
2020-04-23 20:05:34 +08:00
|
|
|
protocols_my_module_path(obj)
|
2019-04-15 17:35:30 +08:00
|
|
|
end
|
2019-03-28 20:43:50 +08:00
|
|
|
when Protocol
|
2019-04-12 21:14:41 +08:00
|
|
|
if obj.in_repository_public?
|
2020-04-23 22:02:36 +08:00
|
|
|
path = protocols_path(type: :public, team: obj.team.id)
|
2019-04-12 21:14:41 +08:00
|
|
|
elsif obj.in_repository_private?
|
2020-04-23 22:02:36 +08:00
|
|
|
path = protocols_path(type: :private, team: obj.team.id)
|
2019-04-12 21:14:41 +08:00
|
|
|
elsif obj.in_repository_archived?
|
2020-04-23 22:02:36 +08:00
|
|
|
path = protocols_path(type: :archive, team: obj.team.id)
|
2019-03-28 20:43:50 +08:00
|
|
|
elsif obj.my_module.navigable?
|
2019-03-28 21:56:34 +08:00
|
|
|
path = protocols_my_module_path(obj.my_module)
|
2019-03-28 20:43:50 +08:00
|
|
|
else
|
2019-03-28 21:56:34 +08:00
|
|
|
return current_value
|
2019-03-28 20:43:50 +08:00
|
|
|
end
|
|
|
|
when Result
|
|
|
|
return current_value unless obj.navigable?
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2019-03-28 20:43:50 +08:00
|
|
|
path = obj.archived? ? archive_my_module_path(obj.my_module) : results_my_module_path(obj.my_module)
|
2019-03-29 22:12:15 +08:00
|
|
|
when Step
|
2019-04-02 16:36:11 +08:00
|
|
|
return current_value
|
2019-04-01 14:55:09 +08:00
|
|
|
when Report
|
2021-05-06 20:00:33 +08:00
|
|
|
preview_type = activity.type_of == 'generate_docx_report' ? :docx : :pdf
|
|
|
|
path = reports_path(team: obj.team.id, preview_report_id: obj.id, preview_type: preview_type)
|
2020-12-01 21:51:26 +08:00
|
|
|
when ProjectFolder
|
2021-01-22 18:24:08 +08:00
|
|
|
path = if obj.new_record?
|
|
|
|
projects_path(team: activity.team.id)
|
|
|
|
else
|
|
|
|
project_folder_path(obj, team: obj.team.id)
|
|
|
|
end
|
2019-03-28 20:43:50 +08:00
|
|
|
else
|
2019-03-28 21:56:34 +08:00
|
|
|
return current_value
|
2019-03-28 20:43:50 +08:00
|
|
|
end
|
2019-03-29 22:12:15 +08:00
|
|
|
route_to_other_team(path, team, current_value)
|
2019-02-27 23:02:53 +08:00
|
|
|
end
|
2019-04-01 17:26:51 +08:00
|
|
|
|
|
|
|
def generate_name(message_item)
|
2021-01-22 18:24:08 +08:00
|
|
|
obj = if message_item['id']
|
|
|
|
message_item['type'].constantize.find_by(id: message_item['id'])
|
|
|
|
else
|
|
|
|
message_item['type'].constantize.new
|
|
|
|
end
|
|
|
|
|
|
|
|
return I18n.t('projects.index.breadcrumbs_root') if obj.is_a?(ProjectFolder) && obj.new_record?
|
|
|
|
|
2019-09-05 14:33:53 +08:00
|
|
|
return message_item['value'] unless obj
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2019-09-05 14:33:53 +08:00
|
|
|
value = obj.public_send(message_item['value_for'] || 'name')
|
2019-04-08 21:07:45 +08:00
|
|
|
value = I18n.t('global_activities.index.no_name') if value.blank?
|
2019-04-02 16:36:11 +08:00
|
|
|
|
2019-03-29 22:12:15 +08:00
|
|
|
value
|
2019-04-01 17:26:51 +08:00
|
|
|
end
|
2019-02-27 23:02:53 +08:00
|
|
|
end
|