Class: Decidim::Proposals::ProposalPresenter

Inherits:
ResourcePresenter
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper, SanitizeHelper
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



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

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



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

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



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

def display_mention
  link_to title, proposal_path
end

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



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

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



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

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

#proposalObject



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

def proposal
  __getobj__
end

#proposal_pathObject



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

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

#resource_manifestObject



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

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.



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

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.



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

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