debian-mirror-gitlab/app/services/projects/autocomplete_service.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

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 }
}
2018-11-08 19:23:39 +05:30
finder_params[:group_ids] = @project.group.self_and_ancestors_ids if @project.group
2017-09-10 17:25:29 +05:30
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
2018-11-08 19:23:39 +05:30
def labels_as_hash(target = nil)
available_labels = LabelsFinder.new(
current_user,
project_id: project.id,
include_ancestor_groups: true
).execute
label_hashes = available_labels.as_json(only: [:title, :color])
if target&.respond_to?(:labels)
already_set_labels = available_labels & target.labels
if already_set_labels.present?
titles = already_set_labels.map(&:title)
label_hashes.each do |hash|
if titles.include?(hash['title'])
hash[:set] = true
end
end
2018-03-17 18:26:18 +05:30
end
end
2018-11-08 19:23:39 +05:30
label_hashes
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
2018-03-17 18:26:18 +05:30
return [] unless noteable&.is_a?(Issuable)
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
2016-09-13 17:45:13 +05:30
end
2015-04-26 12:48:37 +05:30
end
end