Sha256: 89c76ef2f1e397d2e23af26fbb512fde33bf3a25f576823e35dadc44866332ab

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell is used to generate a filter of activities types
  # Model is expected to be a list of types
  class ResourceTypesFilterCell < Decidim::ViewModel
    ALL_TYPES_KEY = "all"

    include ActionView::Helpers::FormOptionsHelper
    include Decidim::FiltersHelper

    private

    def resource_types
      return @resource_types if defined?(@resource_types)

      @resource_types = model.map do |klass_name|
        next if (klass = klass_name.safe_constantize).blank?

        [klass_name, klass.model_name.human]
      end.compact.sort_by(&:last)

      @resource_types.unshift(all_resource_types_option)
    end

    def id
      options[:id] || "filters"
    end

    def form_path
      options[:form_path]
    end

    def filter_param_key
      @filter_param_key ||= options[:filter_param_key] || :resource_type
    end

    def filter_param
      @filter_param ||= params.dig(:filter, filter_param_key) || all_types_key
    end

    def filter
      options[:filter]
    end

    def all_resource_types_option
      [all_types_key, I18n.t("all", scope: "decidim.last_activities")]
    end

    def all_types_key
      ALL_TYPES_KEY
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/cells/decidim/resource_types_filter_cell.rb
decidim-core-0.29.0 app/cells/decidim/resource_types_filter_cell.rb
decidim-core-0.29.0.rc4 app/cells/decidim/resource_types_filter_cell.rb
decidim-core-0.29.0.rc3 app/cells/decidim/resource_types_filter_cell.rb
decidim-core-0.29.0.rc2 app/cells/decidim/resource_types_filter_cell.rb
decidim-core-0.29.0.rc1 app/cells/decidim/resource_types_filter_cell.rb