2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2012-01-03 23:36:40 +04:00
|
|
|
# Copyright (C) 2010-2012 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
class AutoCompletesController < ApplicationController
|
2010-12-04 00:59:23 +03:00
|
|
|
before_filter :find_project, :only => :issues
|
2009-10-20 23:28:07 +04:00
|
|
|
before_filter :require_admin, :only => :projects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
def issues
|
|
|
|
@issues = []
|
|
|
|
q = params[:q].to_s
|
2011-05-04 21:12:56 +04:00
|
|
|
|
|
|
|
if q.present?
|
|
|
|
query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues
|
|
|
|
|
|
|
|
@issues |= query.visible.find_all_by_id(q.to_i) if q =~ /^\d+$/
|
|
|
|
|
|
|
|
@issues |= query.visible.find(:all,
|
2011-03-14 03:11:04 +03:00
|
|
|
:limit => 10,
|
|
|
|
:order => "#{Issue.table_name}.id ASC",
|
|
|
|
:conditions => ["LOWER(#{Issue.table_name}.subject) LIKE :q OR CAST(#{Issue.table_name}.id AS CHAR(13)) LIKE :q", {:q => "%#{q.downcase}%" }])
|
2010-08-17 19:03:58 +04:00
|
|
|
end
|
2011-05-04 21:12:56 +04:00
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
2010-12-04 00:59:23 +03:00
|
|
|
def users
|
2010-12-04 01:08:52 +03:00
|
|
|
if params[:remove_group_members].present?
|
|
|
|
@group = Group.find(params[:remove_group_members])
|
|
|
|
@removed_users = @group.users
|
|
|
|
end
|
2010-12-04 01:56:29 +03:00
|
|
|
|
|
|
|
if params[:remove_watchers].present? && params[:klass].present?
|
|
|
|
watcher_class = params[:klass].constantize
|
|
|
|
if watcher_class.included_modules.include?(Redmine::Acts::Watchable) # check class is a watching class
|
|
|
|
@object = watcher_class.find(params[:remove_watchers])
|
|
|
|
@removed_users = @object.watcher_users
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@removed_users ||= []
|
2011-04-19 23:03:55 +04:00
|
|
|
|
|
|
|
if params[:include_groups]
|
|
|
|
user_finder = Principal
|
|
|
|
else
|
|
|
|
user_finder = User
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2011-04-19 23:03:55 +04:00
|
|
|
@users = user_finder.active.like(params[:q]).find(:all, :limit => 100) - @removed_users
|
2010-12-04 00:59:23 +03:00
|
|
|
render :layout => false
|
|
|
|
end
|
2009-10-20 23:28:07 +04:00
|
|
|
|
|
|
|
def projects
|
|
|
|
@principal = Principal.find(params[:id])
|
|
|
|
@projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @principal.projects
|
|
|
|
render :layout => false
|
|
|
|
end
|
2012-01-18 22:26:03 +04:00
|
|
|
|
2010-08-17 19:03:58 +04:00
|
|
|
private
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
|
|
|
|
@project = Project.find(project_id)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|