Merge pull request #2745 from aignatov-bio/ai-sci-4785-fix-inventories-activity-filters

Fix global activities filters [SCI-4785]
This commit is contained in:
Alex Kriuchykhin 2020-07-23 10:09:36 +02:00 committed by GitHub
commit cb9fe04584
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 6 deletions

View file

@ -57,7 +57,7 @@ var globalActivities = (function() {
Project: convertToInt(dropdownSelector.getValues(projectFilter) || []), Project: convertToInt(dropdownSelector.getValues(projectFilter) || []),
Experiment: convertToInt(dropdownSelector.getValues(experimentFilter) || []), Experiment: convertToInt(dropdownSelector.getValues(experimentFilter) || []),
MyModule: convertToInt(dropdownSelector.getValues(taskFilter) || []), MyModule: convertToInt(dropdownSelector.getValues(taskFilter) || []),
Repository: convertToInt(dropdownSelector.getValues(inventoryFilter) || []), RepositoryBase: convertToInt(dropdownSelector.getValues(inventoryFilter) || []),
RepositoryRow: convertToInt(dropdownSelector.getValues(inventoryItemFilter) || []), RepositoryRow: convertToInt(dropdownSelector.getValues(inventoryItemFilter) || []),
Protocol: convertToInt(dropdownSelector.getValues(protocolFilter) || []), Protocol: convertToInt(dropdownSelector.getValues(protocolFilter) || []),
Report: convertToInt(dropdownSelector.getValues(reportFilter) || []) Report: convertToInt(dropdownSelector.getValues(reportFilter) || [])

View file

@ -132,7 +132,7 @@ class GlobalActivitiesController < ApplicationController
selected_subject = subject_search_params[:subjects] selected_subject = subject_search_params[:subjects]
matched = matched.where(project_id: selected_subject['Project']) if subject == Experiment matched = matched.where(project_id: selected_subject['Project']) if subject == Experiment
matched = matched.where(experiment_id: selected_subject['Experiment']) if subject == MyModule matched = matched.where(experiment_id: selected_subject['Experiment']) if subject == MyModule
matched = matched.where(repository_id: selected_subject['Repository']) if subject == RepositoryRow matched = matched.where(repository_id: selected_subject['RepositoryBase']) if subject == RepositoryRow
matched = matched.limit(Constants::SEARCH_LIMIT).pluck(:id, :name) matched = matched.limit(Constants::SEARCH_LIMIT).pluck(:id, :name)
matched.map { |pr| { value: pr[0], label: escape_input(pr[1]) } } matched.map { |pr| { value: pr[0], label: escape_input(pr[1]) } }

View file

@ -14,9 +14,9 @@ class ActivitiesService
if filters[:subjects].present? if filters[:subjects].present?
subjects_with_children = load_subjects_children(filters[:subjects]) subjects_with_children = load_subjects_children(filters[:subjects])
if subjects_with_children[:project] if subjects_with_children['Project']
query = query.where('project_id IN (?)', subjects_with_children[:project]) query = query.where('project_id IN (?)', subjects_with_children['Project'])
subjects_with_children.except!(:project) subjects_with_children.except!('Project')
end end
where_condition = subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR ') where_condition = subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR ')
where_arguments = subjects_with_children.flatten where_arguments = subjects_with_children.flatten
@ -50,10 +50,11 @@ class ActivitiesService
def self.load_subjects_children(subjects = {}) def self.load_subjects_children(subjects = {})
Extends::ACTIVITY_SUBJECT_CHILDREN.each do |subject_name, children| Extends::ACTIVITY_SUBJECT_CHILDREN.each do |subject_name, children|
subject_name = subject_name.to_s.camelize
next unless children && subjects[subject_name] next unless children && subjects[subject_name]
children.each do |child| children.each do |child|
parent_model = subject_name.to_s.camelize.constantize parent_model = subject_name.constantize
child_model = parent_model.reflect_on_association(child).class_name.to_sym child_model = parent_model.reflect_on_association(child).class_name.to_sym
next if subjects[child_model] next if subjects[child_model]