Show only possibe ticket states.

This commit is contained in:
Martin Edenhofer 2013-01-04 09:09:59 +01:00
parent 9ac0301e71
commit 99b4836921
6 changed files with 112 additions and 103 deletions

View file

@ -80,7 +80,7 @@ class App.Controller extends Spine.Controller
{ name: 'last_contact_customer', callback: @frontendTime }, { name: 'last_contact_customer', callback: @frontendTime },
{ name: 'first_response', callback: @frontendTime }, { name: 'first_response', callback: @frontendTime },
{ name: 'close_time', callback: @frontendTime }, { name: 'close_time', callback: @frontendTime },
{ name: 'article_count', title: 'group'}, { name: 'article_count', },
] ]
shown_all_attributes = [] shown_all_attributes = []
for all_attribute in all_attributes for all_attribute in all_attributes

View file

@ -92,7 +92,7 @@ class Index extends App.Controller
# set defaults # set defaults
defaults = template['options'] || {} defaults = template['options'] || {}
if !( 'ticket_state_id' of defaults ) if !( 'ticket_state_id' of defaults )
defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'new' ).id defaults['ticket_state_id'] = App.Collection.findByAttribute( 'TicketState', 'name', 'open' ).id
if !( 'ticket_priority_id' of defaults ) if !( 'ticket_priority_id' of defaults )
defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id defaults['ticket_priority_id'] = App.Collection.findByAttribute( 'TicketPriority', 'name', '2 normal' ).id

View file

@ -17,5 +17,4 @@ class App.Ticket extends App.Model
{ name: 'first_response', display: 'First response', tag: 'time', null: true, style: 'width: 12%' }, { name: 'first_response', display: 'First response', tag: 'time', null: true, style: 'width: 12%' },
{ name: 'close_time', display: 'Close time', tag: 'time', null: true, style: 'width: 12%' }, { name: 'close_time', display: 'Close time', tag: 'time', null: true, style: 'width: 12%' },
{ name: 'article_count', display: 'Article#', style: 'width: 12%' }, { name: 'article_count', display: 'Article#', style: 'width: 12%' },
] ]

View file

@ -323,14 +323,6 @@ class TicketsController < ApplicationController
users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id ) users[ticket.created_by_id] = User.user_data_full( ticket.created_by_id )
end end
owner_ids = []
ticket.agent_of_group.each { |user|
owner_ids.push user.id
if !users[user.id]
users[user.id] = User.user_data_full( user.id )
end
}
# log object as viewed # log object as viewed
log_view( ticket ) log_view( ticket )
@ -349,6 +341,23 @@ class TicketsController < ApplicationController
) )
end end
# get attributes to update
attributes_to_change = Ticket.attributes_to_change( :user => current_user, :ticket => ticket )
attributes_to_change[:owner_id].each { |user_id|
if !users[user_id]
users[user_id] = User.user_data_full( user_id )
end
}
attributes_to_change[:group_id__owner_id].each {|group_id, user_ids|
user_ids.each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full( user_id )
end
}
}
# get related articles # get related articles
ticket = ticket.attributes ticket = ticket.attributes
ticket[:article_ids] = [] ticket[:article_ids] = []
@ -377,52 +386,44 @@ class TicketsController < ApplicationController
end end
} }
# get groups
group_ids = []
Group.where( :active => true ).each { |group|
group_ids.push group.id
}
agents = {}
Ticket.agents.each { |user|
agents[ user.id ] = 1
}
groups_users = {}
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find(group_id).users.each {|user|
next if !agents[ user.id ]
groups_users[ group_id ].push user.id
if !users[user.id]
users[user.id] = User.user_data_full( user.id )
end
}
}
# return result # return result
render :json => { render :json => {
:ticket => ticket, :ticket => ticket,
:articles => articles_used, :articles => articles_used,
:signature => signature, :signature => signature,
:users => users, :users => users,
:edit_form => { :edit_form => attributes_to_change,
:group_id__owner_id => groups_users,
:owner_id => owner_ids,
}
} }
end end
# GET /ticket_create/1 # GET /ticket_create/1
def ticket_create def ticket_create
# get attributes # get attributes to update
create_attributes = Ticket.create_attributes( attributes_to_change = Ticket.attributes_to_change(
:current_user_id => current_user.id, :user => current_user,
# :ticket_id => params[:ticket_id],
# :article_id => params[:article_id]
) )
users = {}
attributes_to_change[:owner_id].each { |user_id|
if !users[user_id]
users[user_id] = User.user_data_full( user_id )
end
}
attributes_to_change[:group_id__owner_id].each {|group_id, user_ids|
user_ids.each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full( user_id )
end
}
}
# split data # split data
ticket = nil ticket = nil
articles = nil articles = nil
users = {}
if params[:ticket_id] && params[:article_id] if params[:ticket_id] && params[:article_id]
ticket = Ticket.find( params[:ticket_id] ) ticket = Ticket.find( params[:ticket_id] )
@ -444,7 +445,7 @@ class TicketsController < ApplicationController
users[user.id] = User.user_data_full( user.id ) users[user.id] = User.user_data_full( user.id )
end end
} }
# get related articles # get related articles
ticket[:article_ids] = [ params[:article_id] ] ticket[:article_ids] = [ params[:article_id] ]
@ -459,18 +460,12 @@ class TicketsController < ApplicationController
end end
end end
create_attributes[:owner_id].each {|user_id|
if !users[user_id]
users[user_id] = User.user_data_full( user_id )
end
}
# return result # return result
render :json => { render :json => {
:ticket => ticket, :ticket => ticket,
:articles => [ article ], :articles => [ article ],
:users => users, :users => users,
:edit_form => create_attributes, :edit_form => attributes_to_change,
} }
end end
@ -522,5 +517,4 @@ class TicketsController < ApplicationController
} }
end end
end end

