Class: Decidim::Proposals::Admin::ProposalForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Proposals::Admin::ProposalForm
- 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
- #author ⇒ Object
-
#category ⇒ Object
Finds the Category from the category_id.
- #component_automatic_hashtags ⇒ Object
- #component_suggested_hashtags ⇒ Object
- #extra_hashtags ⇒ Object
- #map_model(model) ⇒ Object
-
#meeting_as_author ⇒ Object
Return the meeting as author.
-
#meetings ⇒ Object
Finds the Meetings of the current participatory space.
-
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
-
#scope_id ⇒ Object
Scope identifier.
- #suggested_hashtag_checked?(hashtag) ⇒ Boolean
- #suggested_hashtags ⇒ Object
Instance Method Details
#author ⇒ Object
80 81 82 83 84 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 80 def return current_organization unless created_in_meeting? end |
#category ⇒ Object
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_hashtags ⇒ Object
99 100 101 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 99 def @component_automatic_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#component_suggested_hashtags ⇒ Object
103 104 105 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 103 def @component_suggested_hashtags ||= ordered_hashtag_list(current_component.current_settings.) end |
#extra_hashtags ⇒ Object
86 87 88 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 86 def @extra_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)..map(&:name).map(&:downcase) end |
#meeting_as_author ⇒ Object
Return the meeting as author
76 77 78 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 76 def @meeting_as_author ||= meetings.find_by(id: meeting_id) end |
#meetings ⇒ Object
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 |
#scope ⇒ Object
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_id ⇒ Object
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
95 96 97 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 95 def suggested_hashtag_checked?(hashtag) .member?(hashtag) end |
#suggested_hashtags ⇒ Object
90 91 92 93 |
# File 'app/forms/decidim/proposals/admin/proposal_form.rb', line 90 def = Array(@suggested_hashtags&.map(&:downcase)).to_set .select { |hashtag| .member?(hashtag.downcase) } end |