Sha256: 94b8f7212dbe2bef4f02ded7412443166142144626eb6a91c0d62f24cf0c30f4

Contents?: true

Size: 1.38 KB

Versions: 44

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

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

        included do
          include Decidim::Admin::Filterable

          private

          def base_query
            query = Decidim::Votings::Admin::PollingOfficersJoinPollingStationsAndUser.for(collection)

            filter_by_role(query)
          end

          def search_field_predicate
            :name_or_email_or_nickname_or_presided_station_title_or_managed_station_title_cont
          end

          def filters
            [
              :role_eq
            ]
          end

          def filters_with_values
            {
              role_eq: roles
            }
          end

          def roles
            [:president, :manager, :unassigned]
          end

          def filter_by_role(query)
            case ransack_params[:role_eq]
            when :president.to_s
              query.where(Arel.sql("presided_station.id IS NOT NULL"))
            when :manager.to_s
              query.where(Arel.sql("managed_station.id IS NOT NULL"))
            when :unassigned.to_s
              query.where(Arel.sql("presided_station.id IS NULL")).where(Arel.sql("managed_station.id IS NULL"))
            else
              query
            end
          end
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.9 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.3 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.8 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.2 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.7 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.1 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.6 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.26.10 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.26.9 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.0 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.5 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.0.rc5 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.28.0.rc4 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.26.8 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.4 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.3 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.26.7 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.26.5 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb
decidim-elections-0.27.2 app/controllers/concerns/decidim/polling_officers/admin/filterable.rb