Module: Decidim::Meetings::ApplicationHelper

Includes:
CheckBoxesTreeHelper, Comments::CommentsHelper, FollowableHelper, Decidim::MapHelper, RichTextEditorHelper, SanitizeHelper, PaginateHelper
Included in:
HighlightedMeetingsForComponentCell, MeetingsHelper, PublicParticipantsListCell
Defined in:
app/helpers/decidim/meetings/application_helper.rb

Overview

Custom helpers, scoped to the meetings engine.

Instance Method Summary collapse

Instance Method Details

#activity_filter_valuesObject

Options to filter meetings by activity.



77
78
79
# File 'app/helpers/decidim/meetings/application_helper.rb', line 77

def activity_filter_values
  flat_filter_values(:all, :my_meetings, scope: "decidim.meetings.meetings.filters")
end

#apply_meetings_pack_tagsObject



126
127
128
129
# File 'app/helpers/decidim/meetings/application_helper.rb', line 126

def apply_meetings_pack_tags
  append_stylesheet_pack_tag("decidim_meetings", media: "all")
  append_javascript_pack_tag("decidim_meetings")
end

#filter_date_valuesObject



37
38
39
# File 'app/helpers/decidim/meetings/application_helper.rb', line 37

def filter_date_values
  flat_filter_values(:all, :upcoming, :past, scope: "decidim.meetings.meetings.filters.date_values")
end

#filter_origin_valuesObject



16
17
18
19
20
21
22
23
24
# File 'app/helpers/decidim/meetings/application_helper.rb', line 16

def filter_origin_values
  origin_keys = %w(official participants)
  origin_keys << "user_group" if current_organization.user_groups_enabled?

  origin_values = flat_filter_values(*origin_keys, scope: "decidim.meetings.meetings.filters.origin_values")
  origin_values.prepend(["", t("all", scope: "decidim.meetings.meetings.filters.origin_values")])

  filter_tree_from_array(origin_values)
end

#filter_sections(date: false, type: false, origin: false, taxonomies: false, space_type: false, activity: false) ⇒ Object

rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/CyclomaticComplexity



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/decidim/meetings/application_helper.rb', line 43

def filter_sections(date: false, type: false, origin: false, taxonomies: false, space_type: false, activity: false)
  @filter_sections ||= begin
    items = []
    if date
      items.append(method: :with_any_date, collection: filter_date_values, label: t("decidim.meetings.meetings.filters.date"), id: "date",
                   type: :radio_buttons)
    end
    items.append(method: :with_any_type, collection: filter_type_values, label: t("decidim.meetings.meetings.filters.type"), id: "type") if type
    if taxonomies
      available_taxonomy_filters.each do |taxonomy_filter|
        items.append(method: "with_any_taxonomies[#{taxonomy_filter.root_taxonomy_id}]",
                     collection: filter_taxonomy_values_for(taxonomy_filter),
                     label: decidim_sanitize_translated(taxonomy_filter.name),
                     id: "taxonomy-#{taxonomy_filter.root_taxonomy_id}")
      end
    end
    items.append(method: :with_any_origin, collection: filter_origin_values, label: t("decidim.meetings.meetings.filters.origin"), id: "origin") if origin
    if space_type
      items.append(method: :with_any_space, collection: directory_meeting_spaces_values, label: t("decidim.meetings.directory.meetings.index.space_type"),
                   id: "space_type")
    end
    if activity
      items.append(method: :activity, collection: activity_filter_values, label: t("decidim.meetings.meetings.filters.activity"), id: "activity",
                   type: :radio_buttons)
    end
    items.reject { |item| item[:collection].blank? }
  end
end

#filter_type_valuesObject



26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/decidim/meetings/application_helper.rb', line 26

def filter_type_values
  type_values = flat_filter_values(*Decidim::Meetings::Meeting::TYPE_OF_MEETING.keys, scope: "decidim.meetings.meetings.filters.type_values").map do |args|
    TreePoint.new(*args)
  end

  TreeNode.new(
    TreePoint.new("", t("decidim.meetings.meetings.filters.type_values.all")),
    type_values
  )
end

#iframe_embed_or_live_event_page?(meeting) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/helpers/decidim/meetings/application_helper.rb', line 122

def iframe_embed_or_live_event_page?(meeting)
  %w(embed_in_meeting_page open_in_live_event_page).include? meeting.iframe_embed_type
end

#online_or_hybrid_meeting?(meeting) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'app/helpers/decidim/meetings/application_helper.rb', line 118

def online_or_hybrid_meeting?(meeting)
  meeting.online? || meeting.hybrid?
end

#prevent_timeout_secondsObject



108
109
110
111
112
113
114
115
116
# File 'app/helpers/decidim/meetings/application_helper.rb', line 108

def prevent_timeout_seconds
  return 0 unless respond_to?(:meeting)
  return 0 if !current_user || !meeting || !meeting.live?
  return 0 unless online_or_hybrid_meeting?(meeting)
  return 0 unless iframe_embed_or_live_event_page?(meeting)
  return 0 unless meeting.iframe_access_level_allowed_for_user?(current_user)

  (meeting.end_time - Time.current).to_i
end

#render_meeting_body(meeting) ⇒ Object

If the content is safe, HTML tags are sanitized, otherwise, they are stripped.



95
96
97
# File 'app/helpers/decidim/meetings/application_helper.rb', line 95

def render_meeting_body(meeting)
  render_meeting_sanitize_field(meeting, :description)
end

#render_meeting_sanitize_field(meeting, field) ⇒ Object



99
100
101
102
103
104
105
106
# File 'app/helpers/decidim/meetings/application_helper.rb', line 99

def render_meeting_sanitize_field(meeting, field)
  sanitized = render_sanitized_content(meeting, field)
  if safe_content?
    Decidim::ContentProcessor.render_without_format(sanitized).html_safe
  else
    Decidim::ContentProcessor.render(sanitized, "div")
  end
end

#safe_content?Boolean

If the meeting is official or the rich text editor is enabled on the frontend, the meeting body is considered as safe content; that is unless the meeting comes from a collaborative_draft or a participatory_text.

Returns:

  • (Boolean)


84
85
86
# File 'app/helpers/decidim/meetings/application_helper.rb', line 84

def safe_content?
  rich_text_editor_in_public_views? || safe_content_admin?
end

#safe_content_admin?Boolean

For admin entered content, the meeting body can contain certain extra tags, such as iframes.

Returns:

  • (Boolean)


90
91
92
# File 'app/helpers/decidim/meetings/application_helper.rb', line 90

def safe_content_admin?
  @meeting.official?
end