First version of user and organisation zoom.

This commit is contained in:
Martin Edenhofer 2014-08-18 13:49:08 +02:00
parent a0c15166ae
commit 5581324823
9 changed files with 328 additions and 35 deletions

View file

@ -0,0 +1,132 @@
class App.DashboardTicketSearch extends App.Controller
events:
'click [data-type=page]': 'page'
constructor: ->
super
@start_page = 1
@navupdate '#'
# render
@fetch()
fetch: (force) =>
@ajax(
id: 'dashboard_ticket_search' + @name,
type: 'GET',
url: @apiPath + '/tickets/search',
data:
condition: @condition
order: @order
detail: true
limit: 200
processData: true,
success: (data) =>
@load( data, true )
)
load: (data = false, ajax = false) =>
if ajax
App.Store.write( 'dashboard_ticket_search' + @name, data )
# load assets
App.Collection.loadAssets( data.assets )
@render( data )
else
data = App.Store.get( 'dashboard_ticket_search' + @name )
if data
@render( data )
render: (data) ->
return if !data
return if !data.tickets
@overview =
name: @name
@tickets_count = data.tickets_count
@ticket_ids = data.tickets
per_page = @per_page || 5
pages_total = parseInt( ( @tickets_count / per_page ) + 0.99999 ) || 1
html = App.view('dashboard/ticket')(
overview: @overview,
pages_total: pages_total,
start_page: @start_page,
)
html = $(html)
html.find('li').removeClass('active')
html.find(".page [data-id=\"#{@start_page}\"]").parents('li').addClass('active')
@tickets_in_table = []
start = ( @start_page-1 ) * 5
end = ( @start_page ) * 5
i = start
while i < end
i = i + 1
if @ticket_ids[ i - 1 ]
@tickets_in_table.push App.Ticket.fullLocal( @ticket_ids[ i - 1 ] )
openTicket = (id,e) =>
ticket = App.Ticket.fullLocal(id)
@navigate ticket.uiUrl()
callbackTicketTitleAdd = (value, object, attribute, attributes, refObject) =>
attribute.title = object.title
value
callbackLinkToTicket = (value, object, attribute, attributes, refObject) =>
attribute.link = object.uiUrl()
value
callbackResetLink = (value, object, attribute, attributes, refObject) =>
attribute.link = undefined
value
callbackUserPopover = (value, object, attribute, attributes, refObject) =>
attribute.class = 'user-popover'
attribute.data =
id: refObject.id
value
new App.ControllerTable(
overview: @view.d
el: html.find('.table-overview'),
model: App.Ticket
objects: @tickets_in_table,
checkbox: false
groupBy: @group_by
bindRow:
events:
'click': openTicket
callbackAttributes:
customer_id:
[ callbackResetLink, callbackUserPopover ]
owner_id:
[ callbackResetLink, callbackUserPopover ]
title:
[ callbackLinkToTicket, callbackTicketTitleAdd ]
number:
[ callbackLinkToTicket, callbackTicketTitleAdd ]
)
@html html
# show frontend times
@frontendTimeUpdate()
# start user popups
@userPopups()
zoom: (e) =>
e.preventDefault()
id = $(e.target).parents('[data-id]').data('id')
@navigate 'ticket/zoom/' + id
page: (e) =>
e.preventDefault()
id = $(e.target).data('id')
@start_page = id
@load()

View file

@ -38,6 +38,11 @@ class App.OrganizationZoom extends App.Controller
organization: organization organization: organization
) )
new Overviews(
el: @el
organization: organization
)
new App.UpdateTastbar( new App.UpdateTastbar(
genericObject: organization genericObject: organization
) )
@ -60,6 +65,55 @@ class App.OrganizationZoom extends App.Controller
ui: @ ui: @
) )
class Overviews extends App.Controller
constructor: ->
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = App.Organization.full( @organization.id, @render, false, true )
release: =>
App.Organization.unsubscribe(@subscribeId)
render: (organization) =>
plugins =
main:
my_organization:
controller: App.DashboardTicketSearch,
params:
name: 'Tickets of Organization'
condition:
'tickets.state_id': [ 1,2,3,4,6 ]
'tickets.organization_id': organization.id
order:
by: 'created_at'
direction: 'DESC'
view:
d: [ 'number', 'title', 'customer', 'state', 'priority', 'created_at' ]
view_mode_default: 'd'
for area, plugins of plugins
for name, plugin of plugins
target = area + '_' + name
@el.find('.' + area + '-overviews').append('<div class="" id="' + target + '"></div>')
if plugin.controller
params = plugin.params || {}
params.el = @el.find( '#' + target )
new plugin.controller( params )
dndOptions =
handle: 'h2.can-move'
placeholder: 'can-move-plcaeholder'
tolerance: 'pointer'
distance: 15
opacity: 0.6
forcePlaceholderSize: true
@el.find( '#sortable' ).sortable( dndOptions )
@el.find( '#sortable-sidebar' ).sortable( dndOptions )
class Widgets extends App.Controller class Widgets extends App.Controller
constructor: -> constructor: ->
super super

