mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +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 ActionView::Helpers::UrlHelper
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
|
|
||||||
def generate_activity_content(activity)
|
def generate_activity_content(activity, no_links = false)
|
||||||
parameters = {}
|
parameters = {}
|
||||||
activity.values[:message_items].each do |key, value|
|
activity.values[:message_items].each do |key, value|
|
||||||
parameters[key] =
|
parameters[key] =
|
||||||
if value.is_a? String
|
if value.is_a? String
|
||||||
value
|
value
|
||||||
else
|
else
|
||||||
generate_link(value, activity)
|
no_links ? generate_name(value) : generate_link(value, activity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
I18n.t("global_activities.content.#{activity.type_of}_html",
|
sanitize_input(I18n.t("global_activities.content.#{activity.type_of}_html",
|
||||||
parameters.symbolize_keys)
|
parameters.symbolize_keys))
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_link(message_item, activity)
|
def generate_link(message_item, activity)
|
||||||
type = message_item[:type]
|
obj = message_item[:type].constantize.find_by_id(message_item[:id])
|
||||||
id = message_item[:id]
|
return message_item[:value] unless obj
|
||||||
getter = message_item[:getter]
|
|
||||||
value = message_item[:value]
|
|
||||||
|
|
||||||
obj = type.constantize.find_by_id id
|
current_value = generate_name(message_item)
|
||||||
return value unless obj
|
|
||||||
|
|
||||||
current_value = obj.public_send(getter || 'name')
|
|
||||||
team = activity.team
|
team = activity.team
|
||||||
path = ''
|
path = ''
|
||||||
|
|
||||||
|
@ -70,4 +65,10 @@ module GlobalActivitiesHelper
|
||||||
end
|
end
|
||||||
route_to_other_team(path, obj, current_value)
|
route_to_other_team(path, obj, current_value)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -90,6 +90,6 @@ class Activity < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def activity_version
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,4 +76,13 @@ class ActivitiesService
|
||||||
|
|
||||||
subjects.each { |_sub, children| children.uniq! }
|
subjects.each { |_sub, children| children.uniq! }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<% provide(:head_title, t("my_modules.repository.head_title",
|
<% provide(:head_title, t("my_modules.repository.head_title",
|
||||||
project: h(@project.name),
|
project: h(@project.name),
|
||||||
module: h(@my_module.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/sidebar", locals: { current_task: @my_module, page: 'task' } %>
|
||||||
<%= render partial: "shared/secondary_navigation" %>
|
<%= render partial: "shared/secondary_navigation" %>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
|
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
|
||||||
<% if order.blank? and @order.present? then order = @order end %>
|
<% if order.blank? and @order.present? then order = @order end %>
|
||||||
<% timestamp = Time.current + 1.year - 2.days %>
|
<% 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 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="report-element-header">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -30,7 +30,11 @@
|
||||||
</span>
|
</span>
|
||||||
<span class="activity-message">
|
<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>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue