mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 21:55:20 +08:00
Truncate activity taking smart annotations into account fixes [SCI-1249]
This commit is contained in:
parent
58e2575c75
commit
e781dfc6a6
3 changed files with 35 additions and 23 deletions
|
@ -290,7 +290,8 @@ class StepsController < ApplicationController
|
|||
"activities.uncheck_step_checklist_item"
|
||||
completed_items = chkItem.checklist.checklist_items.where(checked: true).count
|
||||
all_items = chkItem.checklist.checklist_items.count
|
||||
text_activity = chkItem.text.gsub(/\s+/, ' ')
|
||||
text_activity = smart_annotation_parser(chkItem.text)
|
||||
.gsub(/\s+/, ' ')
|
||||
message = t(
|
||||
str,
|
||||
user: current_user.full_name,
|
||||
|
|
|
@ -1,31 +1,42 @@
|
|||
module ActivityHelper
|
||||
TAGS_LENGTH = 4
|
||||
TRUNCATE_OFFSET = 3
|
||||
def activity_truncate(message, len = Constants::NAME_TRUNCATION_LENGTH)
|
||||
activity_titles = message.scan(/<strong>(.*?)<\/strong>/)
|
||||
activity_titles.each do |activity_title|
|
||||
activity_title = activity_title[0]
|
||||
unless activity_title.length == smart_annotation_parser(activity_title)
|
||||
.length
|
||||
temp = activity_title.index('[')
|
||||
while !temp.nil? && temp < len
|
||||
if activity_title[temp + 1] == '#' || activity_title[temp + 1] == '@'
|
||||
last_sa = activity_title.index(']', temp)
|
||||
end
|
||||
temp = activity_title.index('[', last_sa)
|
||||
len = last_sa if last_sa > len
|
||||
end
|
||||
len += 4
|
||||
closing = activity_title.index('</a>')
|
||||
unless closing.nil?
|
||||
ind = activity_title.index('<img')
|
||||
ind_temp = activity_title.index('<span')
|
||||
ind = ind_temp if ind.nil? || ind > ind_temp
|
||||
end
|
||||
temp = len
|
||||
while !ind.nil? && !closing.nil? && ind < temp
|
||||
stripped = strip_tags(activity_title[ind...closing]).length
|
||||
temp += (activity_title[ind...closing + TAGS_LENGTH]).length - stripped
|
||||
len = temp + TRUNCATE_OFFSET + TAGS_LENGTH if len <= closing
|
||||
closing_temp = closing + 1
|
||||
closing = activity_title.index('</a>', closing_temp)
|
||||
unless closing.nil?
|
||||
ind = activity_title.index('<img', closing_temp)
|
||||
ind_temp = activity_title.index('<span', closing_temp)
|
||||
ind = ind_temp if ind.nil? || ind > ind_temp
|
||||
end
|
||||
end
|
||||
len = activity_title.length if len > activity_title.length &&
|
||||
len != Constants::NAME_TRUNCATION_LENGTH
|
||||
if activity_title.length > len
|
||||
title = "<div class='modal-tooltip'>
|
||||
#{truncate(activity_title, length: len)}
|
||||
#{truncate(activity_title, length: len, escape: false)}
|
||||
<span class='modal-tooltiptext'>
|
||||
#{activity_title}
|
||||
</span>
|
||||
</div>"
|
||||
else
|
||||
title = truncate(activity_title, length: len)
|
||||
title = truncate(activity_title, length: len, escape: false)
|
||||
end
|
||||
message = smart_annotation_parser(message.gsub(/#{Regexp.escape(activity_title)}/, title))
|
||||
message = message.gsub(/#{Regexp.escape(activity_title)}/, title)
|
||||
end
|
||||
sanitize_input(message) if message
|
||||
end
|
||||
|
|
|
@ -126,12 +126,12 @@ module ApplicationHelper
|
|||
next unless project
|
||||
if project.archived?
|
||||
"<span class='sa-type'>" \
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to project.name,
|
||||
projects_archive_path} #{I18n.t('atwho.res.archived')}"
|
||||
else
|
||||
"<span class='sa-type'>" \
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to project.name,
|
||||
project_path(project)}"
|
||||
end
|
||||
|
@ -140,13 +140,13 @@ module ApplicationHelper
|
|||
next unless experiment
|
||||
if experiment.archived?
|
||||
"<span class='sa-type'>" \
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to experiment.name,
|
||||
experiment_archive_project_path(experiment.project)} " \
|
||||
"#{I18n.t('atwho.res.archived')}"
|
||||
else
|
||||
"<span class='sa-type'>"\
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to experiment.name,
|
||||
canvas_experiment_path(experiment)}"
|
||||
end
|
||||
|
@ -155,25 +155,25 @@ module ApplicationHelper
|
|||
next unless my_module
|
||||
if my_module.archived?
|
||||
"<span class='sa-type'>" \
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to my_module.name,
|
||||
module_archive_experiment_path(my_module.experiment)} " \
|
||||
"#{I18n.t('atwho.res.archived')}"
|
||||
else
|
||||
"<span class='sa-type'>" \
|
||||
"#{sanitize_input(match[2])}</span> " \
|
||||
"#{sanitize_input(match[2])}</span>" \
|
||||
"#{link_to my_module.name,
|
||||
protocols_my_module_path(my_module)}"
|
||||
end
|
||||
when 'sam'
|
||||
sample = Sample.find_by_id(match[3].base62_decode)
|
||||
if sample
|
||||
"<span class='glyphicon glyphicon-tint'></span> " \
|
||||
"<span class='glyphicon glyphicon-tint'></span>" \
|
||||
"#{link_to(sample.name,
|
||||
sample_path(sample.id),
|
||||
class: 'sample-info-link')}"
|
||||
else
|
||||
"<span class='glyphicon glyphicon-tint'></span> " \
|
||||
"<span class='glyphicon glyphicon-tint'></span>" \
|
||||
"#{match[1]} #{I18n.t('atwho.res.deleted')}"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue