Class: Decidim::DecidimAwesome::ContentBlocks::AwesomeProcessGroupsCell

Inherits:
ContentBlocks::BaseCell
  • Object
show all
Includes:
CardHelper, CellsPaginateHelper
Defined in:
app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb

Instance Method Summary collapse

Instance Method Details

#block_idObject



29
30
31
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 29

def block_id
  "awesome-process-groups-#{model.id}"
end

#count_for(filter) ⇒ Object

Counts always reflect the full group (not affected by taxonomy selection).



74
75
76
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 74

def count_for(filter)
  query.status_counts[filter] || 0
end

#current_pageObject



49
50
51
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 49

def current_page
  @current_page ||= [params[:page].to_i, 1].max
end

#current_statusObject



41
42
43
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 41

def current_status
  @current_status ||= params[:status].in?(%w(active past upcoming)) ? params[:status] : "all"
end

#dataObject



33
34
35
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 33

def data
  { "process-groups-filter": "" }
end

#filter_url(overrides = {}) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 57

def filter_url(overrides = {})
  status = overrides.fetch(:status, current_status)
  url_params = {}
  url_params[:status] = status unless status == "all"
  url_params[:taxonomy_ids] = selected_taxonomy_ids if selected_taxonomy_ids.any?
  url_params.merge!(overrides.except(:status))
  participatory_process_group_path(resource, **url_params)
end

#i18n_scopeObject



21
22
23
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 21

def i18n_scope
  "decidim.decidim_awesome.content_blocks.awesome_process_groups"
end

#max_countObject



25
26
27
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 25

def max_count
  [model.settings&.max_count.to_i, 1].max
end

#paginated_itemsObject



66
67
68
69
70
71
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 66

def paginated_items
  @paginated_items ||= query.filtered_relation(
    status: current_status,
    taxonomy_ids: selected_taxonomy_ids
  ).page(current_page).per(max_count)
end

#selected_taxonomy_idsObject



45
46
47
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 45

def selected_taxonomy_ids
  @selected_taxonomy_ids ||= Array(params[:taxonomy_ids]).map(&:to_i).reject(&:zero?).uniq
end

#selected_taxonomy_tagsObject



86
87
88
89
90
91
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 86

def selected_taxonomy_tags
  @selected_taxonomy_tags ||= begin
    all_items = taxonomy_filter_groups.flat_map { |group| group[:items] }
    selected_taxonomy_ids.filter_map { |taxonomy_id| all_items.find { |item| item[:id] == taxonomy_id } }
  end
end

#showObject



11
12
13
14
15
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 11

def show
  return unless resource

  render if query.base_relation.exists?
end

#status_filtersObject



37
38
39
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 37

def status_filters
  %w(active past upcoming all)
end

#taxonomy_filter_groupsObject



78
79
80
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 78

def taxonomy_filter_groups
  @taxonomy_filter_groups ||= build_taxonomy_filter_groups
end

#taxonomy_filters_available?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 82

def taxonomy_filters_available?
  taxonomy_filter_groups.any?
end

#taxonomy_selected?(id) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 53

def taxonomy_selected?(id)
  selected_taxonomy_ids.include?(id)
end

#titleObject



17
18
19
# File 'app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb', line 17

def title
  translated_attribute(model.settings.title).presence || t("default_title", scope: i18n_scope)
end