mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-04 02:45:53 +08:00
Fix report generating for empty tables [SCI-12144]
This commit is contained in:
parent
b0efe5b914
commit
747a6ca7bf
3 changed files with 14 additions and 12 deletions
|
@ -4,7 +4,7 @@ module TableHelper
|
|||
def table_data
|
||||
content = {}
|
||||
data = JSON.parse(contents)['data']
|
||||
return [] if data.blank?
|
||||
return {} if data.blank?
|
||||
|
||||
cells = metadata.fetch('cells', [])
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ module Reports
|
|||
table_data = add_headers_to_table(table_data, table_type == 'well_plates_table')
|
||||
|
||||
if table.metadata.present? && table.metadata['cells'].is_a?(Array)
|
||||
table.metadata['cells'].each do |cell|
|
||||
table.metadata&.dig('cells')&.each do |cell|
|
||||
next unless cell.is_a?(Hash)
|
||||
next unless cell['row'].present? && cell['col'].present?
|
||||
|
||||
row_index = cell['row'].to_i + 1
|
||||
|
@ -21,6 +22,9 @@ module Reports
|
|||
end
|
||||
end
|
||||
@docx.p
|
||||
|
||||
return unless table_data.present? && table_data[0].present?
|
||||
|
||||
@docx.table table_data, border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE do
|
||||
cell_style rows[0], bold: true, background: color[:concrete]
|
||||
cell_style cols[0], bold: true, background: color[:concrete]
|
||||
|
@ -50,18 +54,16 @@ module Reports
|
|||
end
|
||||
|
||||
def add_headers_to_table(table, is_well_plate)
|
||||
table.each_with_index do |row, index|
|
||||
table&.each_with_index do |row, index|
|
||||
row.unshift(is_well_plate ? convert_index_to_letter(index) : index + 1)
|
||||
end
|
||||
|
||||
header_row = Array.new(table.first.length) do |index|
|
||||
if index.zero?
|
||||
''
|
||||
else
|
||||
is_well_plate ? index : convert_index_to_letter(index - 1)
|
||||
end
|
||||
header_row = Array.new(table&.dig(0)&.length || 0) do |index|
|
||||
next '' if index.zero?
|
||||
|
||||
is_well_plate ? index : convert_index_to_letter(index - 1)
|
||||
end
|
||||
table.unshift(header_row)
|
||||
table&.unshift(header_row)
|
||||
end
|
||||
|
||||
def convert_index_to_letter(index)
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
<% content[:contents].first.each_with_index do |el, index| %>
|
||||
<% content[:contents]&.first&.each_with_index do |el, index| %>
|
||||
<th style="width:<%= content[:columns_size][index] %>px">
|
||||
<%= content[:columns_title][index] %>
|
||||
</th>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
<% content[:contents].each_with_index do |line, row_index| %>
|
||||
<% content[:contents]&.each_with_index do |line, row_index| %>
|
||||
<tr style="height:<%= content[:rows_size][row_index] %>px">
|
||||
<td style="text-align:center"> <%= content[:rows_title][row_index] %></td>
|
||||
<% line.each_with_index do |el, column_index| %>
|
||||
|
|
Loading…
Add table
Reference in a new issue