Styling changes in DOCX report [SCI-3633] (#1899)

* Styling changes in DOCX report

* Update result comments in docx report

* Fix markup
This commit is contained in:
aignatov-bio 2019-07-12 13:48:14 +02:00 committed by GitHub
parent 5ca822a7d8
commit 4bae87e3f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 77 additions and 58 deletions

View file

@ -8,7 +8,7 @@ module DrawExperiment
experiment = Experiment.find_by_id(subject['id']['experiment_id'])
return unless experiment
@docx.h2 experiment.name
@docx.h2 experiment.name, size: Constants::REPORT_DOCX_EXPERIMENT_TITLE_SIZE
@docx.p do
text I18n.t('projects.reports.elements.experiment.user_time',
timestamp: I18n.l(experiment.created_at, format: :full)), color: color[:gray]

View file

@ -6,9 +6,10 @@ module DrawMyModule
link_style = @link_style
scinote_url = @scinote_url
my_module = MyModule.find_by_id(subject['id']['my_module_id'])
tags = my_module.tags
return unless my_module
@docx.h3 my_module.name, italic: false
@docx.h3 my_module.name, italic: false, size: Constants::REPORT_DOCX_MY_MODULE_TITLE_SIZE
@docx.p do
text I18n.t('projects.reports.elements.module.user_time',
timestamp: I18n.l(my_module.created_at, format: :full)), color: color[:gray]
@ -20,8 +21,8 @@ module DrawMyModule
text I18n.t('projects.reports.elements.module.no_due_date'), color: color[:gray]
end
if my_module.completed?
text " #{I18n.t('my_modules.states.completed')} #{I18n.l(my_module.completed_on, format: :full)}",
color: color[:gray]
text " #{I18n.t('my_modules.states.completed')}", bold: true, color: color[:green]
text " #{I18n.l(my_module.completed_on, format: :full)}", color: color[:gray]
end
if my_module.archived?
text ' | '
@ -41,9 +42,14 @@ module DrawMyModule
@docx.p do
text I18n.t 'projects.reports.elements.module.tags_header'
my_module.tags.each do |tag|
if tags.any?
my_module.tags.each do |tag|
text ' '
text "[#{tag.name}]", color: tag.color.delete('#')
end
else
text ' '
text tag.name, color: tag.color.delete('#')
text I18n.t 'projects.reports.elements.module.no_tags'
end
end

View file

@ -11,7 +11,8 @@ module DrawMyModuleActivity
color = @color
@docx.p
@docx.p I18n.t('projects.reports.elements.module_activity.name', my_module: my_module.name), bold: true
@docx.p I18n.t('projects.reports.elements.module_activity.name', my_module: my_module.name),
bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE
activities.each do |activity|
activity_ts = activity.created_at
activity_text = if activity.old_activity?

View file

@ -45,8 +45,9 @@ module DrawMyModuleRepository
@docx.p
@docx.p I18n.t('projects.reports.elements.module_repository.name',
repository: repository.name,
my_module: my_module.name), bold: true
my_module: my_module.name), bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE
@docx.table table, border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE
@docx.p
@docx.p
end

View file

