Check index filters
Some checks failed
/ Run tests (push) Successful in 2m24s
/ Run system tests (push) Has been cancelled
/ Build, push and deploy image (push) Has been cancelled

This commit is contained in:
david 2024-09-12 00:50:38 +02:00
parent 338447763f
commit bf52112e5c
6 changed files with 58 additions and 25 deletions

View file

@ -52,12 +52,35 @@ class Check < ApplicationRecord
:standard_text,
:powerpoint_text
after_create { update(number: id) }
after_create { update(number: id) unless number }
scope(:search, lambda do |term|
scope(:search, lambda { |term|
# TODO: Search only fields for current locale.
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where("checks.name_de LIKE :term OR checks.name_de LIKE :term OR action_text_rich_texts.body LIKE :term", term: "%#{term}%").distinct
end)
joined = joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'")
if term.to_i > 0
joined.where("checks.name_de LIKE :term OR checks.name_de LIKE :term OR checks.number = :number OR action_text_rich_texts.body LIKE :term", term: "%#{term}%", number: term.to_i).distinct
else
joined.where("checks.name_de LIKE :term OR checks.name_de LIKE :term OR action_text_rich_texts.body LIKE :term", term: "%#{term}%").distinct
end
})
scope(:filter_by, lambda { |filter|
relation = where(nil)
filter.slice(:s, :principle_id, :priorities, :standard_ids, :conformity_level).each do |key, value|
next unless value.present?
case key
when "s"
relation = relation.search(value)
when "standard_ids"
relation = relation.joins(:standards).where(standards: { id: value })
else
relation = relation.where(key => value)
end
end
relation
})
def self.ransackable_attributes(auth_object = nil)
[ "applicable_to_app", "applicable_to_web", "auditory", "cognitive", "conformity_level", "created_at", "external_number", "external_url", "id", "level", "manual_test", "name", "name_de", "name_en", "number", "physical", "position", "principle_id", "priority", "test_url", "updated_at", "visual" ]