Sha256: f944771b742f68e4739a6e9e7806dd44fd7ed738a81f46dfc10f4ee3466a1786

Contents?: true

Size: 1.87 KB

Versions: 25

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    # This cell renders a set of filtered participatory processes from a base
    # relation provided by the model
    #
    # The `model` must be a relation of participatory processes
    #
    # Available options:
    #
    # - `default_date_filter` => The date filter to use if not given by
    #    params. If not provided is inferred from the model relation
    #
    # Example:
    #
    # cell(
    #   "decidim/participatory_processes/filtered_participatory_processes",
    #   group.participatory_processes.published,
    #   date_filter: "active"
    # )
    class FilteredParticipatoryProcessesCell < Decidim::ViewModel
      include Decidim::FilterResource
      include Decidim::CardHelper

      def elements
        @elements ||= search.results
      end

      private

      def search_klass
        Decidim::ParticipatoryProcesses::ParticipatoryProcessSearch
      end

      def default_search_params
        {
          base_relation: model,
          date: default_date_filter
        }
      end

      def default_date_filter
        @default_date_filter ||= options[:default_filter].presence || if model.any?(&:active?)
                                                                        "active"
                                                                      elsif model.any?(&:upcoming?)
                                                                        "upcoming"
                                                                      elsif model.any?(&:past?)
                                                                        "past"
                                                                      else
                                                                        "all"
                                                                      end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.26.10 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.9 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.8 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.7 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.5 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.4 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.3 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.2 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.1 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.0 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.0.rc2 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.26.0.rc1 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.2 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.1 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.0 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.0.rc4 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.0.rc3 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.0.rc2 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.25.0.rc1 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb
decidim-participatory_processes-0.24.3 app/cells/decidim/participatory_processes/filtered_participatory_processes_cell.rb