2012-10-02 17:54:55 +01:00
|
|
|
class AutocompletesController < ApplicationController
|
2015-03-19 23:31:41 +00:00
|
|
|
before_action :authenticate_user!
|
|
|
|
skip_after_action :verify_authorized
|
2012-10-02 17:54:55 +01:00
|
|
|
|
2014-11-10 22:21:48 +00:00
|
|
|
def autocomplete_user_uname
|
|
|
|
results = User.opened.search(params[:query]).search_order.limit(5)
|
|
|
|
render json: results.map{ |u| { id: u.id, name: u.uname } }
|
|
|
|
end
|
2013-06-04 20:59:08 +01:00
|
|
|
|
2014-10-21 21:56:36 +01:00
|
|
|
def autocomplete_user_or_group
|
2014-11-10 22:21:48 +00:00
|
|
|
results << User.opened.search(params[:query]).search_order.limit(5).pluck(:uname)
|
|
|
|
results << Group.search(params[:query]).search_order.limit(5).pluck(:uname)
|
|
|
|
render json: results.flatten.sort.map{ |r| { id: r, name: r } }
|
2014-10-21 21:56:36 +01:00
|
|
|
end
|
|
|
|
|
2013-06-04 20:59:08 +01:00
|
|
|
def autocomplete_extra_build_list
|
2015-03-19 23:31:41 +00:00
|
|
|
bl = BuildListPolicy::Scope.new(current_user, BuildList).read.
|
|
|
|
for_extra_build_lists(params[:term], save_to_platform).first
|
2013-06-04 20:59:08 +01:00
|
|
|
results << { :id => bl.id,
|
|
|
|
:value => bl.id,
|
|
|
|
:label => "#{bl.id} (#{bl.project.name} - #{bl.arch.name})",
|
|
|
|
:path => build_list_path(bl)
|
|
|
|
} if bl
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
|
|
|
|
2014-06-27 20:08:14 +01:00
|
|
|
def autocomplete_extra_mass_build
|
|
|
|
mb = MassBuild.where(id: params[:term]).first
|
|
|
|
results << {
|
|
|
|
id: mb.id,
|
|
|
|
value: mb.id,
|
|
|
|
label: "#{mb.id} - #{mb.name}",
|
|
|
|
path: platform_mass_build_path(mb.save_to_platform, mb)
|
2015-03-14 22:10:04 +00:00
|
|
|
} if mb && policy(mb).show?
|
2014-06-27 20:08:14 +01:00
|
|
|
render json: results.to_json
|
|
|
|
end
|
|
|
|
|
2013-06-04 20:59:08 +01:00
|
|
|
def autocomplete_extra_repositories
|
2013-08-02 13:53:56 +01:00
|
|
|
# Only personal and build for platform repositories can be attached to the build
|
2015-04-07 20:43:40 +01:00
|
|
|
platforms = PlatformPolicy::Scope.new(current_user, Platform).show.
|
2015-03-19 23:31:41 +00:00
|
|
|
includes(:repositories).search(params[:term]).search_order.limit(5).
|
|
|
|
where("platforms.platform_type = 'personal' OR platforms.id = ?", params[:build_for_platform_id])
|
|
|
|
platforms.each do |platform|
|
2013-06-04 20:59:08 +01:00
|
|
|
platform.repositories.each do |repository|
|
2014-10-25 08:29:34 +01:00
|
|
|
results <<
|
|
|
|
{
|
|
|
|
id: repository.id,
|
|
|
|
platform_name: platform.name,
|
|
|
|
repository_name: repository.name,
|
|
|
|
label: "#{platform.name}/#{repository.name}",
|
|
|
|
path: platform_repository_path(platform, repository)
|
|
|
|
}
|
2013-06-04 20:59:08 +01:00
|
|
|
end
|
|
|
|
end if save_to_platform.personal?
|
|
|
|
render json: results.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def save_to_platform
|
2015-03-19 23:31:41 +00:00
|
|
|
@save_to_platform ||= Platform.find_cached(params[:platform_id])
|
2013-06-04 20:59:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def results
|
|
|
|
@results ||= []
|
|
|
|
end
|
|
|
|
|
2012-10-02 17:54:55 +01:00
|
|
|
end
|