forked from codeforjapan/decidim-cfj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LastCommentActivitiesCell and Comments::LastCommentActivityCell
add `Comments::LastCommentActivityCell#max_comment_length` to limit activities' length
- Loading branch information
1 parent
ec86adf
commit 3523426
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="activity" data-activity> | ||
<div class="activity__time"> | ||
<%= created_at %> | ||
</div> | ||
<div class="activity__content"> | ||
<span> | ||
<% if title.present? %> | ||
<span> | ||
<%= title_icon %> | ||
<%= title %> | ||
</span> | ||
<% end %> | ||
<a href="<%= resource_link_path %>"> | ||
<%= html_truncate decidim_sanitize(resource_link_text, strip_tags: true), length: max_comment_length %> | ||
</a> | ||
</span> | ||
<% unless hide_participatory_space? %> | ||
<span> | ||
<%= participatory_space_link %> | ||
</span> | ||
<% end %> | ||
</div> | ||
<% if show_author? %> | ||
<div class="activity__author"> | ||
<%= author %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Comments | ||
# A cell to display when a comment has been created. | ||
class LastCommentActivityCell < ActivityCell | ||
include CommentCellsHelper | ||
|
||
def show | ||
return unless renderable? | ||
|
||
render | ||
end | ||
|
||
def title | ||
I18n.t("decidim.comments.last_activity.new_comment") | ||
end | ||
|
||
def participatory_space | ||
model.participatory_space_lazy | ||
end | ||
|
||
def participatory_space_link | ||
link_to(root_commentable_title, resource_link_path) | ||
end | ||
|
||
def participatory_space_icon | ||
resource_type_icon(root_commentable.class) | ||
end | ||
|
||
def hide_participatory_space? = false | ||
|
||
def comment | ||
model.resource_lazy | ||
end | ||
|
||
def max_comment_length | ||
40 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="activity__container"> | ||
<% activities.each do |activity| %> | ||
<%= activity_cell_for(activity) %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# Renders a collection of activities using a different cell for | ||
# each one. | ||
class LastCommentActivitiesCell < Decidim::ViewModel | ||
include Decidim::CardHelper | ||
include Decidim::IconHelper | ||
include Decidim::Core::Engine.routes.url_helpers | ||
|
||
# Since we are rendering each activity separatedly we need to trigger | ||
# BatchLoader in order to accumulate all the ids to be found later. | ||
def show | ||
return if activities.blank? | ||
|
||
render | ||
end | ||
|
||
def activity_cell_for(activity) | ||
opts = options.slice(:id_prefix, :hide_participatory_space).merge( | ||
show_author: (context[:user] != activity.user) | ||
) | ||
|
||
cell "decidim/comments/last_comment_activity", activity, context: opts | ||
end | ||
|
||
def activities | ||
@activities ||= model.map do |activity| | ||
activity.organization_lazy | ||
activity.resource_lazy | ||
activity.participatory_space_lazy | ||
activity.component_lazy | ||
activity | ||
end | ||
end | ||
end | ||
end |