2020-09-09 20:17:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-05 17:52:00 +08:00
|
|
|
class SmartAnnotation
|
2023-05-05 22:09:14 +08:00
|
|
|
include InputSanitizeHelper
|
2017-01-05 17:52:00 +08:00
|
|
|
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
|
2023-05-03 17:05:29 +08:00
|
|
|
MyModule.search_by_name_and_id(@current_user, @current_team, @query).active
|
2020-09-09 20:17:19 +08:00
|
|
|
.joins(experiment: :project)
|
|
|
|
.where(projects: { archived: false }, experiments: { archived: false })
|
2020-09-11 19:00:13 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
2017-01-05 17:52:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def projects
|
|
|
|
# Search projects
|
2023-05-03 17:05:29 +08:00
|
|
|
Project.search_by_name_and_id(@current_user, @current_team, @query)
|
2020-09-09 20:17:19 +08:00
|
|
|
.where(archived: false)
|
2020-09-11 19:00:13 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
2017-01-05 17:52:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def experiments
|
|
|
|
# Search experiments
|
2023-05-03 17:05:29 +08:00
|
|
|
Experiment.search_by_name_and_id(@current_user, @current_team, @query)
|
2020-09-09 20:17:19 +08:00
|
|
|
.joins(:project)
|
|
|
|
.where(projects: { archived: false }, experiments: { archived: false })
|
2020-09-11 19:00:13 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
2017-01-05 17:52:00 +08:00
|
|
|
end
|
|
|
|
|
2023-04-25 21:12:19 +08:00
|
|
|
def repository_rows(repository, my_module_id)
|
2018-04-03 02:38:56 +08:00
|
|
|
res = RepositoryRow
|
2020-06-16 14:47:48 +08:00
|
|
|
.active
|
2018-04-03 02:38:56 +08:00
|
|
|
.where(repository: repository)
|
2023-05-03 17:05:29 +08:00
|
|
|
.search_by_name_and_id(@current_user, @current_team, @query)
|
2020-09-11 19:00:13 +08:00
|
|
|
.limit(Constants::ATWHO_SEARCH_LIMIT + 1)
|
2023-04-25 21:12:19 +08:00
|
|
|
|
|
|
|
if my_module_id.present?
|
|
|
|
res = res.joins('LEFT OUTER JOIN "my_module_repository_rows" "current_my_module_repository_rows"'\
|
|
|
|
'ON "current_my_module_repository_rows"."repository_row_id" = "repository_rows"."id" '\
|
|
|
|
'AND "current_my_module_repository_rows"."my_module_id" = ' + my_module_id.to_s)
|
2023-05-05 22:09:14 +08:00
|
|
|
.select('repository_rows.*',
|
2023-04-25 21:12:19 +08:00
|
|
|
'CASE WHEN current_my_module_repository_rows.id IS NOT NULL '\
|
|
|
|
'THEN true ELSE false END as row_assigned')
|
|
|
|
end
|
2018-04-03 02:38:56 +08:00
|
|
|
rep_items_list = []
|
2023-05-03 17:07:18 +08:00
|
|
|
|
2018-04-03 02:38:56 +08:00
|
|
|
res.each do |rep_row|
|
|
|
|
rep_item = {}
|
2020-09-04 22:48:53 +08:00
|
|
|
rep_item[:id] = rep_row.id.base62_encode
|
2023-05-03 17:07:18 +08:00
|
|
|
rep_item[:name] = escape_input(rep_row.name)
|
|
|
|
rep_item[:code] = escape_input(rep_row.code)
|
2023-04-25 21:12:19 +08:00
|
|
|
if my_module_id.present?
|
|
|
|
rep_item[:row_assigned] = rep_row&.row_assigned
|
|
|
|
rep_item[:my_module_id] = my_module_id
|
|
|
|
end
|
2018-04-03 02:38:56 +08:00
|
|
|
rep_items_list << rep_item
|
|
|
|
end
|
|
|
|
rep_items_list
|
|
|
|
end
|
2017-01-05 17:52:00 +08:00
|
|
|
end
|