View file

@ -26,6 +26,75 @@ class Ticket < ApplicationModel
User.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq() User.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
end end
def self.attributes_to_change(params)
if params[:ticket_id]
params[:ticket] = self.find( params[:ticket_id] )
end
if params[:article_id]
params[:article] = self.find( params[:article_id] )
end
# get ticket states
ticket_state_ids = []
if params[:ticket]
ticket_state_type = params[:ticket].ticket_state.state_type
end
ticket_state_types = ['open', 'closed', 'pending action', 'pending reminder']
if ticket_state_type && !ticket_state_types.include?(ticket_state_type.name)
ticket_state_ids.push params[:ticket].ticket_state.id
end
ticket_state_types.each {|type|
ticket_state_type = Ticket::StateType.where( :name => type ).first
if ticket_state_type
ticket_state_type.states.each {|ticket_state|
ticket_state_ids.push ticket_state.id
}
end
}
# get owner
owner_ids = []
if params[:ticket]
params[:ticket].agent_of_group.each { |user|
owner_ids.push user.id
}
end
# get group
group_ids = []
Group.where( :active => true ).each { |group|
group_ids.push group.id
}
# get group / user relations
agents = {}
Ticket.agents.each { |user|
agents[ user.id ] = 1
}
groups_users = {}
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find( group_id ).users.each {|user|
next if !agents[ user.id ]
groups_users[ group_id ].push user.id
}
}
# get priorities
ticket_priority_ids = []
Ticket::Priority.where( :active => true ).each { |priority|
ticket_priority_ids.push priority.id
}
return {
:ticket_state_id => ticket_state_ids,
:ticket_priority_id => ticket_priority_ids,
:owner_id => owner_ids,
:group_id => group_ids,
:group_id__owner_id => groups_users,
}
end
def merge_to(data) def merge_to(data)
# update articles # update articles
@ -300,59 +369,6 @@ class Ticket < ApplicationModel
end end
# Ticket.create_attributes(
# :current_user_id => 123,
# )
def self.create_attributes (data)
# get groups
group_ids = []
Group.where( :active => true ).each { |group|
group_ids.push group.id
}
# get related users
# users = {}
user_ids = []
agents = {}
Ticket.agents.each { |user|
agents[ user.id ] = 1
user_ids.push user.id
}
groups_users = {}
group_ids.each {|group_id|
groups_users[ group_id ] = []
Group.find(group_id).users.each {|user|
next if !agents[ user.id ]
groups_users[ group_id ].push user.id
# if !users[user.id]
# users[user.id] = User.user_data_full(user.id)
# end
}
}
# get states
ticket_state_ids = []
Ticket::State.where( :active => true ).each { |state|
ticket_state_ids.push state.id
}
# get priorities
ticket_priority_ids = []
Ticket::Priority.where( :active => true ).each { |priority|
ticket_priority_ids.push priority.id
}
return {
# :users => users,
:owner_id => user_ids,
:group_id__owner_id => groups_users,
:group_id => group_ids,
:ticket_state_id => ticket_state_ids,
:ticket_priority_id => ticket_priority_ids,
}
end
def self.number_adapter def self.number_adapter
# load backend based on config # load backend based on config

View file

@ -311,7 +311,7 @@ class UserState
# create_attributes # create_attributes
cache_key = @cache_key + '_ticket_create_attributes' cache_key = @cache_key + '_ticket_create_attributes'
if CacheIn.expired(cache_key) if CacheIn.expired(cache_key)
ticket_create_attributes = Ticket.create_attributes( ticket_create_attributes = Ticket.attributes_to_change(
:current_user_id => user.id, :current_user_id => user.id,
) )
ticket_create_attributes_cache = CacheIn.get( cache_key, { :re_expire => true } ) ticket_create_attributes_cache = CacheIn.get( cache_key, { :re_expire => true } )