Class: Decidim::CollaborativeTexts::SuggestionPresenter

Inherits:
ResourcePresenter
  • Object
show all
Includes:
ApplicationHelper
Defined in:
decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb

Overview

Decorator for collaborative texts suggestions.

Constant Summary

Constants included from AmendmentsHelper

AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods included from ApplicationHelper

#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #layout_item_classes, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials

Methods included from Decidim::CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from Decidim::ContextualHelpHelper

#floating_help

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods inherited from ResourcePresenter

#editor_locales, #handle_locales

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Instance Method Details

#originalObject



23
24
25
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 23

def original
  @original ||= ActionView::Base.full_sanitizer.sanitize(changeset["original"]&.join(" ")&.strip).to_s
end

#safe_jsonObject



45
46
47
48
49
50
51
52
53
54
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 45

def safe_json
  {
    id:,
    changeset:,
    summary:,
    status:,
    type:,
    createdAt: created_at
  }
end

#suggestionObject



27
28
29
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 27

def suggestion
  __getobj__
end

#summaryObject

A summary to print in the UI



13
14
15
16
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 13

def summary
  txt = type == :remove ? original : text
  @summary ||= I18n.t("decidim.collaborative_texts.suggestion.#{type}_html", text: txt.truncate(150))
end

#textObject

A text representation of the changeset. Without HTML.



19
20
21
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 19

def text
  @text ||= ActionView::Base.full_sanitizer.sanitize(changeset["replace"]&.join(" ")&.strip).to_s
end

#title(html_escape: false, all_locales: false) ⇒ Object

Render the suggestion title

Returns a String.



34
35
36
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 34

def title(html_escape: false, all_locales: false)
  super(suggestion.document.title, html_escape, all_locales)
end

#typeObject



38
39
40
41
42
43
# File 'decidim-collaborative_texts/app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 38

def type
  return :remove if text.blank?
  return :add if text.include?(original.to_s)

  :replace
end