View file

@ -34,10 +34,16 @@ class App.UserZoom extends App.Controller
render: (user) => render: (user) =>
@html App.view('user_zoom')( @html App.view('user_zoom')(
user: user user: user
) )
new Overviews(
el: @el
user: user
)
new App.UpdateTastbar( new App.UpdateTastbar(
genericObject: user genericObject: user
) )
@ -60,6 +66,74 @@ class App.UserZoom extends App.Controller
ui: @ ui: @
) )
class Overviews extends App.Controller
constructor: ->
super
# subscribe and reload data / fetch new data if triggered
@subscribeId = App.User.full( @user.id, @render, false, true )
release: =>
App.User.unsubscribe(@subscribeId)
render: (user) =>
plugins = {
main: {
my_assigned: {
controller: App.DashboardTicketSearch,
params: {
name: 'Tickets of User'
condition:
'tickets.state_id': [ 1,2,3,4,6 ]
'tickets.customer_id': user.id
order:
by: 'created_at'
direction: 'DESC'
view:
d: [ 'number', 'title', 'state', 'priority', 'created_at' ]
view_mode_default: 'd'
},
},
},
}
if user.organization_id
plugins.main.my_organization = {
controller: App.DashboardTicketSearch,
params: {
name: 'Tickets of Organization'
condition:
'tickets.state_id': [ 1,2,3,4,6 ]
'tickets.organization_id': user.organization_id
order:
by: 'created_at'
direction: 'DESC'
view:
d: [ 'number', 'title', 'customer', 'state', 'priority', 'created_at' ]
view_mode_default: 'd'
},
}
for area, plugins of plugins
for name, plugin of plugins
target = area + '_' + name
@el.find('.' + area + '-overviews').append('<div class="" id="' + target + '"></div>')
if plugin.controller
params = plugin.params || {}
params.el = @el.find( '#' + target )
new plugin.controller( params )
dndOptions =
handle: 'h2.can-move'
placeholder: 'can-move-plcaeholder'
tolerance: 'pointer'
distance: 15
opacity: 0.6
forcePlaceholderSize: true
@el.find( '#sortable' ).sortable( dndOptions )
@el.find( '#sortable-sidebar' ).sortable( dndOptions )
class Widgets extends App.Controller class Widgets extends App.Controller
constructor: -> constructor: ->
super super

View file

@ -1,7 +1,7 @@
<div class="span9"> <div class="span9">
<div class="page-header clearfix"> <div class="page-header clearfix">
<div class="page-header-title"> <div class="page-header-title">
<h2 class="can-move"><%- @T( @overview.name ) %> <small><a href="#" data-type="settings" class="glyphicon glyphicon-edit"></a></small></h2> <h2 class="can-move"><%- @T( @overview.name ) %> <small><% if @overview.id: %><a href="#" data-type="settings" class="glyphicon glyphicon-edit"></a><% end %></small></h2>
</div> </div>
<div class="page-header-meta"> <div class="page-header-meta">
<ul class="pagination"> <ul class="pagination">

View file

@ -9,10 +9,7 @@
<h1></h1> <h1></h1>
</div> </div>
<div class="ticket-answer"> <div class="main-overviews" id="sortable"></div>
<div class="article-view"></div>
<div class="edit"></div>
</div>
</div> </div>
</div> </div>

View file

@ -9,10 +9,7 @@
<h1></h1> <h1></h1>
</div> </div>
<div class="ticket-answer"> <div class="main-overviews" id="sortable"></div>
<div class="article-view"></div>
<div class="edit"></div>
</div>
</div> </div>
</div> </div>

View file

@ -364,7 +364,9 @@ class TicketsController < ApplicationController
tickets = Ticket.search( tickets = Ticket.search(
:limit => params[:limit], :limit => params[:limit],
:query => params[:term], :query => params[:term],
:condition => params[:condition],
:current_user => current_user, :current_user => current_user,
:detail => params[:detail]
) )
assets = {} assets = {}
ticket_result = [] ticket_result = []
@ -376,6 +378,7 @@ class TicketsController < ApplicationController
# return result # return result
render :json => { render :json => {
:tickets => ticket_result, :tickets => ticket_result,
:tickets_count => tickets.count,
:assets => assets, :assets => assets,
} }
end end

View file

@ -16,6 +16,20 @@ returns
result = [ticket_model1, ticket_model2] result = [ticket_model1, ticket_model2]
search tickets
result = Ticket.search(
:current_user => User.find(123),
:query => 'search something',
:limit => 15,
:full => 0
)
returns
result = [1,3,5,6,7]
=end =end
def search (params) def search (params)
@ -24,9 +38,13 @@ returns
query = params[:query] query = params[:query]
limit = params[:limit] || 12 limit = params[:limit] || 12
current_user = params[:current_user] current_user = params[:current_user]
full = false
if params[:full] || !params.has_key?(:full)
full = true
end
# try search index backend # try search index backend
if SearchIndexBackend.enabled? if !params[:detail] && SearchIndexBackend.enabled?
query_extention = {} query_extention = {}
query_extention['bool'] = {} query_extention['bool'] = {}
query_extention['bool']['must'] = [] query_extention['bool']['must'] = []
@ -39,28 +57,31 @@ returns
groups.each {|group| groups.each {|group|
group_condition.push group.name group_condition.push group.name
} }
condition = { access_condition = {
'query_string' => { 'default_field' => 'Ticket.group.name', 'query' => "\"#{group_condition.join('" OR "')}\"" } 'query_string' => { 'default_field' => 'Ticket.group.name', 'query' => "\"#{group_condition.join('" OR "')}\"" }
} }
query_extention['bool']['must'].push condition query_extention['bool']['must'].push access_condition
else else
if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
condition = { access_condition = {
'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id } 'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id }
} }
# customer_id: XXX # customer_id: XXX
# conditions = [ 'customer_id = ?', current_user.id ] # conditions = [ 'customer_id = ?', current_user.id ]
else else
condition = { access_condition = {
'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" } 'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" }
} }
# customer_id: XXX OR organization_id: XXX # customer_id: XXX OR organization_id: XXX
# conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]
end end
query_extention['bool']['must'].push condition query_extention['bool']['must'].push access_condition
end end
ids = SearchIndexBackend.search( query, limit, 'Ticket', query_extention ) ids = SearchIndexBackend.search( query, limit, 'Ticket', query_extention )
if !full
return ids
end
tickets = [] tickets = []
ids.each { |id| ids.each { |id|
tickets.push Ticket.lookup( :id => id ) tickets.push Ticket.lookup( :id => id )
@ -69,38 +90,53 @@ returns
end end
# fallback do sql query # fallback do sql query
conditions = [] access_condition = []
if current_user.is_role('Agent') if current_user.is_role('Agent')
group_ids = Group.select( 'groups.id' ).joins(:users). group_ids = Group.select( 'groups.id' ).joins(:users).
where( 'groups_users.user_id = ?', current_user.id ). where( 'groups_users.user_id = ?', current_user.id ).
where( 'groups.active = ?', true ). where( 'groups.active = ?', true ).
map( &:id ) map( &:id )
conditions = [ 'group_id IN (?)', group_ids ] access_condition = [ 'group_id IN (?)', group_ids ]
else else
if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
conditions = [ 'customer_id = ?', current_user.id ] access_condition = [ 'customer_id = ?', current_user.id ]
else else
conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] access_condition = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]
end end
end end
# do query # do query
# - stip out * we already search for *query* - # - stip out * we already search for *query* -
if query
query.gsub! '*', '' query.gsub! '*', ''
tickets_all = Ticket.select('DISTINCT(tickets.id)'). tickets_all = Ticket.select('DISTINCT(tickets.id)').
where(conditions). where(access_condition).
where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ). where( '( `tickets`.`title` LIKE ? OR `tickets`.`number` LIKE ? OR `ticket_articles`.`body` LIKE ? OR `ticket_articles`.`from` LIKE ? OR `ticket_articles`.`to` LIKE ? OR `ticket_articles`.`subject` LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ).
joins(:articles). joins(:articles).
order('`tickets`.`created_at` DESC'). order('`tickets`.`created_at` DESC').
limit(limit) limit(limit)
else
tickets_all = Ticket.select('DISTINCT(tickets.id)').
where(access_condition).
where(params[:condition]).
order('`tickets`.`created_at` DESC').
limit(limit)
end
# build result list # build result list
if !full
ids = []
tickets_all.each { |ticket|
ids.push ticket.id
}
return ids
end
tickets = [] tickets = []
tickets_all.each do |ticket| tickets_all.each { |ticket|
tickets.push Ticket.lookup( :id => ticket.id ) tickets.push Ticket.lookup( :id => ticket.id )
end }
return tickets
tickets
end end
end end