mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-01 13:13:22 +08:00
Fix advanced filtering for check list items [SCI-6522] (#3841)
This commit is contained in:
parent
ed8ba13525
commit
1e0966ac11
2 changed files with 26 additions and 8 deletions
|
@ -26,16 +26,34 @@ class RepositoryChecklistValue < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.add_filter_condition(repository_rows, join_alias, filter_element)
|
||||
repository_rows
|
||||
items_join_alias = "#{join_alias}_checklist_items"
|
||||
repository_rows =
|
||||
repository_rows
|
||||
.joins(
|
||||
"INNER JOIN \"repository_checklist_items_values\"" \
|
||||
" ON \"repository_checklist_items_values\".\"repository_checklist_value_id\" = \"#{join_alias}\".\"id\""
|
||||
"LEFT OUTER JOIN \"repository_checklist_items_values\" AS \"#{join_alias}_checklist_items_values\" " \
|
||||
"ON \"#{join_alias}_checklist_items_values\".\"repository_checklist_value_id\" = \"#{join_alias}\".\"id\""
|
||||
)
|
||||
.joins(
|
||||
'INNER JOIN "repository_checklist_items"' \
|
||||
' ON "repository_checklist_items_values"."repository_checklist_item_id" = "repository_checklist_items"."id"'
|
||||
"LEFT OUTER JOIN \"repository_checklist_items\" AS \"#{items_join_alias}\" " \
|
||||
"ON \"#{join_alias}_checklist_items_values\".\"repository_checklist_item_id\" = \"#{items_join_alias}\".\"id\""
|
||||
)
|
||||
.where(repository_checklist_items: { id: filter_element.parameters['item_ids'] })
|
||||
|
||||
case filter_element.operator
|
||||
when 'any_of'
|
||||
repository_rows
|
||||
.where("#{items_join_alias}.id = ANY(ARRAY[?]::bigint[])", filter_element.parameters['item_ids'])
|
||||
when 'all_of'
|
||||
repository_rows
|
||||
.having("ARRAY_AGG(#{items_join_alias}.id ORDER BY #{items_join_alias}.id) @> ARRAY[?]::bigint[]",
|
||||
filter_element.parameters['item_ids'].sort)
|
||||
.group(:id)
|
||||
when 'none_of'
|
||||
repository_rows
|
||||
.having("NOT ARRAY_AGG(#{items_join_alias}.id) && ARRAY[?]::bigint[]", filter_element.parameters['item_ids'])
|
||||
.group(:id)
|
||||
else
|
||||
raise ArgumentError, 'Wrong operator for RepositoryChecklistValue!'
|
||||
end
|
||||
end
|
||||
|
||||
def data
|
||||
|
|
|
@ -339,11 +339,11 @@ class RepositoryDatatableService
|
|||
repository_rows =
|
||||
repository_rows
|
||||
.joins(
|
||||
"INNER JOIN \"repository_cells\" AS \"#{join_cells_alias}\"" \
|
||||
"LEFT OUTER JOIN \"repository_cells\" AS \"#{join_cells_alias}\"" \
|
||||
" ON \"repository_rows\".\"id\" = \"#{join_cells_alias}\".\"repository_row_id\"" \
|
||||
" AND \"#{join_cells_alias}\".\"repository_column_id\" = '#{filter_element.repository_column.id}'")
|
||||
.joins(
|
||||
"INNER JOIN \"#{config[:table_name]}\" AS \"#{join_values_alias}\"" \
|
||||
"LEFT OUTER JOIN \"#{config[:table_name]}\" AS \"#{join_values_alias}\"" \
|
||||
" ON \"#{join_values_alias}\".\"id\" = \"#{join_cells_alias}\".\"value_id\""
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue