Class: Decidim::ActivityCell
- Inherits:
-
ViewModel
- Object
- ViewModel
- Decidim::ActivityCell
- Includes:
- ActionView::Helpers::DateHelper, Cell::ViewModel::Partial, ApplicationHelper, IconHelper, SanitizeHelper
- Defined in:
- decidim-core/app/cells/decidim/activity_cell.rb
Overview
This cell is used to render public activities performed by users.
Each model that we want to represent should inherit from this cell and tweak the necessary methods (usually `title` is enough).
Direct Known Subclasses
Decidim::Accountability::ResultActivityCell, AssemblyActivityCell, Blogs::PostActivityCell, Budgets::OrderActivityCell, Comments::CommentActivityCell, ConsultationActivityCell, Consultations::QuestionActivityCell, Debates::DebateActivityCell, InitiativeActivityCell, Meetings::MeetingActivityCell, ParticipatoryProcessActivityCell, Proposals::ProposalActivityCell, Surveys::SurveyActivityCell
Constant Summary
Constants included from IconHelper
IconHelper::DEFAULT_RESOURCE_TYPE_ICONS
Instance Method Summary collapse
- #cache_hash ⇒ Object
- #created_at ⇒ Object
-
#description ⇒ Object
The description to show at the card.
- #element_id ⇒ Object
-
#renderable? ⇒ Boolean
Since activity logs could be linked to resource no longer available this method is added in order to skip rendering a cell if there's not enough data.
-
#resource ⇒ Object
The resource linked to the activity.
-
#resource_link_path ⇒ Object
The link to the resource linked to the activity.
-
#resource_link_text ⇒ Object
The text to show as the link to the resource.
- #show ⇒ Object
-
#title ⇒ Object
The title to show at the card.
- #user ⇒ Object
Methods included from IconHelper
#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key
Instance Method Details
#cache_hash ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 94 def cache_hash hash = [] hash << I18n.locale.to_s hash << model.class.name.underscore hash << model.cache_key_with_version if ( = ) hash.push(Digest::MD5.hexdigest(.send(:cache_hash))) end hash.join(Decidim.cache_key_separator) end |
#created_at ⇒ Object
75 76 77 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 75 def created_at t("decidim.activity.time_ago", time: time_ago_in_words(model.created_at)) end |
#description ⇒ Object
The description to show at the card.
The card will also be displayed OK if there's no description.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 51 def description resource_description = resource.try(:resource_description) || resource.try(:description) return if resource_description.blank? resource_description = case resource_description when String resource_description when Hash translated_attribute(resource_description) end truncate((resource_description), length: 300) end |
#element_id ⇒ Object
90 91 92 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 90 def element_id "action-#{model.id}" end |
#renderable? ⇒ Boolean
Since activity logs could be linked to resource no longer available this method is added in order to skip rendering a cell if there's not enough data.
24 25 26 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 24 def renderable? resource.present? && participatory_space.present? && published? end |
#resource ⇒ Object
The resource linked to the activity.
29 30 31 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 29 def resource model.resource_lazy end |
#resource_link_path ⇒ Object
The link to the resource linked to the activity.
66 67 68 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 66 def resource_link_path resource_locator(resource).path end |
#resource_link_text ⇒ Object
The text to show as the link to the resource.
71 72 73 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 71 def resource_link_text decidim_html_escape(translated_attribute(resource.title)) end |
#show ⇒ Object
15 16 17 18 19 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 15 def show return unless renderable? render end |
#title ⇒ Object
The title to show at the card.
The card will also be displayed OK if there's no title.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 36 def title resource_title = resource.try(:resource_title) || resource.try(:title) return if resource_title.blank? case resource_title when String resource_title when Hash translated_attribute(resource_title) end end |
#user ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'decidim-core/app/cells/decidim/activity_cell.rb', line 79 def user return resource. if resource.respond_to?(:normalized_author) return resource. if resource.respond_to?(:author) # As Proposals have Coauthorable concern instead of Authorable return resource.identities.first if resource.respond_to?(:identities) model.user_lazy if resource.respond_to?(:user) end |