2016-02-12 23:52:43 +08:00
|
|
|
module ApplicationHelper
|
2016-07-29 21:47:41 +08:00
|
|
|
def module_page?
|
|
|
|
controller_name == 'my_modules'
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-29 21:47:41 +08:00
|
|
|
def experiment_page?
|
|
|
|
controller_name == 'experiments'
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2016-07-29 21:47:41 +08:00
|
|
|
def project_page?
|
|
|
|
controller_name == 'projects' ||
|
|
|
|
(controller_name == 'reports' && action_name == 'index')
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
2016-12-14 20:36:10 +08:00
|
|
|
|
|
|
|
def display_tooltip(message, len = Constants::NAME_TRUNCATION_LENGTH)
|
|
|
|
if message.strip.length > Constants::NAME_TRUNCATION_LENGTH
|
|
|
|
"<div class='modal-tooltip'>#{truncate(message.strip, length: len)} \
|
|
|
|
<span class='modal-tooltiptext'>#{message.strip}</span></div>".html_safe
|
|
|
|
else
|
|
|
|
truncate(message.strip, length: len)
|
|
|
|
end
|
|
|
|
end
|
2016-12-15 00:05:00 +08:00
|
|
|
|
2016-12-12 17:30:03 +08:00
|
|
|
def sample_types_page_project?
|
2016-12-14 17:35:48 +08:00
|
|
|
controller_name == 'sample_types' &&
|
|
|
|
@my_module.nil? &&
|
|
|
|
@experiment.nil?
|
2016-12-12 17:30:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sample_groups_page_project?
|
2016-12-14 17:35:48 +08:00
|
|
|
controller_name == 'sample_groups' &&
|
|
|
|
@my_module.nil? &&
|
|
|
|
@experiment.nil?
|
2016-12-12 17:30:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sample_types_page_my_module?
|
2016-12-14 17:35:48 +08:00
|
|
|
controller_name == 'sample_types' && !@my_module.nil?
|
2016-12-12 17:30:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def sample_groups_page_my_module?
|
2016-12-14 17:35:48 +08:00
|
|
|
controller_name == 'sample_groups' && !@my_module.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def sample_groups_page_experiment?
|
|
|
|
controller_name == 'sample_groups' &&
|
|
|
|
@my_module.nil? &&
|
|
|
|
!@experiment.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def sample_types_page_expermient?
|
|
|
|
controller_name == 'sample_types' &&
|
|
|
|
@my_module.nil? &&
|
|
|
|
!@experiment.nil?
|
2016-12-12 17:30:03 +08:00
|
|
|
end
|
2017-01-10 00:16:39 +08:00
|
|
|
|
|
|
|
def smart_annotation_parser(text)
|
2017-01-11 21:56:47 +08:00
|
|
|
sa_reg = /\[\#(.*?)~(prj|exp|tsk|sam)~([0-9a-zA-Z]+)\]/
|
2017-01-11 00:05:32 +08:00
|
|
|
new_text = text.gsub(sa_reg) do |el|
|
2017-01-10 00:16:39 +08:00
|
|
|
match = el.match(sa_reg)
|
2017-01-11 00:05:32 +08:00
|
|
|
case match[2]
|
|
|
|
when 'prj'
|
2017-01-11 21:56:47 +08:00
|
|
|
project = Project.find_by_id(match[3].base62_decode)
|
2017-01-11 17:34:14 +08:00
|
|
|
next unless project
|
|
|
|
if project.archived?
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to project.name,
|
|
|
|
projects_archive_path} #{t'atwho.res.archived'}"
|
|
|
|
else
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to project.name,
|
|
|
|
project_path(project)}"
|
|
|
|
end
|
2017-01-11 00:05:32 +08:00
|
|
|
when 'exp'
|
2017-01-11 21:56:47 +08:00
|
|
|
experiment = Experiment.find_by_id(match[3].base62_decode)
|
2017-01-11 17:34:14 +08:00
|
|
|
next unless experiment
|
|
|
|
if experiment.archived?
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to experiment.name,
|
|
|
|
experiment_archive_project_path(experiment.project)} " \
|
|
|
|
"#{t'atwho.res.archived'}"
|
|
|
|
else
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to experiment.name,
|
|
|
|
canvas_experiment_path(experiment)}"
|
|
|
|
end
|
2017-01-11 00:05:32 +08:00
|
|
|
when 'tsk'
|
2017-01-11 21:56:47 +08:00
|
|
|
my_module = MyModule.find_by_id(match[3].base62_decode)
|
2017-01-11 17:34:14 +08:00
|
|
|
next unless my_module
|
|
|
|
if my_module.archived?
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to my_module.name,
|
|
|
|
module_archive_experiment_path(my_module.experiment)}" \
|
|
|
|
"#{t'atwho.res.archived'}"
|
|
|
|
else
|
|
|
|
"<span class='sa-type'>#{sanitize(match[2])}</span> " \
|
|
|
|
"#{link_to my_module.name,
|
|
|
|
protocols_my_module_path(my_module)}"
|
|
|
|
end
|
2017-01-11 00:05:32 +08:00
|
|
|
when 'sam'
|
2017-01-11 21:56:47 +08:00
|
|
|
sample = Sample.find_by_id(match[3].base62_decode)
|
2017-01-11 00:05:32 +08:00
|
|
|
if sample
|
2017-01-11 17:34:14 +08:00
|
|
|
"<span class='glyphicon glyphicon-tint'></span> " \
|
|
|
|
"#{link_to sample.name,
|
|
|
|
samples_project_path(sample
|
|
|
|
.organization
|
|
|
|
.projects
|
|
|
|
.first)}"
|
|
|
|
else
|
|
|
|
"<span class='glyphicon glyphicon-tint'></span> " \
|
|
|
|
"#{match[1]} #{t'atwho.res.deleted'}"
|
2017-01-10 00:16:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-01-11 00:05:32 +08:00
|
|
|
|
2017-01-11 21:56:47 +08:00
|
|
|
sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/
|
2017-01-11 00:05:32 +08:00
|
|
|
new_text = new_text.gsub(sa_user) do |el|
|
|
|
|
match = el.match(sa_user)
|
2017-01-11 21:56:47 +08:00
|
|
|
user = User.find_by_id(match[2].base62_decode)
|
|
|
|
if user
|
|
|
|
"<span>#{image_tag avatar_path(user, :icon_small)} " \
|
|
|
|
"#{user.full_name}</span>"
|
|
|
|
end
|
2017-01-11 00:05:32 +08:00
|
|
|
end
|
|
|
|
new_text
|
2017-01-10 00:16:39 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|