2019-07-01 16:14:16 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-17 16:50:01 +08:00
|
|
|
module Reports::Docx::DrawStepTable
|
2023-05-10 22:15:14 +08:00
|
|
|
def draw_step_table(table, table_type)
|
2019-07-08 18:51:26 +08:00
|
|
|
color = @color
|
2019-07-01 16:14:16 +08:00
|
|
|
timestamp = table.created_at
|
2023-02-13 18:32:18 +08:00
|
|
|
obj = self
|
2023-05-10 22:15:14 +08:00
|
|
|
table_data = JSON.parse(table.contents_utf_8)['data']
|
|
|
|
table_data = obj.add_headers_to_table(table_data, table_type == 'step_well_plates_table')
|
2019-07-01 16:14:16 +08:00
|
|
|
@docx.p
|
2023-05-10 22:15:14 +08:00
|
|
|
@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]
|
|
|
|
|
|
|
|
if table.metadata.present?
|
|
|
|
table.metadata['cells']&.each do |cell|
|
2023-02-13 18:32:18 +08:00
|
|
|
data = cell[1]
|
2023-03-20 18:32:38 +08:00
|
|
|
next unless data.present? && data['row'].present? && data['col'].present? && data['className'].present?
|
|
|
|
|
2023-05-10 22:15:14 +08:00
|
|
|
cell_style rows.dig(data['row'].to_i + 1, data['col'].to_i + 1),
|
|
|
|
align: obj.table_cell_alignment(data['className'])
|
2023-02-13 18:32:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-01 16:14:16 +08:00
|
|
|
@docx.p do
|
2023-05-10 22:15:14 +08:00
|
|
|
text I18n.t("projects.reports.elements.#{table_type}.table_name", name: table.name), italic: true
|
2019-07-01 16:14:16 +08:00
|
|
|
text ' '
|
2023-05-10 22:15:14 +08:00
|
|
|
text I18n.t("projects.reports.elements.#{table_type}.user_time",
|
2019-07-08 18:51:26 +08:00
|
|
|
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
|
2019-07-01 16:14:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|