Class: Decidim::Proposals::Admin::ProposalForm

Inherits:
Form
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/forms/decidim/proposals/admin/proposal_form.rb

Overview

A form object to be used when admin users want to create a proposal.

Instance Method Summary collapse

Instance Method Details

#authorObject



80
81
82
83
84
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 80

def author
  return current_organization unless created_in_meeting?

  meeting_as_author
end

#categoryObject

Finds the Category from the category_id.

Returns a Decidim::Category



51
52
53
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 51

def category
  @category ||= categories.find_by(id: category_id)
end

#component_automatic_hashtagsObject



99
100
101
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 99

def component_automatic_hashtags
  @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.automatic_hashtags)
end

#component_suggested_hashtagsObject



103
104
105
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 103

def component_suggested_hashtags
  @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.suggested_hashtags)
end

#extra_hashtagsObject



86
87
88
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 86

def extra_hashtags
  @extra_hashtags ||= (component_automatic_hashtags + suggested_hashtags).uniq
end

#map_model(model) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 37

def map_model(model)
  return unless model.categorization

  self.category_id = model.categorization.decidim_category_id
  self.scope_id = model.decidim_scope_id

  @suggested_hashtags = Decidim::ContentRenderers::HashtagRenderer.new(model.body).extra_hashtags.map(&:name).map(&:downcase)
end

#meeting_as_authorObject

Return the meeting as author



76
77
78
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 76

def meeting_as_author
  @meeting_as_author ||= meetings.find_by(id: meeting_id)
end

#meetingsObject

Finds the Meetings of the current participatory space



70
71
72
73
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 70

def meetings
  @meetings ||= Decidim.find_resource_manifest(:meetings).try(:resource_scope, current_component)
                       &.order(title: :asc)
end

#scopeObject

Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.

Returns a Decidim::Scope



58
59
60
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 58

def scope
  @scope ||= @scope_id ? current_participatory_space.scopes.find_by(id: @scope_id) : current_participatory_space.scope
end

#scope_idObject

Scope identifier

Returns the scope identifier related to the proposal



65
66
67
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 65

def scope_id
  @scope_id || scope&.id
end

#suggested_hashtag_checked?(hashtag) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 95

def suggested_hashtag_checked?(hashtag)
  suggested_hashtags.member?(hashtag)
end

#suggested_hashtagsObject



90
91
92
93
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 90

def suggested_hashtags
  downcased_suggested_hashtags = Array(@suggested_hashtags&.map(&:downcase)).to_set
  component_suggested_hashtags.select { |hashtag| downcased_suggested_hashtags.member?(hashtag.downcase) }
end