2017-01-05 17:52:00 +08:00
|
|
|
class SmartAnnotation
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
|
2017-01-25 17:24:50 +08:00
|
|
|
attr_writer :current_user, :current_team, :query
|
2017-01-05 17:52:00 +08:00
|
|
|
|
2017-01-25 17:24:50 +08:00
|
|
|
def initialize(current_user, current_team, query)
|
2017-01-05 17:52:00 +08:00
|
|
|
@current_user = current_user
|
2017-01-25 17:24:50 +08:00
|
|
|
@current_team = current_team
|
2017-01-05 17:52:00 +08:00
|
|
|
@query = query
|
|
|
|
end
|
|
|
|
|
|
|
|
def my_modules
|
|
|
|
# Search tasks
|
|
|
|
res = MyModule
|
2017-01-25 17:24:50 +08:00
|
|
|
.search(@current_user, false, @query, 1, @current_team)
|
2017-01-20 00:09:25 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
2017-01-05 17:52:00 +08:00
|
|
|
|
|
|
|
modules_list = []
|
|
|
|
res.each do |my_module_res|
|
|
|
|
my_mod = {}
|
2017-01-11 21:56:47 +08:00
|
|
|
my_mod['id'] = my_module_res.id.base62_encode
|
2017-01-18 23:57:51 +08:00
|
|
|
my_mod['name'] = sanitize(my_module_res.name)
|
2017-01-05 17:52:00 +08:00
|
|
|
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
|
2017-01-25 17:24:50 +08:00
|
|
|
.search(@current_user, false, @query, 1, @current_team)
|
2017-01-20 00:09:25 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
2017-01-05 17:52:00 +08:00
|
|
|
|
|
|
|
projects_list = []
|
|
|
|
res.each do |project_res|
|
|
|
|
prj = {}
|
2017-01-11 21:56:47 +08:00
|
|
|
prj['id'] = project_res.id.base62_encode
|
2017-01-18 23:57:51 +08:00
|
|
|
prj['name'] = sanitize(project_res.name)
|
2017-01-05 17:52:00 +08:00
|
|
|
prj['type'] = 'prj'
|
|
|
|
projects_list << prj
|
|
|
|
end
|
|
|
|
projects_list
|
|
|
|
end
|
|
|
|
|
|
|
|
def experiments
|
|
|
|
# Search experiments
|
|
|
|
res = Experiment
|
2017-01-25 17:24:50 +08:00
|
|
|
.search(@current_user, false, @query, 1, @current_team)
|
2017-01-20 00:09:25 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
2017-01-05 17:52:00 +08:00
|
|
|
|
|
|
|
experiments_list = []
|
|
|
|
res.each do |experiment_res|
|
|
|
|
exp = {}
|
2017-01-11 21:56:47 +08:00
|
|
|
exp['id'] = experiment_res.id.base62_encode
|
2017-01-18 23:57:51 +08:00
|
|
|
exp['name'] = sanitize(experiment_res.name)
|
2017-01-05 17:52:00 +08:00
|
|
|
exp['type'] = 'exp'
|
2017-01-10 21:13:37 +08:00
|
|
|
exp['projectName'] = truncate(
|
2017-01-05 17:52:00 +08:00
|
|
|
sanitize(experiment_res.project.name,
|
|
|
|
length: Constants::NAME_TRUNCATION_LENGTH)
|
|
|
|
)
|
|
|
|
experiments_list << exp
|
|
|
|
end
|
|
|
|
experiments_list
|
|
|
|
end
|
|
|
|
|
|
|
|
def samples
|
|
|
|
# Search samples
|
|
|
|
res = Sample
|
2017-01-25 17:24:50 +08:00
|
|
|
.search(@current_user, false, @query, 1, @current_team)
|
2017-01-20 00:09:25 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
2017-01-05 17:52:00 +08:00
|
|
|
|
|
|
|
samples_list = []
|
|
|
|
res.each do |sample_res|
|
|
|
|
sam = {}
|
2017-01-11 21:56:47 +08:00
|
|
|
sam['id'] = sample_res.id.base62_encode
|
2017-01-18 23:57:51 +08:00
|
|
|
sam['name'] = sanitize(sample_res.name)
|
2017-01-05 17:52:00 +08:00
|
|
|
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)
|
2017-01-18 21:46:53 +08:00
|
|
|
)}"
|
2017-01-05 17:52:00 +08:00
|
|
|
sam['type'] = 'sam'
|
|
|
|
samples_list << sam
|
|
|
|
end
|
|
|
|
samples_list
|
|
|
|
end
|
2018-04-03 02:38:56 +08:00
|
|
|
|
|
|
|
def repository_rows(repository)
|
|
|
|
res = RepositoryRow
|
|
|
|
.where(repository: repository)
|
2018-07-06 20:26:20 +08:00
|
|
|
.where_attributes_like('name', @query, at_search: true)
|
2018-04-03 02:38:56 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
|
|
|
rep_items_list = []
|
|
|
|
splitted_name = repository.name.gsub(/[^0-9a-z ]/i, '').split
|
|
|
|
repository_tag =
|
|
|
|
case splitted_name.length
|
|
|
|
when 1
|
|
|
|
splitted_name[0][0..2]
|
|
|
|
when 2
|
|
|
|
if splitted_name[0].length == 1
|
|
|
|
splitted_name[0][0] + splitted_name[1][0..1]
|
|
|
|
else
|
|
|
|
splitted_name[0][0..1] + splitted_name[1][0]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
splitted_name[0][0] + splitted_name[1][0] + splitted_name[2][0]
|
|
|
|
end
|
|
|
|
repository_tag.downcase!
|
|
|
|
res.each do |rep_row|
|
|
|
|
rep_item = {}
|
|
|
|
rep_item['id'] = rep_row.id.base62_encode
|
|
|
|
rep_item['name'] = sanitize(rep_row.name)
|
|
|
|
rep_item['repository_tag'] = repository_tag
|
|
|
|
rep_item['type'] = 'rep_item'
|
|
|
|
rep_items_list << rep_item
|
|
|
|
end
|
|
|
|
rep_items_list
|
|
|
|
end
|
2017-01-05 17:52:00 +08:00
|
|
|
end
|