mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-02 02:10:34 +08:00
Adding children selector to global activities subjects [SCI-3247] (#1605)
* Adding children selector to global activities subjects * Fix naming, add seperate check for project id
This commit is contained in:
parent
ba4b35d004
commit
b51dcc9d75
5 changed files with 45 additions and 11 deletions
app
assets/javascripts/global_activities
controllers
services
config/initializers
|
@ -1,4 +1,4 @@
|
|||
/* global animateSpinner */
|
||||
/* global animateSpinner I18n */
|
||||
|
||||
// Common code
|
||||
|
||||
|
@ -79,7 +79,10 @@ $(function() {
|
|||
label: key
|
||||
};
|
||||
});
|
||||
result.push({ text: key, children: updateItems });
|
||||
result.push({
|
||||
text: I18n.t('global_activities.subject_name.' + key.toLowerCase()),
|
||||
children: updateItems
|
||||
});
|
||||
});
|
||||
return {
|
||||
results: result
|
||||
|
@ -142,7 +145,7 @@ $(function() {
|
|||
} else {
|
||||
moreButton.addClass('hidden');
|
||||
}
|
||||
if (json.activities_html === "") {
|
||||
if (json.activities_html === '') {
|
||||
noActivitiesMessage.removeClass('hidden');
|
||||
} else {
|
||||
noActivitiesMessage.addClass('hidden');
|
||||
|
|
|
@ -57,8 +57,7 @@ class GlobalActivitiesController < ApplicationController
|
|||
.pluck(:id, :name)
|
||||
next if matched.length.zero?
|
||||
|
||||
subject_name = t("global_activities.subject_name.#{subject.to_s.downcase}")
|
||||
results[subject_name] = matched.map { |pr| { id: pr[0], name: pr[1] } }
|
||||
results[subject] = matched.map { |pr| { id: pr[0], name: pr[1] } }
|
||||
end
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
|
|
|
@ -77,9 +77,7 @@ class MyModulesController < ApplicationController
|
|||
|
||||
def activities
|
||||
params[:subjects] = {
|
||||
MyModule: [@my_module.id],
|
||||
Result: @my_module.results.pluck(:id),
|
||||
Protocol: @my_module.protocols.pluck(:id)
|
||||
MyModule: [@my_module.id]
|
||||
}
|
||||
@activity_types = Activity.activity_types_list
|
||||
@user_list = User.where(id: UserTeam.where(team: current_user.teams).select(:user_id))
|
||||
|
|
|
@ -8,10 +8,15 @@ class ActivitiesService
|
|||
query = Activity.where(project: visible_projects)
|
||||
.or(Activity.where(project: nil, team: visible_teams))
|
||||
if filters[:subjects].present?
|
||||
subjects_with_children = load_subjects_children(filters[:subjects])
|
||||
if subjects_with_children[:Project]
|
||||
add_or = subjects_with_children.length > 1
|
||||
query = query.where("project_id IN (?) #{add_or ? 'OR' : ''}", subjects_with_children[:Project])
|
||||
subjects_with_children.except!(:Project)
|
||||
end
|
||||
query = query.where(
|
||||
filters[:subjects]
|
||||
.to_h.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR '),
|
||||
*filters[:subjects].to_h.flatten
|
||||
subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR '),
|
||||
*subjects_with_children.flatten
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -53,4 +58,22 @@ class ActivitiesService
|
|||
results[last_date] = activities.to_a
|
||||
[results, more_left]
|
||||
end
|
||||
|
||||
def self.load_subjects_children(subjects = {})
|
||||
subject_types = Extends::ACTIVITY_SUBJECT_CHILDREN
|
||||
subject_types.each do |subject_name, children|
|
||||
next unless children && subjects[subject_name]
|
||||
|
||||
children.each do |child|
|
||||
parent_model = subject_name.to_s.constantize
|
||||
child_model = parent_model.reflect_on_association(child).class_name.to_sym
|
||||
child_id = parent_model.where(id: subjects[subject_name])
|
||||
.joins(child)
|
||||
.pluck("#{child}.id")
|
||||
subjects[child_model] = (subjects[child_model] ||= []) + child_id
|
||||
end
|
||||
end
|
||||
|
||||
subjects.each { |_sub, children| children.uniq! }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -92,6 +92,17 @@ class Extends
|
|||
Repository Project Experiment MyModule Result Protocol Step Report
|
||||
).freeze
|
||||
|
||||
ACTIVITY_SUBJECT_CHILDREN = {
|
||||
Repository: nil,
|
||||
Report: nil,
|
||||
Project: nil,
|
||||
Experiment: [:my_modules],
|
||||
MyModule: [:results,:protocols],
|
||||
Result: nil,
|
||||
Protocol: [:steps],
|
||||
Step: nil
|
||||
}.freeze
|
||||
|
||||
ACTIVITY_MESSAGE_ITEMS_TYPES =
|
||||
ACTIVITY_SUBJECT_TYPES + %w(User Tag RepositoryColumn RepositoryRow Step)
|
||||
.freeze
|
||||
|
|
Loading…
Add table
Reference in a new issue