Add helper function for auto_complete
This commit is contained in:
parent
4ee6fa2993
commit
5cc93f6c02
@ -1,4 +1,17 @@
|
||||
module AdditionalsQueryHelper
|
||||
def additionals_select2_search_users(where_filter = '', where_params = {})
|
||||
q = params[:q].to_s.strip
|
||||
exclude_id = params[:user_id].to_i
|
||||
scope = User.active.where(type: 'User')
|
||||
scope = scope.where.not(id: exclude_id) if exclude_id > 0
|
||||
scope = scope.where(where_filter, where_params) if where_filter.present?
|
||||
scope = scope.like(q) if q.present?
|
||||
scope = scope.order(last_login_on: :desc)
|
||||
.limit(params[:limit] || Additionals::SELECT2_INIT_ENTRIES)
|
||||
@users = scope.to_a.sort! { |x, y| x.name <=> y.name }
|
||||
render layout: false, partial: 'users'
|
||||
end
|
||||
|
||||
def query_to_xls(items, query, options = {})
|
||||
require 'spreadsheet'
|
||||
Spreadsheet.client_encoding = options[:encoding].presence || 'UTF-8'
|
||||
|
9
app/views/auto_completes/_users.html.erb
Normal file
9
app/views/auto_completes/_users.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<%= raw @users.map { |user| {
|
||||
'id' => user.id,
|
||||
'text' => user.name,
|
||||
'name' => user.name,
|
||||
'name_with_icon' => user_with_avatar(user, no_link: true),
|
||||
'value' => user.id
|
||||
}
|
||||
}.to_json
|
||||
%>
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class AdditionalsFontAwesomeTest < ActiveSupport::TestCase
|
||||
class AdditionalsFontAwesomeTest < Redmine::HelperTest
|
||||
fixtures :projects, :users, :members, :member_roles, :roles,
|
||||
:trackers, :projects_trackers,
|
||||
:enabled_modules,
|
||||
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path('../../../test_helper', __FILE__)
|
||||
|
||||
class GlobalHelperTest < ActionView::TestCase
|
||||
class GlobalHelperTest < Redmine::HelperTest
|
||||
include ApplicationHelper
|
||||
include Additionals::Helpers
|
||||
include CustomFieldsHelper
|
||||
|
@ -1,7 +1,7 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Redmine
|
||||
class I18nTest < ActiveSupport::TestCase
|
||||
class I18nTest < Redmine::HelperTest
|
||||
include Redmine::I18n
|
||||
|
||||
def setup
|
||||
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class IssueTest < ActiveSupport::TestCase
|
||||
class IssueTest < Redmine::HelperTest
|
||||
fixtures :projects, :users, :members, :member_roles, :roles,
|
||||
:trackers, :projects_trackers,
|
||||
:enabled_modules,
|
||||
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class TimeEntryTest < ActiveSupport::TestCase
|
||||
class TimeEntryTest < Redmine::HelperTest
|
||||
fixtures :issues, :projects, :users, :time_entries,
|
||||
:members, :roles, :member_roles,
|
||||
:trackers, :issue_statuses,
|
||||
|
@ -1,6 +1,6 @@
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class WatcherTest < ActiveSupport::TestCase
|
||||
class WatcherTest < Redmine::HelperTest
|
||||
fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :enabled_modules,
|
||||
:issues, :issue_statuses, :enumerations, :trackers, :projects_trackers,
|
||||
:boards, :messages,
|
||||
|
Loading…
Reference in New Issue
Block a user