mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-29 00:14:41 +08:00
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:
commit
f85a3493cd
10 changed files with 48 additions and 19 deletions
|
@ -365,6 +365,10 @@ label {
|
|||
margin-left: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
// Result table element style
|
||||
|
@ -418,6 +422,11 @@ label {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.report-element-children {
|
||||
height: 0;
|
||||
}
|
||||
|
|
|
@ -93,6 +93,10 @@ div.print-report {
|
|||
&:hover > .report-element-header .attachment-icon {
|
||||
color: $color-black;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.report-step-table-element {
|
||||
|
@ -195,6 +199,10 @@ div.print-report {
|
|||
}
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
&:hover > .report-element-header {
|
||||
.result-icon,
|
||||
.result-name,
|
||||
|
|
|
@ -99,9 +99,9 @@ module ReportsHelper
|
|||
|
||||
# "Hack" to omit file preview URL because of WKHTML issues
|
||||
def report_image_asset_url(asset)
|
||||
image_tag(asset.medium_preview
|
||||
.processed
|
||||
.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
|
||||
preview = asset.inline? ? asset.large_preview : asset.medium_preview
|
||||
image_tag(preview.processed
|
||||
.service_url(expires_in: Constants::URL_LONG_EXPIRE_TIME))
|
||||
end
|
||||
|
||||
# "Hack" to load Glyphicons css directly from the CDN
|
||||
|
|
|
@ -17,7 +17,7 @@ module Reports::Docx::DrawResultAsset
|
|||
user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
|
||||
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|
|
||||
public_send("draw_#{child['type_of']}", child, result)
|
||||
|
|
|
@ -15,6 +15,6 @@ module Reports::Docx::DrawStepAsset
|
|||
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
|
||||
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
|
||||
|
|
|
@ -141,9 +141,9 @@ module Reports
|
|||
def self.render_asset_image(docx, 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
|
||||
|
||||
x = dimension[0]
|
||||
|
@ -152,8 +152,14 @@ module Reports
|
|||
y = y * 300 / x
|
||||
x = 300
|
||||
end
|
||||
docx.img image_path.split('&')[0] do
|
||||
data asset.blob.download
|
||||
blob_data = if asset_preview.class == ActiveStorage::Preview
|
||||
asset_preview.image.download
|
||||
else
|
||||
asset_preview.blob.download
|
||||
end
|
||||
|
||||
docx.img asset_preview.service_url.split('&')[0] do
|
||||
data blob_data
|
||||
width x
|
||||
height y
|
||||
end
|
||||
|
|
|
@ -121,7 +121,7 @@ module Reports
|
|||
image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value))
|
||||
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)
|
||||
|
||||
return unless dimension
|
||||
|
|
|
@ -6,8 +6,16 @@ module Reports
|
|||
link[0] == '/' ? scinote_url + link : link
|
||||
end
|
||||
|
||||
def self.image_path(attachment)
|
||||
attachment.service_url
|
||||
def self.image_prepare(asset)
|
||||
if asset.class == Asset
|
||||
if asset.inline?
|
||||
asset.large_preview
|
||||
else
|
||||
asset.medium_preview
|
||||
end
|
||||
elsif asset.class == TinyMceAsset
|
||||
asset.image
|
||||
end
|
||||
end
|
||||
|
||||
def self.calculate_color_hsp(color)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
<% result ||= @result %>
|
||||
<% asset = result.asset %>
|
||||
<% is_image = result.asset.image? %>
|
||||
<% comments = result.result_comments %>
|
||||
<% 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"
|
||||
data-ts="<%= timestamp.to_i %>"
|
||||
data-type="result_asset"
|
||||
|
@ -42,7 +41,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row"></div>
|
||||
<% if is_image %>
|
||||
<% if asset.previewable? && !asset.list? %>
|
||||
<div class="report-element-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 file-image">
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
<% asset ||= @asset %>
|
||||
<% is_image = asset.image? %>
|
||||
<% 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-header">
|
||||
<div class="row">
|
||||
<div class="pull-left attachment-icon">
|
||||
<span class="<%= icon_class %>"></span>
|
||||
<span class="fas <%= icon_class %>"></span>
|
||||
</div>
|
||||
<div class="pull-left file-name">
|
||||
<% if defined? export_all and export_all %>
|
||||
|
@ -29,7 +28,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="report-element-body">
|
||||
<% if is_image %>
|
||||
<% if asset.previewable? && !asset.list? %>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 file-image">
|
||||
<% if defined?(export_all) && export_all %>
|
||||
|
|
Loading…
Add table
Reference in a new issue