Print protocol smart annotation and table improvements [SCI-6566] (#3925)

* Improve table printing in the print menu [SCI-6566]

* Open smart annotation in new tab for print view [SCI-6566]

* Unify naming of same parameter [SCI-6566]

* Fix typo [SCI-6566]

* Fix hound errors [SCI-6566]
This commit is contained in:
ajugo 2022-03-29 12:09:33 +02:00 committed by GitHub
parent ea5ee65618
commit f75265974e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 20 deletions

View file

@ -6,6 +6,12 @@
margin: 8mm;
}
@media print {
.print-table {
page-break-inside: avoid;
}
}
.page-break {
clear: both;
}

View file

@ -107,24 +107,28 @@ module ApplicationHelper
UserNotification.create(notification: notification, user: target_user) if target_user.assignments_notification
end
def smart_annotation_parser(text, team = nil, base64_encoded_imgs = false)
def custom_link_open_new_tab(text)
text.gsub(/\<a /, '<a target=_blank ')
end
def smart_annotation_parser(text, team = nil, base64_encoded_imgs = false, preview_repository = false)
# sometimes happens that the "team" param gets wrong data: "{nil, []}"
# so we have to check if the "team" param is kind of Team object
team = nil unless team.is_a? Team
new_text = smart_annotation_filter_resources(text, team)
new_text = smart_annotation_filter_resources(text, team, preview_repository)
new_text = smart_annotation_filter_users(new_text, team, base64_encoded_imgs)
new_text
end
# Check if text have smart annotations of resources
# and outputs a link to resource
def smart_annotation_filter_resources(text, team)
def smart_annotation_filter_resources(text, team, preview_repository = false)
user = if !defined?(current_user) && @user
@user
else
current_user
end
SmartAnnotations::TagToHtml.new(user, team, text).html
SmartAnnotations::TagToHtml.new(user, team, text, preview_repository).html
end
# Check if text have smart annotations of users

View file

@ -23,12 +23,13 @@ module InputSanitizeHelper
team = options.fetch(:team) { nil }
wrapper_tag = options.fetch(:wrapper_tag) { {} }
tags = options.fetch(:tags) { [] }
preview_repository = options.fetch(:preview_repository) { false }
format_opt = wrapper_tag.merge(sanitize: false)
base64_encoded_imgs = options.fetch(:base64_encoded_imgs) { false }
text = sanitize_input(text, tags)
text = simple_format(sanitize_input(text), {}, format_opt) if simple_f
auto_link(
smart_annotation_parser(text, team, base64_encoded_imgs),
custom_link_open_new_tab(smart_annotation_parser(text, team, base64_encoded_imgs, preview_repository)),
link: :urls,
sanitize: false,
html: { target: '_blank' }

View file

@ -3,8 +3,12 @@
module SmartAnnotations
class HtmlPreview
class << self
def html(name, type, object)
send("generate_#{type}_snippet", name, object)
def html(name, type, object, preview_repository = false)
if preview_repository
send('generate_rep_snippet', name, object)
else
send("generate_#{type}_snippet", name, object)
end
end
private
@ -45,6 +49,17 @@ module SmartAnnotations
end
end
def generate_rep_snippet(name, object)
if object&.repository
repository_name = fetch_repository_name(object)
"<a href='#{ROUTES.repository_path(object)}' " \
"><span class='sa-type'>#{trim_repository_name(repository_name)}</span>" \
"#{object.name} #{object.archived? ? I18n.t('atwho.res.archived') : ''}</a>"
else
"<span class='sa-type'>Inv</span> #{name} #{I18n.t('atwho.res.deleted')}"
end
end
def trim_repository_name(name)
splited_name = name.split
size = splited_name.size

View file

@ -4,8 +4,8 @@ module SmartAnnotations
class TagToHtml
attr_reader :html
def initialize(user, team, text)
parse(user, team, text)
def initialize(user, team, text, preview_repository = false)
parse(user, team, text, preview_repository)
end
private
@ -16,7 +16,7 @@ module SmartAnnotations
tsk: MyModule,
rep_item: RepositoryRow }.freeze
def parse(user, team, text)
def parse(user, team, text, preview_repository = false)
@html = text.gsub(REGEX) do |el|
value = extract_values(el)
type = value[:object_type]
@ -24,7 +24,7 @@ module SmartAnnotations
object = fetch_object(type, value[:object_id])
# handle repository_items edge case
if type == 'rep_item'
repository_item(value[:name], user, team, type, object)
repository_item(value[:name], user, team, type, object, preview_repository)
else
next unless object && SmartAnnotations::PermissionEval.check(user,
team,
@ -38,13 +38,13 @@ module SmartAnnotations
end
end
def repository_item(name, user, team, type, object)
def repository_item(name, user, team, type, object, preview_repository)
if object&.repository
return unless SmartAnnotations::PermissionEval.check(user, team, type, object)
return SmartAnnotations::HtmlPreview.html(nil, type, object)
return SmartAnnotations::HtmlPreview.html(nil, type, object, preview_repository)
end
SmartAnnotations::HtmlPreview.html(name, type, object)
SmartAnnotations::HtmlPreview.html(name, type, object, preview_repository)
end
def extract_values(element)

View file

@ -35,7 +35,8 @@
<%= custom_auto_link(step.tinymce_render(:description),
simple_format: false,
tags: %w(img),
team: current_team) %>
team: current_team,
preview_repository: true) %>
</div>
<% end %>
</div>
@ -59,12 +60,12 @@
<% end %>
<% step.tables.each do |table| %>
<strong>
<%= auto_link(simple_format(table.name),
link: :urls,
html: { target: '_blank' }) %>
</strong>
<div class="print-table">
<strong>
<%= auto_link(simple_format(table.name),
link: :urls,
html: { target: '_blank' }) %>
</strong>
<div class="page-break"></div>
<div data-role="hot-table" class="hot-table">
<%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %>