mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Add global activities to reports [SCI-3255]
This commit is contained in:
parent
913bdd91be
commit
98e58ff7eb
5 changed files with 30 additions and 16 deletions
|
@ -5,30 +5,25 @@ module GlobalActivitiesHelper
|
|||
include ActionView::Helpers::UrlHelper
|
||||
include InputSanitizeHelper
|
||||
|
||||
def generate_activity_content(activity)
|
||||
def generate_activity_content(activity, no_links = false)
|
||||
parameters = {}
|
||||
activity.values[:message_items].each do |key, value|
|
||||
parameters[key] =
|
||||
if value.is_a? String
|
||||
value
|
||||
else
|
||||
generate_link(value, activity)
|
||||
no_links ? generate_name(value) : generate_link(value, activity)
|
||||
end
|
||||
end
|
||||
I18n.t("global_activities.content.#{activity.type_of}_html",
|
||||
parameters.symbolize_keys)
|
||||
sanitize_input(I18n.t("global_activities.content.#{activity.type_of}_html",
|
||||
parameters.symbolize_keys))
|
||||
end
|
||||
|
||||
def generate_link(message_item, activity)
|
||||
type = message_item[:type]
|
||||
id = message_item[:id]
|
||||
getter = message_item[:getter]
|
||||
value = message_item[:value]
|
||||
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
||||
return message_item[:value] unless obj
|
||||
|
||||
obj = type.constantize.find_by_id id
|
||||
return value unless obj
|
||||
|
||||
current_value = obj.public_send(getter || 'name')
|
||||
current_value = generate_name(message_item)
|
||||
team = activity.team
|
||||
path = ''
|
||||
|
||||
|
@ -70,4 +65,10 @@ module GlobalActivitiesHelper
|
|||
end
|
||||
route_to_other_team(path, obj, current_value)
|
||||
end
|
||||
|
||||
def generate_name(message_item)
|
||||
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
||||
return message_item[:value] unless obj
|
||||
obj.public_send(message_item[:getter] || 'name')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -90,6 +90,6 @@ class Activity < ApplicationRecord
|
|||
end
|
||||
|
||||
def activity_version
|
||||
errors.add(:activity, 'wrong combination of associations') if (experiment || my_module) && subject
|
||||
errors.add(:activity, 'wrong combination of associations') if (experiment_id || my_module_id) && subject
|
||||
end
|
||||
end
|
||||
|
|
|
@ -76,4 +76,13 @@ class ActivitiesService
|
|||
|
||||
subjects.each { |_sub, children| children.uniq! }
|
||||
end
|
||||
|
||||
def self.my_module_activities(my_module)
|
||||
subjects_with_children = load_subjects_children(MyModule: [my_module.id])
|
||||
query = Activity.where(project: my_module.experiment.project)
|
||||
query.where(
|
||||
subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR '),
|
||||
*subjects_with_children.flatten
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<% provide(:head_title, t("my_modules.repository.head_title",
|
||||
project: h(@project.name),
|
||||
module: h(@my_module.name),
|
||||
repository: @repository.name).html_safe) %>
|
||||
repository: h(@repository.name)).html_safe) %>
|
||||
<%= render partial: "shared/sidebar", locals: { current_task: @my_module, page: 'task' } %>
|
||||
<%= render partial: "shared/secondary_navigation" %>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
|
||||
<% if order.blank? and @order.present? then order = @order end %>
|
||||
<% timestamp = Time.current + 1.year - 2.days %>
|
||||
<% activities = my_module.activities.order(created_at: order) %>
|
||||
<% activities = ActivitiesService.my_module_activities(my_module).order(created_at: order) %>
|
||||
<div class="report-element report-module-activity-element" data-ts="<%= timestamp.to_i %>" data-type="my_module_activity" data-id='{ "my_module_id": <%= my_module.id %> }' data-scroll-id="<%= my_module.id %>" data-order="<%= order == :asc ? "asc" : "desc" %>" data-name="<%=t "projects.reports.elements.module_activity.sidebar_name" %>" data-icon-class="fas fa-list">
|
||||
<div class="report-element-header">
|
||||
<div class="row">
|
||||
|
@ -30,7 +30,11 @@
|
|||
</span>
|
||||
<span class="activity-message">
|
||||
|
||||
<%= sanitize_input(activity.message) %>
|
||||
<% if activity.old_activity? %>
|
||||
<%= sanitize_input(activity.message) %>
|
||||
<% else %>
|
||||
<%= sanitize_input(generate_activity_content(activity, true)) %>
|
||||
<% end %>
|
||||
</span>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue