Fixed ticket list in user and org profile.
This commit is contained in:
parent
e260261bda
commit
2311d1c393
5 changed files with 45 additions and 19 deletions
|
@ -389,11 +389,11 @@ class TicketsController < ApplicationController
|
|||
if params[:user_id]
|
||||
user = User.find( params[:user_id] )
|
||||
condition = {
|
||||
'tickets.state_id' => {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: Ticket::State.by_category('open').map(&:id),
|
||||
},
|
||||
'tickets.customer_id' => {
|
||||
'ticket.customer_id' => {
|
||||
operator: 'is',
|
||||
value: user.id,
|
||||
},
|
||||
|
@ -407,11 +407,11 @@ class TicketsController < ApplicationController
|
|||
|
||||
# lookup closed user tickets
|
||||
condition = {
|
||||
'tickets.state_id' => {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: Ticket::State.by_category('closed').map(&:id),
|
||||
},
|
||||
'tickets.customer_id' => {
|
||||
'ticket.customer_id' => {
|
||||
operator: 'is',
|
||||
value: user.id,
|
||||
},
|
||||
|
@ -463,11 +463,11 @@ class TicketsController < ApplicationController
|
|||
if params[:organization_id] && !params[:organization_id].empty?
|
||||
|
||||
condition = {
|
||||
'tickets.state_id' => {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: Ticket::State.by_category('open').map(&:id),
|
||||
},
|
||||
'tickets.organization_id' => {
|
||||
'ticket.organization_id' => {
|
||||
operator: 'is',
|
||||
value: params[:organization_id],
|
||||
},
|
||||
|
@ -481,11 +481,11 @@ class TicketsController < ApplicationController
|
|||
|
||||
# lookup closed org tickets
|
||||
condition = {
|
||||
'tickets.state_id' => {
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: Ticket::State.by_category('closed').map(&:id),
|
||||
},
|
||||
'tickets.organization_id' => {
|
||||
'ticket.organization_id' => {
|
||||
operator: 'is',
|
||||
value: params[:organization_id],
|
||||
},
|
||||
|
|
|
@ -285,16 +285,41 @@ returns
|
|||
false
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
get count of tickets and tickets which match on selector
|
||||
|
||||
ticket_count, tickets = Ticket.selectors(params[:condition], 6)
|
||||
|
||||
=end
|
||||
|
||||
def self.selectors(selectors, limit = 10)
|
||||
return if !selectors
|
||||
query, bind_params, tables = _selectors(selectors)
|
||||
query, bind_params, tables = selector2sql(selectors)
|
||||
return [] if !query
|
||||
ticket_count = Ticket.where(query, *bind_params).joins(tables).count
|
||||
tickets = Ticket.where(query, *bind_params).joins(tables).limit(limit)
|
||||
[ticket_count, tickets]
|
||||
end
|
||||
|
||||
def self._selectors(selectors)
|
||||
=begin
|
||||
|
||||
generate condition query to search for tickets based on condition
|
||||
|
||||
query_condition, bind_condition = selector2sql(params[:condition])
|
||||
|
||||
condition example
|
||||
|
||||
{
|
||||
'ticket.state_id' => {
|
||||
operator: 'is',
|
||||
value: [1,2,5]
|
||||
}
|
||||
}
|
||||
|
||||
=end
|
||||
|
||||
def self.selector2sql(selectors)
|
||||
return if !selectors
|
||||
query = ''
|
||||
bind_params = []
|
||||
|
@ -308,13 +333,14 @@ returns
|
|||
tables.push selector[0].to_sym
|
||||
}
|
||||
|
||||
selectors.each {|attribute, selector|
|
||||
selectors.each {|attribute, selector_raw|
|
||||
if query != ''
|
||||
query += ' AND '
|
||||
end
|
||||
next if !selector
|
||||
next if !selector.respond_to?(:key?)
|
||||
next if !selector['operator']
|
||||
selector = selector_raw.stringify_keys
|
||||
fail "Invalid selector #{selector.inspect}" if !selector
|
||||
fail "Invalid selector #{selector.inspect}" if !selector.respond_to?(:key?)
|
||||
fail "Invalid selector, operator missing #{selector.inspect}" if !selector['operator']
|
||||
return nil if !selector['value']
|
||||
return nil if selector['value'].respond_to?(:empty?) && selector['value'].empty?
|
||||
attributes = attribute.split(/\./)
|
||||
|
|
|
@ -206,7 +206,7 @@ returns
|
|||
if !sla.condition || sla.condition.empty?
|
||||
sla_selected = sla
|
||||
elsif sla.condition
|
||||
query_condition, bind_condition = Ticket._selectors(sla.condition)
|
||||
query_condition, bind_condition = Ticket.selector2sql(sla.condition)
|
||||
ticket = Ticket.where( query_condition, *bind_condition ).find_by(id: id)
|
||||
next if !ticket
|
||||
sla_selected = sla
|
||||
|
|
|
@ -111,7 +111,7 @@ returns
|
|||
result = []
|
||||
overviews.each { |overview|
|
||||
|
||||
query_condition, bind_condition = Ticket._selectors(overview.condition)
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview.condition)
|
||||
|
||||
# get count
|
||||
count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count()
|
||||
|
@ -136,7 +136,7 @@ returns
|
|||
order_by = overview_selected.group_by + '_id, ' + order_by
|
||||
end
|
||||
|
||||
query_condition, bind_condition = Ticket._selectors(overview_selected.condition)
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition)
|
||||
|
||||
tickets = Ticket.select('id')
|
||||
.where( access_condition )
|
||||
|
@ -160,7 +160,7 @@ returns
|
|||
|
||||
# get tickets for overview
|
||||
data[:start_page] ||= 1
|
||||
query_condition, bind_condition = Ticket._selectors(overview_selected.condition)
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition)
|
||||
tickets = Ticket.where( access_condition )
|
||||
.where( query_condition, *bind_condition )
|
||||
.order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )
|
||||
|
|
|
@ -160,7 +160,7 @@ returns
|
|||
.order('`tickets`.`created_at` DESC')
|
||||
.limit(limit)
|
||||
else
|
||||
query_condition, bind_condition = _selectors(params[:condition])
|
||||
query_condition, bind_condition = selector2sql(params[:condition])
|
||||
tickets_all = Ticket.select('DISTINCT(tickets.id)')
|
||||
.where(access_condition)
|
||||
.where(query_condition, *bind_condition)
|
||||
|
|
Loading…
Reference in a new issue