Sha256: e3d0b20b285432dc4cf68f51016cd9dbdfbdc54182b207456fd0719894050880

Contents?: true

Size: 1.4 KB

Versions: 46

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Initiatives
    module Admin
      module Filterable
        extend ActiveSupport::Concern

        included do
          include Decidim::Admin::Filterable

          private

          def base_query
            collection.joins(:scoped_type).left_joins(:area).joins("JOIN decidim_users ON decidim_users.id = decidim_initiatives.decidim_author_id")
          end

          def search_field_predicate
            :title_or_description_or_id_string_or_author_name_or_author_nickname_cont
          end

          def filters
            [:state_eq, :type_id_eq, :decidim_area_id_eq]
          end

          def filters_with_values
            {
              state_eq: Initiative.states.keys,
              type_id_eq: InitiativesType.where(organization: current_organization).pluck(:id),
              decidim_area_id_eq: current_organization.areas.pluck(:id)
            }
          end

          def dynamically_translated_filters
            [:type_id_eq, :decidim_area_id_eq]
          end

          def translated_type_id_eq(id)
            translated_attribute(Decidim::InitiativesType.find_by(id: id).title[I18n.locale.to_s])
          end

          def translated_decidim_area_id_eq(id)
            translated_attribute(Decidim::Area.find_by(id: id).name[I18n.locale.to_s])
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.9 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.8 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.7 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.6 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.10 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.9 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.5 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.8 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.4 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.3 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.7 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.5 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.2 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.1 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.4 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.0 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.3 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.0.rc2 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.27.0.rc1 app/controllers/concerns/decidim/initiatives/admin/filterable.rb
decidim-initiatives-0.26.2 app/controllers/concerns/decidim/initiatives/admin/filterable.rb