2019-02-27 23:02:53 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module GlobalActivitiesHelper
|
|
|
|
include ActionView::Helpers::AssetTagHelper
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include InputSanitizeHelper
|
|
|
|
|
2019-04-01 17:26:51 +08:00
|
|
|
def generate_activity_content(activity, no_links = false)
|
2019-02-27 23:02:53 +08:00
|
|
|
parameters = {}
|
2019-03-19 20:33:32 +08:00
|
|
|
activity.values[:message_items].each do |key, value|
|
2019-02-27 23:02:53 +08:00
|
|
|
parameters[key] =
|
|
|
|
if value.is_a? String
|
|
|
|
value
|
2019-04-02 20:21:06 +08:00
|
|
|
elsif value[:type] == 'Time' # use saved date for printing
|
|
|
|
l(Time.at(value[:value]), format: :full_date)
|
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
|
|
|
|
end
|
2019-04-03 18:53:52 +08:00
|
|
|
custom_auto_link(
|
|
|
|
I18n.t("global_activities.content.#{activity.type_of}_html", parameters.symbolize_keys),
|
|
|
|
team: activity.team
|
|
|
|
)
|
2019-04-04 03:14:11 +08:00
|
|
|
rescue StandardError => ex
|
|
|
|
Rails.logger.error(ex.message)
|
|
|
|
Rails.logger.error(ex.backtrace.join("\n"))
|
|
|
|
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)
|
2019-04-01 17:26:51 +08:00
|
|
|
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
|
|
|
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
|
2019-03-28 21:56:34 +08:00
|
|
|
path = projects_path
|
2019-03-28 20:43:50 +08:00
|
|
|
when Repository
|
2019-03-28 21:56:34 +08:00
|
|
|
path = repository_path(obj)
|
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
|
|
|
|
2019-03-28 21:56:34 +08:00
|
|
|
path = repository_path(obj.repository)
|
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
|
|
|
|
2019-03-28 21:56:34 +08:00
|
|
|
path = repository_path(obj.repository)
|
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
|
|
|
|
2019-03-28 20:43:50 +08:00
|
|
|
path = obj.archived? ? experiment_archive_project_path(obj.project) : canvas_experiment_path(obj)
|
|
|
|
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
|
|
|
|
path = if %w(assign_repository_record unassign_repository_record).include? activity.type_of
|
|
|
|
repository_my_module_path(obj, activity.values['message_items']['repository']['id'])
|
|
|
|
else
|
|
|
|
protocols_my_module_path(obj)
|
|
|
|
end
|
|
|
|
end
|
2019-03-28 20:43:50 +08:00
|
|
|
when Protocol
|
2019-04-12 21:14:41 +08:00
|
|
|
if obj.in_repository_public?
|
|
|
|
path = protocols_path(type: :public)
|
|
|
|
elsif obj.in_repository_private?
|
|
|
|
path = protocols_path(type: :private)
|
|
|
|
elsif obj.in_repository_archived?
|
|
|
|
path = protocols_path(type: :archive)
|
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
|
|
|
|
path = reports_path
|
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)
|
|
|
|
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
|
|
|
return message_item[:value] unless obj
|
2019-03-29 22:12:15 +08:00
|
|
|
|
2019-04-02 16:36:11 +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
|