Adding missing avatars to comments (#1838)

This commit is contained in:
aignatov-bio 2019-06-14 16:20:13 +02:00 committed by GitHub
parent 52a2f5cd0e
commit 7a3eedf461
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 40 deletions

View file

@ -144,6 +144,21 @@
}
}
// Looks like PDF has some specail CSS rules, here is some hack
&.report {
display: block;
float: left;
width: 100%;
.avatar-placehodler {
float: left;
}
.content-placeholder {
float: left;
}
}
&[data-edit-mode="0"]:hover,
&[data-edit-mode="1"] {
.comment-right {

View file

@ -196,16 +196,7 @@ module ApplicationHelper
# No more dirty hack
def user_avatar_absolute_url(user, style)
begin
unless missing_avatar(user, style)
image = if user.avatar.options[:storage].to_sym == :s3
URI.parse(user.avatar.url(style)).open.to_a.join
else
File.open(user.avatar.path(style)).to_a.join
end
encoded_data = Base64.strict_encode64(image)
avatar_base64 = "data:#{user.avatar_content_type};base64,#{encoded_data}"
return avatar_base64
end
return user.avatar_base64(style) unless missing_avatar(user, style)
rescue StandardError => e
Rails.logger.error e.message
end

View file

@ -559,6 +559,22 @@ class User < ApplicationRecord
.map { |i| { name: escape_input(i[:full_name]), id: i[:id] } }
end
def avatar_base64(style)
unless avatar.present?
missing_link = File.open("#{Rails.root}/app/assets/images/#{style}/missing.png").to_a.join
return "data:image/png;base64,#{Base64.strict_encode64(missing_link)}"
end
avatar_uri = if avatar.options[:storage].to_sym == :s3
URI.parse(avatar.url(style)).open.to_a.join
else
File.open(avatar.path(style)).to_a.join
end
encoded_data = Base64.strict_encode64(avatar_uri)
"data:#{avatar_content_type};base64,#{encoded_data}"
end
protected
def confirmation_required?

View file

@ -18,22 +18,13 @@
</div>
<div class="report-element-body">
<div class="row">
<div class="col-xs-12 comments-container">
<div class="col-xs-12 comments-container simple">
<% if comments.count == 0 %>
<em><%=t "projects.reports.elements.result_comments.no_comments" %></em>
<% else %>
<ul class="no-style comments-list">
<ul class="no-style content-comments">
<% comments.each do |comment| %>
<% comment_ts = comment.created_at %>
<li class="comment" data-ts="<%= comment_ts.to_i %>">
<span class="comment-prefix">
<em><%=t "projects.reports.elements.result_comments.comment_prefix", user: comment.user.full_name, date: l(comment_ts, format: :full_date), time: l(comment_ts, format: :time) %></em>
</span>
<span class="comment-message">
&nbsp;
<%= custom_auto_link(comment.message, team: current_team) %>
</span>
</li>
<%= render partial: 'shared/comments/item.html.erb', locals: { comment: comment, readonly: true, report: true } %>
<% end %>
</ul>
<% end %>

View file

@ -18,22 +18,13 @@
</div>
<div class="report-element-body">
<div class="row">
<div class="col-xs-12 comments-container">
<div class="col-xs-12 comments-container simple">
<% if comments.count == 0 %>
<em><%=t "projects.reports.elements.step_comments.no_comments" %></em>
<% else %>
<ul class="no-style comments-list">
<ul class="no-style content-comments">
<% comments.each do |comment| %>
<% comment_ts = comment.created_at %>
<li class="comment" data-ts="<%= comment_ts.to_i %>">
<span class="comment-prefix">
<em><%=t "projects.reports.elements.step_comments.comment_prefix", user: comment.user.full_name, date: l(comment_ts, format: :full_date), time: l(comment_ts, format: :time) %></em>
</span>
<span class="comment-message">
&nbsp;
<%= custom_auto_link(comment.message, team: current_team) %>
</span>
</li>
<%= render partial: 'shared/comments/item.html.erb', locals: { comment: comment, readonly: true, report: true } %>`
<% end %>
</ul>
<% end %>

View file

@ -1,6 +1,8 @@
<% user_comment = comment.user == current_user %>
<% report = false unless defined?(report) %>
<% readonly = false unless defined?(readonly) %>
<% edit_mode = (comment.user == current_user && !readonly) %>
<div
class="comment-container <%= user_comment ? 'comment-editable-field' : '' %>"
class="comment-container <%= edit_mode ? 'comment-editable-field' : '' %> <%= report ? 'report' : '' %>"
data-field-to-update="message"
data-params-group="comment"
data-path-to-update="<%= comment_action_url(comment) %>"
@ -10,15 +12,19 @@
error="false"
>
<div class="avatar-placehodler">
<span class='global-avatar-container'>
<%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %>
<span class='global-avatar-container'>
<% if report %>
<%= image_tag comment.user.avatar_base64(:icon_small), class: 'avatar' %>
<% else %>
<%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %>
<% end %>
</span>
</div>
<div class="content-placeholder">
<div class="comment-name"><%= comment.user.full_name %></div>
<div class="comment-right">
<div class="comment-datetime"><%= l(comment.created_at, format: :full) %></div>
<% if user_comment %>
<% if edit_mode %>
<div class="comment-actions">
<div class="edit-buttons">
<span class="save-button"><i class="fas fa-save"></i><%= t('general.save') %></span>
@ -39,7 +45,7 @@
</div>
<div class="comment-message">
<div class="view-mode"><%= custom_auto_link(comment.message, team: current_team, simple_format: true).html_safe %></div>
<% if user_comment %>
<% if edit_mode %>
<%= text_area_tag 'message', comment.message, disabled: true, class: 'smart-text-area hidden' %>
<% end %>
</div>