@ -11,10 +11,10 @@ module DrawResultAsset
color = @color
@docx.p
@docx.p do
text result.name
text result.name, italic: true
text ' ' + I18n.t('search.index.archived'), color: color[:gray] if result.archived?
text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_file_name)
text ' ' + I18n.t('projects.reports.elements.result_asset.user_time',
text ' ' + I18n.t('projects.reports.elements.result_asset.file_name', file: asset.file_file_name)
text ' ' + I18n.t('projects.reports.elements.result_asset.user_time',
user: result.user.full_name, timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]
end

View file

@ -9,22 +9,17 @@ module DrawResultComments
return if comments.count.zero?
@docx.p
@docx.p I18n.t('projects.reports.elements.result_comments.name', result: result.name), bold: true
team = @report_team
user = @user
@docx.ol do
comments.each do |comment|
comment_ts = comment.created_at
li do
text I18n.t('projects.reports.elements.result_comments.comment_prefix',
user: comment.user.full_name,
date: I18n.l(comment_ts, format: :full_date),
time: I18n.l(comment_ts, format: :time)), italic: true
br
text SmartAnnotations::TagToText.new(user, team, comment.message).text
br
end
end
@docx.p I18n.t('projects.reports.elements.result_comments.name', result: result.name),
bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE
comments.each do |comment|
comment_ts = comment.created_at
@docx.p I18n.t('projects.reports.elements.result_comments.comment_prefix',
user: comment.user.full_name,
date: I18n.l(comment_ts, format: :full_date),
time: I18n.l(comment_ts, format: :time)), italic: true
html = custom_auto_link(comment.message, team: @report_team)
html_to_word_converter(html)
@docx.p
end
end
end

View file

@ -10,7 +10,7 @@ module DrawResultTable
color = @color
@docx.p
@docx.p do
text result.name
text result.name, italic: true
text ' ' + I18n.t('search.index.archived'), color: color[:gray] if result.archived?
text ' '
text I18n.t 'projects.reports.elements.result_table.table_name', name: table.name

View file

@ -10,7 +10,7 @@ module DrawResultText
color = @color
@docx.p
@docx.p do
text result.name
text result.name, italic: true
text ' ' + I18n.t('search.index.archived'), color: color[:gray] if result.archived?
text ' '
text I18n.t('projects.reports.elements.result_table.user_time',

View file

@ -2,6 +2,7 @@
module DrawStep
def draw_step(subject)
color = @color
step = Step.find_by_id(subject['id']['step_id'])
return unless step
@ -9,20 +10,20 @@ module DrawStep
user = step.completed || !step.changed? ? step.user : step.last_modified_by
timestamp = step.completed ? step.completed_on : step.updated_at
@docx.p
@docx.h5 I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one) +
' ' + step.name
@docx.h5 (I18n.t('projects.reports.elements.step.step_pos', pos: step.position_plus_one) +
' ' + step.name), size: Constants::REPORT_DOCX_STEP_TITLE_SIZE
@docx.p do
if step.completed
text I18n.t('protocols.steps.completed'), color: '2dbe61'
text I18n.t('protocols.steps.completed'), color: color[:green], bold: true
else
text I18n.t('protocols.steps.uncompleted'), color: 'a0a0a0'
text I18n.t('protocols.steps.uncompleted'), color: color[:gray], bold: true
end
text ' | '
text I18n.t(
"projects.reports.elements.step.#{step_type_str}.user_time",
user: user.full_name,
timestamp: I18n.l(timestamp, format: :full)
), color: 'a0a0a0'
), color: color[:gray]
end
if step.description.present?
html = custom_auto_link(step.description, team: @report_team)

View file

@ -10,7 +10,7 @@ module DrawStepAsset
color = @color
@docx.p
@docx.p do
text I18n.t 'projects.reports.elements.step_asset.file_name', file: asset.file_file_name
text (I18n.t 'projects.reports.elements.step_asset.file_name', file: asset.file_file_name), italic: true
text ' '
text I18n.t('projects.reports.elements.step_asset.user_time',
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]

View file

@ -14,7 +14,7 @@ module DrawStepChecklist
@user,
@report_team,
I18n.t('projects.reports.elements.step_checklist.checklist_name', name: checklist.name)
).text
).text, italic: true
text ' '
text I18n.t('projects.reports.elements.step_checklist.user_time',
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]

View file

