mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-25 01:04:02 +08:00
Fix advanced filters for list and status data types [SCI-6524][SCI-6521] (#3844)
This commit is contained in:
parent
97898fef7a
commit
6cc102cfd1
4 changed files with 35 additions and 11 deletions
|
@ -47,7 +47,7 @@
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value() {
|
value() {
|
||||||
this.parameters = { status_ids: this.value };
|
this.parameters = { item_ids: this.value };
|
||||||
this.updateFilter();
|
this.updateFilter();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,12 +28,24 @@ class RepositoryListValue < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_filter_condition(repository_rows, join_alias, filter_element)
|
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(
|
.joins(
|
||||||
"INNER JOIN \"repository_list_items\"" \
|
"LEFT OUTER JOIN \"repository_list_items\" AS \"#{items_join_alias}\" " \
|
||||||
" ON \"repository_list_items\".\"id\" = \"#{join_alias}\".\"repository_list_item_id\""
|
"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
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
|
|
|
@ -21,8 +21,8 @@ class RepositoryStatusItem < ApplicationRecord
|
||||||
|
|
||||||
def update_table_fiter_elements
|
def update_table_fiter_elements
|
||||||
repository_column.repository_table_filter_elements.find_each do |filter_element|
|
repository_column.repository_table_filter_elements.find_each do |filter_element|
|
||||||
filter_element.parameters['status_ids']&.delete(id.to_s)
|
filter_element.parameters['item_ids']&.delete(id.to_s)
|
||||||
filter_element.parameters['status_ids'].blank? ? filter_element.destroy! : filter_element.save!
|
filter_element.parameters['item_ids'].blank? ? filter_element.destroy! : filter_element.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,12 +20,24 @@ class RepositoryStatusValue < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_filter_condition(repository_rows, join_alias, filter_element)
|
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(
|
.joins(
|
||||||
"INNER JOIN \"repository_status_items\"" \
|
"LEFT OUTER JOIN \"repository_status_items\" AS \"#{items_join_alias}\" " \
|
||||||
" ON \"repository_status_items\".\"id\" = \"#{join_alias}\".\"repository_status_item_id\""
|
"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
|
end
|
||||||
|
|
||||||
def data_changed?(new_data)
|
def data_changed?(new_data)
|
||||||
|
|
Loading…
Reference in a new issue