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

@ -5,11 +5,7 @@ class ChecksController < ApplicationController
# GET /checks or /checks.json
def index
@pagy, @checks = if filter_params[:s]
pagy(Check.search(filter_params[:s]).order(:conformity_level))
else
pagy(Check.all.order(:conformity_level))
end
@pagy, @checks = pagy(Check.filter_by(filter_params).order(:conformity_level))
end
# GET /checks/1 or /checks/1.json
@ -71,7 +67,7 @@ class ChecksController < ApplicationController
end
def filter_params
@filter_params ||= params.permit(filter: %i[s level])[:filter] || {}
@filter_params ||= params.permit(filter: [ :s, priority: [], conformity_level: [], standard_ids: [], principle_id: [] ])[:filter] || {}
end
private

View file

@ -7,7 +7,6 @@ module LinkChecker
def http(input)
response = Net::HTTP.get_response(URI.parse(input), { 'User-Agent': UA })
# debugger
case response
when Net::HTTPSuccess
response.uri

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" ]

View file

@ -11,14 +11,35 @@ h1
= f.check_box :principle_id_in, checked: @q[:principle_id_in].include?(principle.id), label: principle.name_de, id: "principle_id_in_#{principle.id}"
= f.submit
= bootstrap_form_with(url: checks_path(page: params[:page]), method: :get, scope: :filter) do |form|
= form.hidden_field :page, value: params[:page] if params[:page]
.row
.col-md-3
= form.text_field(:s, placeholder: "suchen...", hide_label: true, value: filter_params[:s])
.col
= form.submit name: "", value: "Suchen"
= link_to "Filter löschen", checks_path, class: "btn btn-outline-secondary ms-3" if filter_params[:s]
.card.mb-3
.card-header.d-flex data-bs-toggle="collapse" href="#filter-form" role="button" aria-expanded="#{filter_params.present?}" aria-controler="filter-form"
' Filter
.card-body.collapse id="filter-form" class="#{"show" if filter_params.present?}"
= bootstrap_form_with(url: checks_path, method: :get, scope: :filter) do |form|
= form.hidden_field :page, value: params[:page] if params[:page]
.row
.col-lg-5
= form.text_field(:s, placeholder: "suchen...", hide_label: true, value: filter_params[:s])
.col-lg-2
- Principle.all.sort_by(&:name_de).each do |principle|
.form-check.form-check-inline
= form.check_box :principle_id, { label: principle.t_name, multiple: true, checked: (filter_params[:principle_id] || []).include?(principle.id.to_s) }, principle.id, nil
.col-lg-2
- Standard.all.sort_by(&:name_de).each do |standard|
.form-check.form-check-inline
= form.check_box :standard_ids, { label: standard.t_name, multiple: true, checked: (filter_params[:standard_ids] || []).include?(standard.id.to_s) }, standard.id, nil
.col-lg-1
- Check.conformity_levels.each do |conformity_level, value|
.form-check.form-check-inline
= form.check_box :conformity_level, { label: conformity_level, multiple: true, checked: (filter_params[:conformity_level] || []).include?(value.to_s) }, value, nil
.col-lg-2
- Check.priorities.each do |priority, value|
.form-check.form-check-inline
= form.check_box :priority, { label: t("priority.#{priority}"), multiple: true, checked: (filter_params[:priority] || []).include?(value.to_s) }, value, nil
.row
.col
= form.submit name: "", value: "Filtern"
= link_to "Filter löschen", checks_path, class: "btn btn-outline-secondary ms-3", data: { turbo_prefetch: false } if filter_params.keys.any?
table.table.table-striped
thead
tr