Added recent created users per default.

This commit is contained in:
Martin Edenhofer 2015-06-10 01:57:22 +02:00
parent 73242cd4b8
commit 7258122455
5 changed files with 96 additions and 6 deletions

View file

@ -30,8 +30,10 @@ class Index extends App.Controller
e.preventDefault()
$(e.target).toggleClass('active')
term = @searchInput.val().trim()
return if !term
@delay( @search, 220, 'search' )
if term
@delay( @search, 220, 'search' )
return
@recent()
)
# start search
@ -43,6 +45,9 @@ class Index extends App.Controller
@delay( @search, 220, 'search' )
)
# show last 20 users
@recent()
renderResult: (user_ids = []) ->
callbackHeader = (header) ->
@ -137,6 +142,28 @@ class Index extends App.Controller
@renderResult(data.user_ids)
)
recent: =>
role_ids = []
@$('.tab.active').each( (i,d) ->
role_ids.push $(d).data('id')
)
App.Ajax.request(
id: 'search'
type: 'GET'
url: @apiPath + '/users/recent'
data:
limit: 40
role_ids: role_ids
full: 1
processData: true,
success: (data, status, xhr) =>
# load assets
App.Collection.loadAssets( data.assets )
@renderResult(data.user_ids)
)
new: (e) ->
e.preventDefault()
new App.ControllerGenericNew(

View file

@ -126,15 +126,15 @@
</div>
<div class="tabs tabs-wide horizontal">
<div class="tab active" data-id="1">
<div class="tab" data-id="1">
Admin
</div>
<div class="tab active" data-id="2">
<div class="tab" data-id="2">
Agent
</div>
<div class="tab active" data-id="3">
<div class="tab" data-id="3">
Customer
</div>
</div>

View file

@ -20,7 +20,7 @@
<div class="userSearch-label"><%- @T('Roles') %>:</div>
<div class="tabs tabs-wide horizontal">
<% for role in @roles: %>
<div class="tab active" data-id="<%= role.id %>"><%- @T(role.displayName() ) %></div>
<div class="tab" data-id="<%= role.id %>"><%- @T(role.displayName() ) %></div>
<% end %>
</div>
</div>

View file

@ -308,6 +308,68 @@ class UsersController < ApplicationController
}
end
# @path [GET] /users/recent
#
# @tag Search
# @tag User
#
# @summary Recent creates Users.
# @notes Recent creates Users.
#
# @parameter limit [Integer] The limit of search results.
# @parameter role_ids(multi) [Array<String>] A list of Role identifiers to which the Users have to be allocated to.
# @parameter full [Boolean] Defines if the result should be
# true: { user_ids => [1,2,...], assets => {...} }
# or false: [{:id => user.id, :label => "firstname lastname <email>", :value => "firstname lastname <email>"},...].
#
# @response_message 200 [Array<User>] A list of User records matching the search term.
# @response_message 401 Invalid session.
def recent
if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN)
response_access_deny
return
end
# do query
if params[:role_ids] && !params[:role_ids].empty?
user_all = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 )
else
user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 )
end
# build result list
if !params[:full]
users = []
user_all.each { |user|
realname = user.firstname.to_s + ' ' + user.lastname.to_s
if user.email && user.email.to_s != ''
realname = realname + ' <' + user.email.to_s + '>'
end
a = { id: user.id, label: realname, value: realname }
users.push a
}
# return result
render json: users
return
end
user_ids = []
assets = {}
user_all.each { |user|
assets = user.assets(assets)
user_ids.push user.id
}
# return result
render json: {
assets: assets,
user_ids: user_ids.uniq,
}
end
# @path [GET] /users/history/{id}
#
# @tag History

View file

@ -3,6 +3,7 @@ Zammad::Application.routes.draw do
# users
match api_path + '/users/search', to: 'users#search', via: [:get, :post]
match api_path + '/users/recent', to: 'users#recent', via: [:get, :post]
match api_path + '/users/password_reset', to: 'users#password_reset_send', via: :post
match api_path + '/users/password_reset_verify', to: 'users#password_reset_verify', via: :post
match api_path + '/users/password_change', to: 'users#password_change', via: :post