mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-26 16:53:12 +08:00
Fix global activities filters
This commit is contained in:
parent
6ad1c6ee3d
commit
75930b99c3
3 changed files with 7 additions and 6 deletions
|
@ -57,7 +57,7 @@ var globalActivities = (function() {
|
|||
Project: convertToInt(dropdownSelector.getValues(projectFilter) || []),
|
||||
Experiment: convertToInt(dropdownSelector.getValues(experimentFilter) || []),
|
||||
MyModule: convertToInt(dropdownSelector.getValues(taskFilter) || []),
|
||||
Repository: convertToInt(dropdownSelector.getValues(inventoryFilter) || []),
|
||||
RepositoryBase: convertToInt(dropdownSelector.getValues(inventoryFilter) || []),
|
||||
RepositoryRow: convertToInt(dropdownSelector.getValues(inventoryItemFilter) || []),
|
||||
Protocol: convertToInt(dropdownSelector.getValues(protocolFilter) || []),
|
||||
Report: convertToInt(dropdownSelector.getValues(reportFilter) || [])
|
||||
|
|
|
@ -132,7 +132,7 @@ class GlobalActivitiesController < ApplicationController
|
|||
selected_subject = subject_search_params[:subjects]
|
||||
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(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.map { |pr| { value: pr[0], label: escape_input(pr[1]) } }
|
||||
|
|
|
@ -14,9 +14,9 @@ class ActivitiesService
|
|||
|
||||
if filters[:subjects].present?
|
||||
subjects_with_children = load_subjects_children(filters[:subjects])
|
||||
if subjects_with_children[:project]
|
||||
query = query.where('project_id IN (?)', subjects_with_children[:project])
|
||||
subjects_with_children.except!(:project)
|
||||
if subjects_with_children['Project']
|
||||
query = query.where('project_id IN (?)', subjects_with_children['Project'])
|
||||
subjects_with_children.except!('Project')
|
||||
end
|
||||
where_condition = subjects_with_children.map { '(subject_type = ? AND subject_id IN(?))' }.join(' OR ')
|
||||
where_arguments = subjects_with_children.flatten
|
||||
|
@ -50,10 +50,11 @@ class ActivitiesService
|
|||
|
||||
def self.load_subjects_children(subjects = {})
|
||||
Extends::ACTIVITY_SUBJECT_CHILDREN.each do |subject_name, children|
|
||||
subject_name = subject_name.to_s.camelize
|
||||
next unless children && subjects[subject_name]
|
||||
|
||||
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
|
||||
next if subjects[child_model]
|
||||
|
||||
|
|
Loading…
Reference in a new issue