Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make avatars helper method simpler #16480

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/api/app/components/notification_component.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
= render NotificationMarkButtonComponent.new(@notification, @selected_filter, @page)
.row.mt-1.ps-sm-4
.col-auto.pe-0
= helpers.avatars(@notification)
%ul.list-inline.d-flex.flex-row-reverse.avatars.m-0
= helpers.hidden_avatars(@notification)
- helpers.avatars_to_display(@notification.avatar_objects).each do |avatar_object|
%li.list-inline-item
= helpers.avatars(avatar_object)
.col-auto.ps-xs-2
.smart-overflow= @notification.description
.row.d-none.d-md-block.ps-4
Expand Down
58 changes: 23 additions & 35 deletions src/api/app/helpers/webui/notification_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ def truncate_to_first_new_line(text)
text.truncate(truncation_index)
end

def avatars(notification)
capture do
tag.ul(class: 'list-inline d-flex flex-row-reverse avatars m-0') do
hidden_avatars(notification)
def avatars(avatar_object)
case avatar_object.class.name
when 'User', 'Group'
render(AvatarComponent.new(name: avatar_object.name, email: avatar_object.email, size: 23, shape: :circle))
when 'Package'
tag.span(class: 'fa fa-archive text-warning rounded-circle bg-body-secondary border simulated-avatar', title: "Package #{avatar_object.project}/#{avatar_object}")
when 'Project'
tag.span(class: 'fa fa-cubes text-secondary rounded-circle bg-body-secondary border simulated-avatar', title: "Project #{avatar_object}")
end
end

def hidden_avatars(notification)
return unless number_of_hidden_avatars(notification.avatar_objects).positive?

avatars_to_display(notification.avatar_objects).each do |avatar_object|
concat(
tag.li(class: 'list-inline-item') do
case avatar_object.class.name
when 'User', 'Group'
render(AvatarComponent.new(name: avatar_object.name, email: avatar_object.email, size: 23, shape: :circle))
when 'Package'
tag.span(class: 'fa fa-archive text-warning rounded-circle bg-body-secondary border simulated-avatar', title: "Package #{avatar_object.project}/#{avatar_object}")
when 'Project'
tag.span(class: 'fa fa-cubes text-secondary rounded-circle bg-body-secondary border simulated-avatar', title: "Project #{avatar_object}")
end
end
)
end
concat(
tag.li(class: 'list-inline-item') do
tag.span("#{number_of_hidden_avatars(notification.avatar_objects)}",
class: 'rounded-circle bg-body-secondary border avatars-counter',
title: "#{number_of_hidden_avatars(notification.avatar_objects)} more users involved")
end
end
)
end

def avatars_to_display(avatar_objects)
avatar_objects.first(MAXIMUM_DISPLAYED_AVATARS).reverse
end

private
Expand All @@ -49,20 +53,4 @@ def mark_as_read_or_unread_button(notification)
def number_of_hidden_avatars(avatar_objects)
[0, avatar_objects.size - MAXIMUM_DISPLAYED_AVATARS].max
end

def hidden_avatars(notification)
return unless number_of_hidden_avatars(notification.avatar_objects).positive?

concat(
tag.li(class: 'list-inline-item') do
tag.span("#{number_of_hidden_avatars(notification.avatar_objects)}",
class: 'rounded-circle bg-body-secondary border avatars-counter',
title: "#{number_of_hidden_avatars(notification.avatar_objects)} more users involved")
end
)
end

def avatars_to_display(avatar_objects)
avatar_objects.first(MAXIMUM_DISPLAYED_AVATARS).reverse
end
end