mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-11 23:54:43 +08:00
Improve parameter filtering in activities filters and smart annotations [SCI-9218] (#6129)
This commit is contained in:
parent
809461273e
commit
df290ad3b3
3 changed files with 33 additions and 22 deletions
|
@ -29,13 +29,18 @@ class AtWhoController < ApplicationController
|
|||
else
|
||||
Repository.active.accessible_by_teams(@team).first
|
||||
end
|
||||
if repository && can_read_repository?(repository)
|
||||
items = SmartAnnotation.new(current_user, current_team, @query)
|
||||
.repository_rows(repository, params[:assignable_my_module_id])
|
||||
repository_id = repository.id
|
||||
else
|
||||
|
||||
items = []
|
||||
repository_id = nil
|
||||
|
||||
if repository && can_read_repository?(repository)
|
||||
assignable_my_module =
|
||||
if params[:assignable_my_module_id].present?
|
||||
MyModule.viewable_by_user(current_user, @team).find_by(id: params[:assignable_my_module_id])
|
||||
end
|
||||
items = SmartAnnotation.new(current_user, current_team, @query)
|
||||
.repository_rows(repository, assignable_my_module&.id)
|
||||
repository_id = repository.id
|
||||
end
|
||||
render json: {
|
||||
res: [
|
||||
|
|
|
@ -43,34 +43,40 @@ module Activities
|
|||
|
||||
def filter_users!
|
||||
@activity_filters = @activity_filters.where(
|
||||
"NOT(filter ? 'users') OR filter -> 'users' @> '\"#{@activity.owner_id}\"'"
|
||||
"NOT(filter ? 'users') OR filter -> 'users' @> '\":owner_id\"'", owner_id: @activity.owner_id
|
||||
)
|
||||
end
|
||||
|
||||
def filter_types!
|
||||
@activity_filters = @activity_filters.where(
|
||||
"NOT(filter ? 'types') OR filter -> 'types' @> '\"#{@activity.type_of_before_type_cast}\"'"
|
||||
"NOT(filter ? 'types') OR filter -> 'types' @> '\":type_of\"'", type_of: @activity.type_of_before_type_cast
|
||||
)
|
||||
end
|
||||
|
||||
def filter_teams!
|
||||
@activity_filters = @activity_filters.where(
|
||||
"NOT(filter ? 'teams') OR filter -> 'teams' @> '\"#{@activity.team_id}\"'"
|
||||
"NOT(filter ? 'teams') OR filter -> 'teams' @> '\":team_id\"'", team_id: @activity.team_id
|
||||
)
|
||||
end
|
||||
|
||||
def filter_subjects!
|
||||
parents = activity_subject_parents
|
||||
filtered_by_subject = @activity_filters
|
||||
|
||||
@activity_filters = @activity_filters.where(
|
||||
"NOT(filter ? 'subjects') OR "\
|
||||
"filter -> 'subjects' -> 'Project' @> '\"#{@activity.project_id}\"' OR "\
|
||||
"filter -> 'subjects' -> '#{@activity.subject_type}' @> '\"#{@activity.subject_id}\"'" +
|
||||
(parents.any? ? ' OR ' : '') +
|
||||
parents.map do |subject|
|
||||
"filter -> 'subjects' -> '#{subject.class}' @> '\"#{subject.id}\"'"
|
||||
end.join(' OR ')
|
||||
)
|
||||
filtered_by_subject =
|
||||
@activity_filters
|
||||
.where("NOT(filter ? 'subjects')")
|
||||
.or(@activity_filters.where("filter -> 'subjects' -> 'Project' @> '\":subject_id\"'",
|
||||
subject_id: @activity.project_id))
|
||||
.or(@activity_filters.where("filter -> 'subjects' -> :subject_type @> '\":subject_id\"'",
|
||||
subject_type: @activity.subject_type, subject_id: @activity.subject_id))
|
||||
parents.each do |parent|
|
||||
filtered_by_subject =
|
||||
filtered_by_subject
|
||||
.or(@activity_filters.where("filter -> 'subjects' -> :subject_type @> '\":subject_id\"'",
|
||||
subject_type: parent.class, subject_id: parent.id))
|
||||
end
|
||||
@activity_filters = filtered_by_subject
|
||||
end
|
||||
|
||||
def activity_subject_parents
|
||||
|
|
|
@ -36,16 +36,16 @@ class SmartAnnotation
|
|||
end
|
||||
|
||||
def repository_rows(repository, my_module_id)
|
||||
res = RepositoryRow
|
||||
res = repository
|
||||
.repository_rows
|
||||
.active
|
||||
.where(repository: repository)
|
||||
.search_by_name_and_id(@current_user, @current_team, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
||||
|
||||
if my_module_id.present?
|
||||
res = res.joins('LEFT OUTER JOIN "my_module_repository_rows" "current_my_module_repository_rows" ' \
|
||||
'ON "current_my_module_repository_rows"."repository_row_id" = "repository_rows"."id" ' \
|
||||
'AND "current_my_module_repository_rows"."my_module_id" = ' + my_module_id.to_s)
|
||||
'AND "current_my_module_repository_rows"."my_module_id" = ' + Integer(my_module_id).to_s)
|
||||
.select('repository_rows.*',
|
||||
'CASE WHEN current_my_module_repository_rows.id IS NOT NULL ' \
|
||||
'THEN true ELSE false END as row_assigned')
|
||||
|
|
Loading…
Add table
Reference in a new issue