@ -8,23 +8,18 @@ module DrawStepComments
comments = step.step_comments
return if comments.count.zero?
team = @report_team
user = @user
@docx.p
@docx.p I18n.t('projects.reports.elements.step_comments.name', step: step.name), bold: true
@docx.ol do
comments.each do |comment|
comment_ts = comment.created_at
li do
text I18n.t('projects.reports.elements.step_comments.comment_prefix',
user: comment.user.full_name,
date: I18n.l(comment_ts, format: :full_date),
time: I18n.l(comment_ts, format: :time)), italic: true
br
text SmartAnnotations::TagToText.new(user, team, comment.message).text
br
end
end
@docx.p I18n.t('projects.reports.elements.step_comments.name', step: step.name),
bold: true, size: Constants::REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE
comments.each do |comment|
comment_ts = comment.created_at
@docx.p I18n.t('projects.reports.elements.step_comments.comment_prefix',
user: comment.user.full_name,
date: I18n.l(comment_ts, format: :full_date),
time: I18n.l(comment_ts, format: :time)), italic: true
html = custom_auto_link(comment.message, team: @report_team)
html_to_word_converter(html)
@docx.p
end
end
end

View file

@ -9,7 +9,7 @@ module DrawStepTable
timestamp = table.created_at
@docx.p
@docx.p do
text I18n.t 'projects.reports.elements.step_table.table_name', name: table.name
text I18n.t('projects.reports.elements.step_table.table_name', name: table.name), italic: true
text ' '
text I18n.t('projects.reports.elements.step_table.user_time',
timestamp: I18n.l(timestamp, format: :full)), color: color[:gray]

View file

@ -72,9 +72,12 @@ module PrivateMethods
style = paragraph_styling(elem.parent)
type = (style[:align] && style[:align] != :justify) || style[:style] ? 'newline' : 'text'
text = smart_annotation_check(elem)
elements.push(
type: type,
value: elem.text.strip.delete(' '), # Invisible symbol
value: text.strip.delete(' '), # Invisible symbol
style: style
)
next
@ -117,7 +120,12 @@ module PrivateMethods
def link_prepare(elem)
text = elem.text
link = elem.attributes['href'].value if elem.attributes['href']
link = nil if elem.attributes['class'] && elem.attributes['class'].value == 'record-info-link'
if elem.attributes['class']&.value == 'record-info-link'
link = nil
text = "##{text}"
end
text = "##{text}" if elem.parent.attributes['class']&.value == 'atwho-inserted'
text = "@#{text}" if elem.attributes['class']&.value == 'atwho-user-popover'
{
type: 'a',
value: text,
@ -125,6 +133,12 @@ module PrivateMethods
}
end
def smart_annotation_check(elem)
return "[#{elem.text}]" if elem.parent.attributes['class']&.value == 'sa-type'
elem.text
end
# Prepare style for text
def paragraph_styling(elem)
style = elem.attributes['style']
@ -265,7 +279,8 @@ module PrivateMethods
}
@color = {
gray: 'a0a0a0'
gray: 'a0a0a0',
green: '2dbe61'
}
end

View file

@ -24,7 +24,7 @@
<% else %>
<ul class="no-style content-comments">
<% comments.each do |comment| %>
<%= render partial: 'shared/comments/item.html.erb', locals: { comment: comment, readonly: true, report: true } %>`
<%= render partial: 'shared/comments/item.html.erb', locals: { comment: comment, readonly: true, report: true } %>
<% end %>
</ul>
<% end %>

View file

@ -113,9 +113,14 @@ class Constants
# Word borders in eighth point units.
# A eighth point is 1/8 of a point. A border size of 4 is equivalent to 0.5pt.
REPORT_DOCX_TABLE_BORDER_SIZE = 4
# All font size in half points
REPORT_DOCX_EXPERIMENT_TITLE_SIZE = 28
REPORT_DOCX_MY_MODULE_TITLE_SIZE = 24
REPORT_DOCX_STEP_TITLE_SIZE = 22
REPORT_DOCX_STEP_ELEMENTS_TITLE_SIZE = 20
#=============================================================================
# Styling
#=============================================================================