2014-07-13 18:52:32 +00:00
|
|
|
class Sessions::Backend::TicketOverviewList
|
|
|
|
def initialize( user, client = nil, client_id = nil )
|
2015-02-25 20:52:14 +00:00
|
|
|
@user = user
|
|
|
|
@client = client
|
|
|
|
@client_id = client_id
|
|
|
|
@last_change = nil
|
|
|
|
@last_ticket_change = nil
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def load
|
2013-09-21 22:40:19 +00:00
|
|
|
|
2014-07-13 18:52:32 +00:00
|
|
|
# get whole collection
|
2013-09-21 22:40:19 +00:00
|
|
|
overviews = Ticket::Overviews.all(
|
2014-07-13 18:52:32 +00:00
|
|
|
:current_user => @user,
|
2013-09-21 22:40:19 +00:00
|
|
|
)
|
2014-07-14 05:26:22 +00:00
|
|
|
result = []
|
|
|
|
overviews.each { |overview|
|
|
|
|
overview_data = Ticket::Overviews.list(
|
|
|
|
:view => overview.link,
|
|
|
|
:current_user => @user,
|
|
|
|
:array => true,
|
|
|
|
)
|
|
|
|
data = { :list => overview_data, :index => overview }
|
|
|
|
result.push data
|
|
|
|
}
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# no data exists
|
2014-07-14 05:26:22 +00:00
|
|
|
return if !result || result.empty?
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# no change exists
|
2014-07-14 05:26:22 +00:00
|
|
|
return if @last_change == result
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# remember last state
|
2014-07-14 05:26:22 +00:00
|
|
|
@last_change = result
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2014-07-14 05:26:22 +00:00
|
|
|
result
|
2013-09-21 22:40:19 +00:00
|
|
|
end
|
|
|
|
|
2014-07-13 18:52:32 +00:00
|
|
|
def client_key
|
|
|
|
"as::load::#{ self.class.to_s }::#{ @user.id }::#{ @client_id }"
|
|
|
|
end
|
|
|
|
|
|
|
|
def push
|
|
|
|
|
2015-02-25 20:52:14 +00:00
|
|
|
# check interval
|
2014-07-13 18:52:32 +00:00
|
|
|
timeout = Sessions::CacheIn.get( self.client_key )
|
|
|
|
return if timeout
|
|
|
|
|
2015-02-25 20:52:14 +00:00
|
|
|
# reset check interval
|
|
|
|
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 6.seconds } )
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2015-02-25 20:52:14 +00:00
|
|
|
# check if min one ticket has changed
|
|
|
|
last_ticket_change = Ticket.latest_change
|
|
|
|
return if last_ticket_change == @last_ticket_change
|
|
|
|
@last_ticket_change = last_ticket_change
|
|
|
|
|
|
|
|
# load current data
|
2014-07-14 05:26:22 +00:00
|
|
|
items = self.load
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2014-07-14 05:26:22 +00:00
|
|
|
return if !items
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# push overviews
|
2014-07-14 05:26:22 +00:00
|
|
|
results = []
|
|
|
|
items.each { |item|
|
2013-09-21 22:40:19 +00:00
|
|
|
|
2014-07-14 05:26:22 +00:00
|
|
|
overview_data = item[:list]
|
2013-09-21 22:40:19 +00:00
|
|
|
|
2014-07-13 18:52:32 +00:00
|
|
|
assets = {}
|
|
|
|
overview_data[:ticket_ids].each {|ticket_id|
|
|
|
|
ticket = Ticket.find( ticket_id )
|
|
|
|
assets = ticket.assets(assets)
|
|
|
|
}
|
2013-09-21 22:40:19 +00:00
|
|
|
|
2014-07-13 18:52:32 +00:00
|
|
|
# get groups
|
|
|
|
group_ids = []
|
|
|
|
Group.where( :active => true ).each { |group|
|
|
|
|
group_ids.push group.id
|
|
|
|
}
|
|
|
|
agents = {}
|
|
|
|
Ticket::ScreenOptions.agents.each { |user|
|
|
|
|
agents[ user.id ] = 1
|
|
|
|
}
|
|
|
|
users = {}
|
|
|
|
groups_users = {}
|
|
|
|
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.find(user.id)
|
|
|
|
assets = users[user.id].assets(assets)
|
|
|
|
end
|
2013-09-21 22:40:19 +00:00
|
|
|
}
|
2014-07-13 18:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !@client
|
2014-07-14 05:26:22 +00:00
|
|
|
result = {
|
2014-07-13 18:52:32 +00:00
|
|
|
:event => 'navupdate_ticket_overview',
|
2014-07-14 05:26:22 +00:00
|
|
|
:data => item[:index],
|
2013-09-21 22:40:19 +00:00
|
|
|
}
|
2014-07-14 05:26:22 +00:00
|
|
|
results.push result
|
|
|
|
else
|
|
|
|
|
|
|
|
@client.log 'notify', "push overview_list for user #{ @user.id }"
|
|
|
|
|
|
|
|
# send update to browser
|
|
|
|
@client.send({
|
|
|
|
:data => assets,
|
|
|
|
:event => [ 'loadAssets' ]
|
|
|
|
})
|
|
|
|
@client.send({
|
|
|
|
:data => {
|
2015-02-19 19:32:37 +00:00
|
|
|
:view => item[:index].link.to_s,
|
2014-07-14 05:26:22 +00:00
|
|
|
:overview => overview_data[:overview],
|
|
|
|
:ticket_ids => overview_data[:ticket_ids],
|
|
|
|
:tickets_count => overview_data[:tickets_count],
|
2015-02-19 19:32:37 +00:00
|
|
|
:bulk => {
|
2014-07-14 05:26:22 +00:00
|
|
|
:group_id__owner_id => groups_users,
|
|
|
|
:owner_id => [],
|
|
|
|
},
|
2013-09-21 22:40:19 +00:00
|
|
|
},
|
2015-02-19 19:32:37 +00:00
|
|
|
:event => [ 'ticket_overview_rebuild' ],
|
2014-07-14 05:26:22 +00:00
|
|
|
})
|
|
|
|
end
|
2013-09-21 22:40:19 +00:00
|
|
|
}
|
2014-07-14 05:26:22 +00:00
|
|
|
return results if !@client
|
|
|
|
nil
|
2013-09-21 22:40:19 +00:00
|
|
|
end
|
|
|
|
|
2014-06-29 19:30:55 +00:00
|
|
|
end
|