Fix advanced filters for list and status data types [SCI-6524][SCI-6521] (#3844)

This commit is contained in:
Alex Kriuchykhin 2022-02-11 13:50:42 +01:00 committed by GitHub
parent 97898fef7a
commit 6cc102cfd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 11 deletions

View file

@ -47,7 +47,7 @@
},
watch: {
value() {
this.parameters = { status_ids: this.value };
this.parameters = { item_ids: this.value };
this.updateFilter();
}
},

View file

@ -28,12 +28,24 @@ class RepositoryListValue < ApplicationRecord
end
def self.add_filter_condition(repository_rows, join_alias, filter_element)
repository_rows
items_join_alias = "#{join_alias}_status_items"
repository_rows =
repository_rows
.joins(
"INNER JOIN \"repository_list_items\"" \
" ON \"repository_list_items\".\"id\" = \"#{join_alias}\".\"repository_list_item_id\""
"LEFT OUTER JOIN \"repository_list_items\" AS \"#{items_join_alias}\" " \
"ON \"#{join_alias}\".\"repository_list_item_id\" = \"#{items_join_alias}\".\"id\""
)
.where(repository_list_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 'none_of'
repository_rows
.where("NOT #{items_join_alias}.id IN(?) OR #{items_join_alias}.id IS NULL",
filter_element.parameters['item_ids'])
else
raise ArgumentError, 'Wrong operator for RepositoryListValue!'
end
end
def data

View file

@ -21,8 +21,8 @@ class RepositoryStatusItem < ApplicationRecord
def update_table_fiter_elements
repository_column.repository_table_filter_elements.find_each do |filter_element|
filter_element.parameters['status_ids']&.delete(id.to_s)
filter_element.parameters['status_ids'].blank? ? filter_element.destroy! : filter_element.save!
filter_element.parameters['item_ids']&.delete(id.to_s)
filter_element.parameters['item_ids'].blank? ? filter_element.destroy! : filter_element.save!
end
end
end

View file

@ -20,12 +20,24 @@ class RepositoryStatusValue < ApplicationRecord
end
def self.add_filter_condition(repository_rows, join_alias, filter_element)
repository_rows
items_join_alias = "#{join_alias}_status_items"
repository_rows =
repository_rows
.joins(
"INNER JOIN \"repository_status_items\"" \
" ON \"repository_status_items\".\"id\" = \"#{join_alias}\".\"repository_status_item_id\""
"LEFT OUTER JOIN \"repository_status_items\" AS \"#{items_join_alias}\" " \
"ON \"#{join_alias}\".\"repository_status_item_id\" = \"#{items_join_alias}\".\"id\""
)
.where(repository_status_items: { id: filter_element.parameters['status_ids'] })
case filter_element.operator
when 'any_of'
repository_rows
.where("#{items_join_alias}.id = ANY(ARRAY[?]::bigint[])", filter_element.parameters['item_ids'])
when 'none_of'
repository_rows
.where("NOT #{items_join_alias}.id IN(?) OR #{items_join_alias}.id IS NULL",
filter_element.parameters['item_ids'])
else
raise ArgumentError, 'Wrong operator for RepositoryStatusValue!'
end
end
def data_changed?(new_data)