Class: Decidim::Proposals::ProposalPresenter

Inherits:
ResourcePresenter show all
Includes:
ActionView::Helpers::UrlHelper, SanitizeHelper
Defined in:
decidim-proposals/app/presenters/decidim/proposals/proposal_presenter.rb

Overview

Decorator for proposals

Direct Known Subclasses

CollaborativeDraftPresenter

Instance Method Summary collapse

Methods included from SanitizeHelper

#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_editor, #decidim_sanitize_newsletter, #decidim_url_escape, included

Methods inherited from ResourcePresenter

#handle_locales

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#authorObject


13
14
15
16
17
18
19
20
# File 'decidim-proposals/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 'decidim-proposals/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 'decidim-proposals/app/presenters/decidim/proposals/proposal_presenter.rb', line 30

def display_mention
  link_to title, proposal_path
end

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


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

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

#proposalObject


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

def proposal
  __getobj__
end

#proposal_pathObject


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

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

#resource_manifestObject


82
83
84
# File 'decidim-proposals/app/presenters/decidim/proposals/proposal_presenter.rb', line 82

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 'decidim-proposals/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: extras
end

#versionsObject

Returns the proposal versions, hiding not published answers

Returns an Array.


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

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["state"] = pending_state_change if pending_state_change
      pending_state_change = nil
    elsif version.changeset["state"]
      pending_state_change = version.changeset.delete("state")
    end

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

    version
  end.compact
end