mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-09 17:09:45 +08:00
149 lines
4.2 KiB
Ruby
149 lines
4.2 KiB
Ruby
class SmartAnnotation
|
|
include ActionView::Helpers::SanitizeHelper
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
attr_writer :current_user, :query
|
|
|
|
def initialize(current_user, query)
|
|
@current_user = current_user
|
|
@query = query
|
|
end
|
|
|
|
def resources
|
|
my_modules
|
|
.concat(projects)
|
|
.concat(experiments)
|
|
.concat(samples)
|
|
end
|
|
|
|
private
|
|
|
|
def my_modules
|
|
# Search tasks
|
|
res = MyModule
|
|
.search(@current_user, true, @query)
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
modules_list = []
|
|
res.each do |my_module_res|
|
|
my_mod = {}
|
|
my_mod['id'] = my_module_res.id
|
|
my_mod['name'] = truncate(
|
|
sanitize(my_module_res.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
my_mod['path'] = Rails
|
|
.application
|
|
.routes
|
|
.url_helpers
|
|
.protocols_my_module_path(my_module_res)
|
|
my_mod['archived'] = my_module_res.archived
|
|
my_mod['experimentName'] = truncate(
|
|
sanitize(my_module_res.experiment.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
my_mod['projectName'] = truncate(
|
|
sanitize(my_module_res.experiment.project.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
my_mod['type'] = 'tsk'
|
|
|
|
modules_list << my_mod
|
|
end
|
|
modules_list
|
|
end
|
|
|
|
def projects
|
|
# Search projects
|
|
res = Project
|
|
.search(@current_user, true, @query)
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
projects_list = []
|
|
res.each do |project_res|
|
|
prj = {}
|
|
prj['id'] = project_res.id
|
|
prj['name'] = truncate(
|
|
sanitize(project_res.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
prj['path'] = Rails
|
|
.application
|
|
.routes
|
|
.url_helpers
|
|
.project_path(project_res)
|
|
prj['type'] = 'prj'
|
|
projects_list << prj
|
|
end
|
|
projects_list
|
|
end
|
|
|
|
def experiments
|
|
# Search experiments
|
|
res = Experiment
|
|
.search(@current_user, true, @query)
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
experiments_list = []
|
|
res.each do |experiment_res|
|
|
exp = {}
|
|
exp['id'] = experiment_res.id
|
|
exp['name'] = truncate(
|
|
sanitize(experiment_res.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
exp['path'] = Rails
|
|
.application
|
|
.routes
|
|
.url_helpers
|
|
.canvas_experiment_path(experiment_res)
|
|
exp['type'] = 'exp'
|
|
exp['project'] = truncate(
|
|
sanitize(experiment_res.project.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
experiments_list << exp
|
|
end
|
|
experiments_list
|
|
end
|
|
|
|
def samples
|
|
# Search samples
|
|
res = Sample
|
|
.search(@current_user, true, @query)
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
samples_list = []
|
|
res.each do |sample_res|
|
|
sam = {}
|
|
sam['id'] = sample_res.id
|
|
sam['name'] = truncate(
|
|
sanitize(sample_res.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)
|
|
sam['path'] = Rails
|
|
.application
|
|
.routes
|
|
.url_helpers
|
|
.samples_project_path(sample_res
|
|
.organization
|
|
.projects
|
|
.first)
|
|
sam['description'] = "#{I18n.t('Added')} #{I18n.l(
|
|
sample_res.created_at, format: :full_date
|
|
)} #{I18n.t('by')} #{truncate(
|
|
sanitize(sample_res.user.full_name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)} #{(',' + truncate(
|
|
sanitize(sample_res.sample_type.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)) if sample_res.sample_type}, #{(',' + truncate(
|
|
sanitize(sample_res.sample_group.name,
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
)) if sample_res.sample_group}"
|
|
sam['type'] = 'sam'
|
|
samples_list << sam
|
|
end
|
|
samples_list
|
|
end
|
|
end
|