Class: Decidim::Proposals::ProposalPresenter

Inherits:
ResourcePresenter
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
app/presenters/decidim/proposals/proposal_presenter.rb

Overview

Decorator for proposals

Direct Known Subclasses

CollaborativeDraftPresenter

Instance Method Summary collapse

Instance Method Details

#authorObject



12
13
14
15
16
17
18
19
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 12

def author
  @author ||= if official?
                Decidim::Proposals::OfficialAuthorPresenter.new
              else
                coauthorship = coauthorships.includes(:author, :user_group).first
                coauthorship.user_group&.presenter || coauthorship.author.presenter
              end
end

#body(links: false, extras: true, strip_tags: false, all_locales: false) ⇒ Object



49
50
51
52
53
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 49

def body(links: false, extras: true, strip_tags: false, all_locales: false)
  return unless proposal

  content_handle_locale(proposal.body, all_locales, extras, links, strip_tags)
end

#display_mentionObject



29
30
31
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 29

def display_mention
  link_to title, proposal_path
end

#editor_body(all_locales: false, extras: true) ⇒ Object



55
56
57
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 55

def editor_body(all_locales: false, extras: true)
  editor_locales(proposal.body, all_locales, extras:)
end

#id_and_title(links: false, extras: true, html_escape: false) ⇒ Object



45
46
47
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 45

def id_and_title(links: false, extras: true, html_escape: false)
  "##{proposal.id} - #{title(links:, extras:, html_escape:)}"
end

#proposalObject



21
22
23
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 21

def proposal
  __getobj__
end

#proposal_pathObject



25
26
27
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 25

def proposal_path
  Decidim::ResourceLocatorPresenter.new(proposal).path
end

#resource_manifestObject



85
86
87
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 85

def resource_manifest
  proposal.class.resource_manifest
end

#title(links: false, extras: true, html_escape: false, all_locales: false) ⇒ Object

Render the proposal title

links - should render hashtags as links? extras - should include extra hashtags?

Returns a String.



39
40
41
42
43
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 39

def title(links: false, extras: true, html_escape: false, all_locales: false)
  return unless proposal

  super(proposal.title, links, html_escape, all_locales, extras:)
end

#versionsObject

Returns the proposal versions, hiding not published answers

Returns an Array.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 62

def versions
  version_state_published = false
  pending_state_change = nil

  proposal.versions.map do |version|
    state_published_change = version.changeset["state_published_at"]
    version_state_published = state_published_change.last.present? if state_published_change

    if version_state_published
      version.changeset["decidim_proposals_proposal_state_id"] = parsed_state_change(*pending_state_change) if pending_state_change
      pending_state_change = nil
    elsif version.changeset["decidim_proposals_proposal_state_id"]
      pending_state_change = version.changeset.delete("decidim_proposals_proposal_state_id")
    end

    next if version.event == "update" && Decidim::Proposals::DiffRenderer.new(version).diff.empty?

    version
  end.compact
end