Class: Decidim::DecidimAwesome::ContentBlocks::AwesomeProcessGroupsCell
- Inherits:
-
ContentBlocks::BaseCell
- Object
- ContentBlocks::BaseCell
- Decidim::DecidimAwesome::ContentBlocks::AwesomeProcessGroupsCell
- Includes:
- CardHelper, CellsPaginateHelper
- Defined in:
- app/cells/decidim/decidim_awesome/content_blocks/awesome_process_groups_cell.rb
Instance Method Summary collapse
- #block_id ⇒ Object
-
#count_for(filter) ⇒ Object
Counts always reflect the full group (not affected by taxonomy selection).
- #current_page ⇒ Object
- #current_status ⇒ Object
- #data ⇒ Object
- #filter_url(overrides = {}) ⇒ Object
- #i18n_scope ⇒ Object
- #max_count ⇒ Object
- #paginated_items ⇒ Object
- #selected_taxonomy_ids ⇒ Object
- #selected_taxonomy_tags ⇒ Object
- #show ⇒ Object
- #status_filters ⇒ Object
- #taxonomy_filter_groups ⇒ Object
- #taxonomy_filters_available? ⇒ Boolean
- #taxonomy_selected?(id) ⇒ Boolean
- #title ⇒ Object
Instance Method Details
#block_id ⇒ Object
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_page ⇒ Object
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_status ⇒ Object
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 |
#data ⇒ Object
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_scope ⇒ Object
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_count ⇒ Object
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_items ⇒ Object
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_ids ⇒ Object
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_tags ⇒ Object
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 ||= 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 |
#show ⇒ Object
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_filters ⇒ Object
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_groups ⇒ Object
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
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
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 |
#title ⇒ Object
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 |