2015-01-22 20:51:35 -05:00
|
|
|
module Projects
|
|
|
|
class AutocompleteService < BaseService
|
|
|
|
def issues
|
2016-08-12 21:17:18 -04:00
|
|
|
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
|
|
|
|
2016-04-04 22:37:50 -04:00
|
|
|
def milestones
|
2017-08-03 13:50:52 -04:00
|
|
|
finder_params = {
|
|
|
|
project_ids: [@project.id],
|
|
|
|
state: :active,
|
|
|
|
order: { due_date: :asc, title: :asc }
|
|
|
|
}
|
|
|
|
|
|
|
|
finder_params[:group_ids] = [@project.group.id] if @project.group
|
|
|
|
|
|
|
|
MilestonesFinder.new(finder_params).execute.select([:iid, :title])
|
2016-04-04 22:37:50 -04:00
|
|
|
end
|
|
|
|
|
2015-01-22 20:51:35 -05:00
|
|
|
def merge_requests
|
2016-08-12 21:17:18 -04:00
|
|
|
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
2016-05-03 07:07:06 -04:00
|
|
|
|
2017-11-27 22:51:03 -05:00
|
|
|
def labels(target = nil)
|
|
|
|
labels = LabelsFinder.new(current_user, project_id: project.id).execute.select([:color, :title])
|
|
|
|
|
|
|
|
return labels unless target&.respond_to?(:labels)
|
|
|
|
|
|
|
|
issuable_label_titles = target.labels.pluck(:title)
|
|
|
|
|
|
|
|
if issuable_label_titles
|
|
|
|
labels = labels.as_json(only: [:title, :color])
|
|
|
|
|
|
|
|
issuable_label_titles.each do |issuable_label_title|
|
|
|
|
found_label = labels.find { |label| label['title'] == issuable_label_title }
|
|
|
|
found_label[:set] = true if found_label
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
labels
|
2016-05-03 07:07:06 -04:00
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
def commands(noteable, type)
|
|
|
|
noteable ||=
|
|
|
|
case type
|
|
|
|
when 'Issue'
|
|
|
|
@project.issues.build
|
|
|
|
when 'MergeRequest'
|
|
|
|
@project.merge_requests.build
|
|
|
|
end
|
2016-08-12 05:19:29 -04:00
|
|
|
|
2017-11-27 22:51:03 -05:00
|
|
|
return [] unless noteable&.is_a?(Issuable)
|
2016-08-12 21:17:18 -04:00
|
|
|
|
2018-02-23 09:23:09 -05:00
|
|
|
QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
|
|
|
end
|