2015-04-26 12:48:37 +05:30
|
|
|
module Projects
|
|
|
|
class AutocompleteService < BaseService
|
2016-06-02 11:05:42 +05:30
|
|
|
def issues
|
2016-09-13 17:45:13 +05:30
|
|
|
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def milestones
|
2017-09-10 17:25:29 +05:30
|
|
|
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])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests
|
2016-09-13 17:45:13 +05:30
|
|
|
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
def labels
|
2016-11-03 12:29:30 +05:30
|
|
|
LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
def commands(noteable, type)
|
|
|
|
noteable ||=
|
|
|
|
case type
|
|
|
|
when 'Issue'
|
|
|
|
@project.issues.build
|
|
|
|
when 'MergeRequest'
|
|
|
|
@project.merge_requests.build
|
|
|
|
end
|
|
|
|
|
|
|
|
return [] unless noteable && noteable.is_a?(Issuable)
|
|
|
|
|
|
|
|
opts = {
|
|
|
|
project: project,
|
|
|
|
issuable: noteable,
|
|
|
|
current_user: current_user
|
|
|
|
}
|
2017-09-10 17:25:29 +05:30
|
|
|
QuickActions::InterpretService.command_definitions.map do |definition|
|
2016-09-13 17:45:13 +05:30
|
|
|
next unless definition.available?(opts)
|
|
|
|
|
|
|
|
definition.to_h(opts)
|
|
|
|
end.compact
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|