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?
|
2023-06-08 14:33:37 +08:00
|
|
|
parameters[key] = '<i class="sn-icon sn-icon-comments"></i>' + parameters[key]
|
2022-03-10 01:43:38 +08:00
|
|
|
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
|
2023-07-05 18:43:23 +08:00
|
|
|
I18n.t("global_activities.content.#{activity.type_of}_html", **parameters.symbolize_keys)
|
2021-02-25 14:43:04 +08:00
|
|
|
else
|
|
|
|
custom_auto_link(
|
2023-07-05 18:43:23 +08:00
|
|
|
I18n.t("global_activities.content.#{activity.type_of}_html", **parameters.symbolize_keys),
|
2021-02-25 14:43:04 +08:00
|
|
|
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
|
2023-12-07 03:53:11 +08:00
|
|
|
path = obj.archived? ? projects_path : experiments_path(project_id: obj)
|
2019-03-28 20:43:50 +08:00
|
|
|
when Experiment
|
|
|
|
return current_value unless obj.navigable?
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2023-12-07 03:53:11 +08:00
|
|
|
path = if obj.archived?
|
|
|
|
experiments_path(project_id: obj.project, view_mode: :archived)
|
|
|
|
else
|
|
|
|
my_modules_experiment_path(obj)
|
|
|
|
end
|
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?
|
2023-01-12 18:31:04 +08:00
|
|
|
my_modules_experiment_path(obj.experiment, view_mode: :archived)
|
2019-04-15 17:35:30 +08:00
|
|
|
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
|
2023-02-21 22:25:01 +08:00
|
|
|
if obj.my_module.nil?
|
|
|
|
path = protocols_path(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
|
|
|
|
2023-09-05 22:23:42 +08:00
|
|
|
path = obj.archived? ? archive_my_module_path(obj.my_module) : my_module_results_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
|
2024-09-11 20:36:14 +08:00
|
|
|
when StorageLocation
|
2024-09-21 00:41:57 +08:00
|
|
|
path = if obj.new_record?
|
|
|
|
storage_locations_path(team: activity.team.id)
|
|
|
|
else
|
|
|
|
storage_location_path(obj)
|
|
|
|
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?
|
|
|
|
|
2024-09-21 00:41:57 +08:00
|
|
|
return I18n.t('storage_locations.index.breadcrumbs_root') if obj.is_a?(StorageLocation) && 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
|