Skip to content

Commit

Permalink
fix wrong ransack predicates after upgrading activeadmin and custom p…
Browse files Browse the repository at this point in the history
…redicates were removed
  • Loading branch information
tsubik committed Jan 3, 2024
1 parent a47461f commit 43718fa
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 24 deletions.
4 changes: 0 additions & 4 deletions app/admin/about_page_entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
permit_params :position, :code, translations_attributes: [:id, :locale, :title, :body, :_destroy]

filter :position, as: :select
filter :translations_title_contains, as: :select, label: -> { I18n.t("activerecord.attributes.about_page_entry.title") },
collection: -> { AboutPageEntry.with_translations(I18n.locale).pluck(:title) }
filter :translations_body_contains, as: :select, label: -> { I18n.t("activerecord.attributes.about_page_entry.body") },
collection: -> { AboutPageEntry.with_translations(I18n.locale).pluck(:body) }

controller do
def scoped_collection
Expand Down
2 changes: 1 addition & 1 deletion app/admin/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def scoped_collection
scope -> { I18n.t("active_admin.shared.active") }, :active

filter :iso, as: :select
filter :translations_name_contains, as: :select,
filter :translations_name_cont, as: :select,
label: -> { I18n.t("activerecord.attributes.country.name") },
collection: -> { Country.order(:name).pluck(:name) }
filter :region_iso, as: :select
Expand Down
2 changes: 0 additions & 2 deletions app/admin/donor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def scoped_collection

permit_params :website, :logo, :priority, :category, translations_attributes: [:id, :locale, :name, :description]

filter :translations_name_contains, as: :select, label: -> { I18n.t("activerecord.attributes.donor.name") },
collection: -> { Donor.with_translations(I18n.locale).pluck(:name) }
filter :website, as: :select

csv do
Expand Down
4 changes: 0 additions & 4 deletions app/admin/faq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
permit_params :position, translations_attributes: [:id, :locale, :question, :answer, :_destroy]

filter :position, as: :select
filter :translations_question_contains, as: :select, label: proc { I18n.t("activerecord.attributes.faq.question") },
collection: -> { Faq.with_translations(I18n.locale).pluck(:question) }
filter :translations_answer_contains, as: :select, label: proc { I18n.t("activerecord.attributes.faq.answer") },
collection: -> { Faq.with_translations(I18n.locale).pluck(:answer) }

controller do
def scoped_collection
Expand Down
4 changes: 2 additions & 2 deletions app/admin/fmu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def scoped_collection
filter :id, as: :select
filter :country, as: :select, label: proc { I18n.t("activerecord.models.country.one") }, collection: -> { Country.joins(:fmus).by_name_asc }
filter :operator_in_all, as: :select, label: proc { I18n.t("activerecord.attributes.fmu.operator") }, collection: -> { Operator.order(:name) }
filter :translations_name_contains,
filter :translations_name_cont,
as: :select, label: proc { I18n.t("activerecord.attributes.fmu/translation.name") },
collection: -> { Fmu.by_name_asc.pluck(:name) }

Expand All @@ -38,7 +38,7 @@ def scoped_collection
operator_in_all: Operator.pluck(:country_id, :id)
},
operator_in_all: {
translations_name_contains: Operator.joins(fmus: :translations).where(fmu_translations: {locale: I18n.locale}).pluck(:id, "fmu_translations.name")
translations_name_cont: Operator.joins(fmus: :translations).where(fmu_translations: {locale: I18n.locale}).pluck(:id, "fmu_translations.name")
}
}
end
Expand Down
4 changes: 2 additions & 2 deletions app/admin/government.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def scoped_collection
end

filter :country, as: :select, collection: -> { Country.joins(:governments).by_name_asc }
filter :translations_government_entity_contains,
filter :translations_government_entity_cont,
as: :select, label: -> { I18n.t("activerecord.attributes.government/translation.government_entity") },
collection: -> { Government.by_entity_asc.distinct.pluck(:government_entity) }

dependent_filters do
{
country_id: {
translations_government_entity_contains: Government.distinct.pluck(:country_id, :government_entity)
translations_government_entity_cont: Government.distinct.pluck(:country_id, :government_entity)
}
}
end
Expand Down
10 changes: 5 additions & 5 deletions app/admin/operator_document_annex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ def scoped_collection
actions
end

filter :annex_documents_documentable_of_OperatorDocument_type_required_operator_document_name_equals,
filter :annex_documents_documentable_of_OperatorDocument_type_required_operator_document_name_eq,
as: :select,
label: proc { I18n.t("active_admin.operator_document_annexes_page.operator_document") },
collection: -> { RequiredOperatorDocument.order(:name).pluck(:name) }

filter :annex_documents_documentable_of_OperatorDocument_type_operator_name_equals,
filter :annex_documents_documentable_of_OperatorDocument_type_operator_name_eq,
as: :select,
label: proc { I18n.t("activerecord.models.operator") },
collection: -> { Operator.order(:name).pluck(:name) }
filter :annex_documents_documentable_of_OperatorDocument_type_fmu_translations_name_equals,
filter :annex_documents_documentable_of_OperatorDocument_type_fmu_translations_name_eq,
as: :select,
label: -> { I18n.t("activerecord.models.fmu.one") },
collection: -> { Fmu.by_name_asc.pluck(:name) }
Expand All @@ -133,8 +133,8 @@ def scoped_collection

dependent_filters do
{
annex_documents_documentable_of_OperatorDocument_type_operator_name_equals: {
annex_documents_documentable_of_OperatorDocument_type_fmu_translations_name_equals:
annex_documents_documentable_of_OperatorDocument_type_operator_name_eq: {
annex_documents_documentable_of_OperatorDocument_type_fmu_translations_name_eq:
Operator.joins(fmus: :translations).where(fmu_translations: {locale: I18n.locale}).pluck(:name, "fmu_translations.name")
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/admin/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def scoped_collection

permit_params :website, :logo, :priority, :category, translations_attributes: [:id, :locale, :name, :description]

filter :translations_name_contains, as: :select, label: proc { I18n.t("activerecord.attributes.partner.name") },
filter :translations_name_cont, as: :select, label: proc { I18n.t("activerecord.attributes.partner.name") },
collection: -> { Partner.with_translations(I18n.locale).pluck(:name) }
filter :website, as: :select

Expand Down
2 changes: 1 addition & 1 deletion app/admin/required_gov_document_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
actions
end

filter :translations_name_contains,
filter :translations_name_cont,
as: :select,
label: -> { I18n.t("activerecord.attributes.required_gov_document_group/translation.name") },
collection: -> {
Expand Down
2 changes: 1 addition & 1 deletion app/admin/required_operator_document_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
actions
end

filter :translations_name_contains,
filter :translations_name_cont,
label: proc { I18n.t("activerecord.attributes.required_operator_document_group.name") },
as: :select,
collection: -> {
Expand Down
2 changes: 1 addition & 1 deletion app/admin/severity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def scoped_collection

permit_params :subcategory_id, :level, translations_attributes: [:id, :locale, :details, :_destroy]

filter :translations_details_contains, label: -> { I18n.t("activerecord.attributes.severity.details") }
filter :translations_details_cont, label: -> { I18n.t("activerecord.attributes.severity.details") }
filter :subcategory, as: :select,
collection: -> { Subcategory.with_translations(I18n.locale).order("subcategory_translations.name") }
filter :level, as: :select, collection: 0..3
Expand Down

0 comments on commit 43718fa

Please sign in to comment.