Merge pull request #2925 from aignatov-bio/ai-sci-5110-add-file-previews-to-reports

Add filer previews to reports [SCI-5110]
This commit is contained in:
aignatov-bio 2020-11-02 18:48:45 +01:00 committed by GitHub
commit f85a3493cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 19 deletions

View file

@ -365,6 +365,10 @@ label {
margin-left: 15px; margin-left: 15px;
} }
} }
img {
max-width: 100%;
}
} }
// Result table element style // Result table element style
@ -418,6 +422,11 @@ label {
} }
} }
img {
max-width: 100%;
}
.report-element-children { .report-element-children {
height: 0; height: 0;
} }

View file

@ -93,6 +93,10 @@ div.print-report {
&:hover > .report-element-header .attachment-icon { &:hover > .report-element-header .attachment-icon {
color: $color-black; color: $color-black;
} }
img {
max-width: 100%;
}
} }
.report-step-table-element { .report-step-table-element {
@ -195,6 +199,10 @@ div.print-report {
} }
} }
img {
max-width: 100%;
}
&:hover > .report-element-header { &:hover > .report-element-header {
.result-icon, .result-icon,
.result-name, .result-name,

View file

@ -99,9 +99,9 @@ module ReportsHelper
# "Hack" to omit file preview URL because of WKHTML issues # "Hack" to omit file preview URL because of WKHTML issues
def report_image_asset_url(asset) def report_image_asset_url(asset)
image_tag(asset.medium_preview preview = asset.inline? ? asset.large_preview : asset.medium_preview
.processed image_tag(preview.processed
.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME)) .service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
end end
# "Hack" to load Glyphicons css directly from the CDN # "Hack" to load Glyphicons css directly from the CDN

View file

@ -17,7 +17,7 @@ module Reports::Docx::DrawResultAsset
user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
end end
Reports::DocxRenderer.render_asset_image(@docx, asset) if asset.image? Reports::DocxRenderer.render_asset_image(@docx, asset) if asset.previewable? && !asset.list?
subject['children'].each do |child| subject['children'].each do |child|
public_send("draw_#{child['type_of']}", child, result) public_send("draw_#{child['type_of']}", child, result)

View file

@ -15,6 +15,6 @@ module Reports::Docx::DrawStepAsset
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray] timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
end end
Reports::DocxRenderer.render_asset_image(@docx, asset) if asset.image? Reports::DocxRenderer.render_asset_image(@docx, asset) if asset.previewable? && !asset.list?
end end
end end

View file

@ -141,9 +141,9 @@ module Reports
def self.render_asset_image(docx, asset) def self.render_asset_image(docx, asset)
return unless asset return unless asset
image_path = Reports::Utils.image_path(asset.file) asset_preview = Reports::Utils.image_prepare(asset)
dimension = FastImage.size(image_path) dimension = FastImage.size(asset_preview.service_url)
return unless dimension return unless dimension
x = dimension[0] x = dimension[0]
@ -152,8 +152,14 @@ module Reports
y = y * 300 / x y = y * 300 / x
x = 300 x = 300
end end
docx.img image_path.split('&')[0] do blob_data = if asset_preview.class == ActiveStorage::Preview
data asset.blob.download asset_preview.image.download
else
asset_preview.blob.download
end
docx.img asset_preview.service_url.split('&')[0] do
data blob_data
width x width x
height y height y
end end

View file

@ -121,7 +121,7 @@ module Reports
image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value)) image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value))
return unless image return unless image
image_path = Reports::Utils.image_path(image.image) image_path = Reports::Utils.image_prepare(image).service_url
dimension = FastImage.size(image_path) dimension = FastImage.size(image_path)
return unless dimension return unless dimension

View file

@ -6,8 +6,16 @@ module Reports
link[0] == '/' ? scinote_url + link : link link[0] == '/' ? scinote_url + link : link
end end
def self.image_path(attachment) def self.image_prepare(asset)
attachment.service_url if asset.class == Asset
if asset.inline?
asset.large_preview
else
asset.medium_preview
end
elsif asset.class == TinyMceAsset
asset.image
end
end end
def self.calculate_color_hsp(color) def self.calculate_color_hsp(color)

View file

@ -1,9 +1,8 @@
<% result ||= @result %> <% result ||= @result %>
<% asset = result.asset %> <% asset = result.asset %>
<% is_image = result.asset.image? %>
<% comments = result.result_comments %> <% comments = result.result_comments %>
<% timestamp = asset.created_at %> <% timestamp = asset.created_at %>
<% icon_class = 'fas ' + (is_image ? 'fa-image' : 'fa-file') %> <% icon_class = 'fas ' + file_fa_icon_class(asset) if asset.file_name %>
<div class="report-element report-result-element report-result-asset-element" <div class="report-element report-result-element report-result-asset-element"
data-ts="<%= timestamp.to_i %>" data-ts="<%= timestamp.to_i %>"
data-type="result_asset" data-type="result_asset"
@ -42,7 +41,7 @@
</div> </div>
</div> </div>
<div class="row"></div> <div class="row"></div>
<% if is_image %> <% if asset.previewable? && !asset.list? %>
<div class="report-element-body"> <div class="report-element-body">
<div class="row"> <div class="row">
<div class="col-xs-12 file-image"> <div class="col-xs-12 file-image">

View file

@ -1,12 +1,11 @@
<% asset ||= @asset %> <% asset ||= @asset %>
<% is_image = asset.image? %>
<% timestamp = asset.created_at %> <% timestamp = asset.created_at %>
<% icon_class = 'fas ' + (is_image ? 'fa-image' : 'fa-file') %> <% icon_class = file_fa_icon_class(asset) if asset.file_name %>
<div class="report-element report-step-attachment-element report-step-asset-element" data-ts="<%= timestamp.to_i %>" data-type="step_asset" data-id='{ "asset_id": <%= asset.id %> }' data-scroll-id="<%= asset.id %>" data-name="<%=t "projects.reports.elements.step_asset.sidebar_name", file: asset.file_name %>" data-icon-class="<%= icon_class %>"> <div class="report-element report-step-attachment-element report-step-asset-element" data-ts="<%= timestamp.to_i %>" data-type="step_asset" data-id='{ "asset_id": <%= asset.id %> }' data-scroll-id="<%= asset.id %>" data-name="<%=t "projects.reports.elements.step_asset.sidebar_name", file: asset.file_name %>" data-icon-class="<%= icon_class %>">
<div class="report-element-header"> <div class="report-element-header">
<div class="row"> <div class="row">
<div class="pull-left attachment-icon"> <div class="pull-left attachment-icon">
<span class="<%= icon_class %>"></span> <span class="fas <%= icon_class %>"></span>
</div> </div>
<div class="pull-left file-name"> <div class="pull-left file-name">
<% if defined? export_all and export_all %> <% if defined? export_all and export_all %>
@ -29,7 +28,7 @@
</div> </div>
</div> </div>
<div class="report-element-body"> <div class="report-element-body">
<% if is_image %> <% if asset.previewable? && !asset.list? %>
<div class="row"> <div class="row">
<div class="col-xs-12 file-image"> <div class="col-xs-12 file-image">
<% if defined?(export_all) && export_all %> <% if defined?(export_all) && export_all %>