Rewrite of overview index and list backend.
This commit is contained in:
parent
8ba009168e
commit
fb1a8987aa
19 changed files with 329 additions and 441 deletions
|
@ -23,6 +23,11 @@ class App.TicketOverview extends App.Controller
|
|||
|
||||
@html elLocal
|
||||
|
||||
@bind 'overview:fetch', =>
|
||||
update = =>
|
||||
App.OverviewListCollection.fetch(@view)
|
||||
@delay(update, 2800, 'overview:fetch')
|
||||
|
||||
active: (state) =>
|
||||
@activeState = state
|
||||
|
||||
|
@ -197,16 +202,16 @@ class Table extends App.Controller
|
|||
super
|
||||
|
||||
if @view
|
||||
@bindId = App.OverviewCollection.bind(@view, @render)
|
||||
@bindId = App.OverviewListCollection.bind(@view, @render)
|
||||
|
||||
# rerender view, e. g. on langauge change
|
||||
@bind 'ui:rerender', =>
|
||||
return if !@authenticate(true)
|
||||
@render(App.OverviewCollection.get(@view))
|
||||
@render(App.OverviewListCollection.get(@view))
|
||||
|
||||
release: =>
|
||||
if @bindId
|
||||
App.OverviewCollection.unbind(@bindId)
|
||||
App.OverviewListCollection.unbind(@bindId)
|
||||
|
||||
update: (params) =>
|
||||
for key, value of params
|
||||
|
@ -219,24 +224,20 @@ class Table extends App.Controller
|
|||
|
||||
if @view
|
||||
if @bindId
|
||||
App.OverviewCollection.unbind(@bindId)
|
||||
@bindId = App.OverviewCollection.bind(@view, @render)
|
||||
App.OverviewListCollection.unbind(@bindId)
|
||||
@bindId = App.OverviewListCollection.bind(@view, @render)
|
||||
|
||||
render: (data) =>
|
||||
return if !data
|
||||
|
||||
# use cache
|
||||
overview = data.overview
|
||||
tickets_count = data.tickets_count
|
||||
ticket_ids = data.ticket_ids
|
||||
|
||||
# use cache if no local change
|
||||
App.Overview.refresh(overview, { clear: true })
|
||||
tickets = data.tickets
|
||||
|
||||
# get ticket list
|
||||
ticket_list_show = []
|
||||
for ticket_id in ticket_ids
|
||||
ticket_list_show.push App.Ticket.fullLocal(ticket_id)
|
||||
for ticket in tickets
|
||||
ticket_list_show.push App.Ticket.fullLocal(ticket.id)
|
||||
|
||||
# if customer and no ticket exists, show the following message only
|
||||
if !ticket_list_show[0] && @isRole('Customer')
|
||||
|
@ -622,8 +623,7 @@ class BulkForm extends App.Controller
|
|||
@hide()
|
||||
|
||||
# fetch overview data again
|
||||
App.OverviewIndexCollection.fetch()
|
||||
App.OverviewCollection.fetch(@view)
|
||||
App.Event.trigger('overview:fetch')
|
||||
)
|
||||
)
|
||||
@holder.find('.table-overview').find('[name="bulk"]:checked').prop('checked', false)
|
||||
|
@ -761,11 +761,10 @@ class App.OverviewSettings extends App.ControllerModal
|
|||
|
||||
# fetch overview data again
|
||||
if @reload_needed
|
||||
App.OverviewIndexCollection.fetch()
|
||||
App.OverviewCollection.fetch(@overview.link)
|
||||
App.OverviewListCollection.fetch(@overview.link)
|
||||
else
|
||||
App.OverviewIndexCollection.trigger()
|
||||
App.OverviewCollection.trigger(@overview.link)
|
||||
App.OverviewListCollection.trigger(@overview.link)
|
||||
|
||||
# close modal
|
||||
@close()
|
||||
|
|
|
@ -618,25 +618,25 @@ class App.TicketZoom extends App.Controller
|
|||
if @overview_id
|
||||
current_position = 0
|
||||
overview = App.Overview.find(@overview_id)
|
||||
list = App.OverviewCollection.get(overview.link)
|
||||
for ticket_id in list.ticket_ids
|
||||
list = App.OverviewListCollection.get(overview.link)
|
||||
for ticket in list.tickets
|
||||
current_position += 1
|
||||
if ticket_id is @ticket_id
|
||||
next = list.ticket_ids[current_position]
|
||||
if ticket.id is @ticket_id
|
||||
next = list.tickets[current_position]
|
||||
if next
|
||||
# close task
|
||||
App.TaskManager.remove(@task_key)
|
||||
|
||||
# open task via task manager to get overview information
|
||||
App.TaskManager.execute(
|
||||
key: 'Ticket-' + next
|
||||
key: 'Ticket-' + next.id
|
||||
controller: 'TicketZoom'
|
||||
params:
|
||||
ticket_id: next
|
||||
ticket_id: next.id
|
||||
overview_id: @overview_id
|
||||
show: true
|
||||
)
|
||||
@navigate "ticket/zoom/#{next}"
|
||||
@navigate "ticket/zoom/#{next.id}"
|
||||
return
|
||||
|
||||
# fallback, close task
|
||||
|
@ -658,6 +658,8 @@ class App.TicketZoom extends App.Controller
|
|||
|
||||
# enable form
|
||||
@formEnable(e)
|
||||
|
||||
App.Event.trigger('overview:fetch')
|
||||
)
|
||||
|
||||
bookmark: (e) ->
|
||||
|
|
|
@ -12,12 +12,12 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
|||
@delay(@render, 2600, 'overview-navigator')
|
||||
|
||||
@overview = App.Overview.find(@overview_id)
|
||||
@bindId = App.OverviewCollection.bind(@overview.link, lateUpdate, false)
|
||||
@bindId = App.OverviewListCollection.bind(@overview.link, lateUpdate, false)
|
||||
|
||||
@render()
|
||||
|
||||
release: =>
|
||||
App.OverviewCollection.unbind(@bindId)
|
||||
App.OverviewListCollection.unbind(@bindId)
|
||||
|
||||
render: =>
|
||||
if !@overview_id
|
||||
|
@ -25,17 +25,17 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
|||
return
|
||||
|
||||
# get overview data
|
||||
overview = App.OverviewCollection.get(@overview.link)
|
||||
overview = App.OverviewListCollection.get(@overview.link)
|
||||
return if !overview
|
||||
current_position = 0
|
||||
found = false
|
||||
next = false
|
||||
previous = false
|
||||
for ticket_id in overview.ticket_ids
|
||||
item_next = false
|
||||
item_previous = false
|
||||
for ticket in overview.tickets
|
||||
current_position += 1
|
||||
next = overview.ticket_ids[current_position]
|
||||
previous = overview.ticket_ids[current_position-2]
|
||||
if ticket_id is @ticket_id
|
||||
item_next = overview.tickets[current_position]
|
||||
item_previous = overview.tickets[current_position-2]
|
||||
if ticket.id is @ticket_id
|
||||
found = true
|
||||
break
|
||||
|
||||
|
@ -44,10 +44,10 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
|||
return
|
||||
|
||||
# get next/previous ticket
|
||||
if next
|
||||
next = App.Ticket.find(next)
|
||||
if previous
|
||||
previous = App.Ticket.find(previous)
|
||||
if item_next
|
||||
next = App.Ticket.find(item_next.id)
|
||||
if item_previous
|
||||
previous = App.Ticket.find(item_previous.id)
|
||||
|
||||
@html App.view('ticket_zoom/overview_navigator')(
|
||||
title: overview.overview.name
|
||||
|
|
|
@ -53,5 +53,7 @@ class App.TicketZoomTitle extends App.Controller
|
|||
# update taskbar with new meta data
|
||||
@metaTaskUpdate()
|
||||
|
||||
App.Event.trigger('overview:fetch')
|
||||
|
||||
release: =>
|
||||
App.Ticket.unsubscribe(@subscribeId)
|
||||
|
|
|
@ -44,6 +44,10 @@ class App._CollectionSingletonBase
|
|||
delete @callbacks[counter]
|
||||
|
||||
fetch: =>
|
||||
if App.WebSocket.support()
|
||||
App.WebSocket.send(event: @event)
|
||||
return
|
||||
|
||||
return if @fetchActive
|
||||
@fetchActive = true
|
||||
App.Ajax.request(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class App.OverviewCollection
|
||||
class App.OverviewListCollection
|
||||
_instance = undefined # Must be declared here to force the closure on the class
|
||||
|
||||
@get: (view) ->
|
||||
|
@ -35,18 +35,11 @@ class _Singleton
|
|||
@counter = 0
|
||||
|
||||
# websocket updates
|
||||
App.Event.bind 'ticket_overview_rebuild', (data) =>
|
||||
if !@overview[data.view]
|
||||
@overview[data.view] = {}
|
||||
|
||||
# proccess assets, delete them later
|
||||
if data.assets
|
||||
App.Collection.loadAssets( data.assets )
|
||||
delete data.assets
|
||||
|
||||
@overview[data.view] = data
|
||||
|
||||
@callback(data.view, data)
|
||||
App.Event.bind 'ticket_overview_list', (data) =>
|
||||
if !@overview[data.overview.view]
|
||||
@overview[data.overview.view] = {}
|
||||
@overview[data.overview.view] = data
|
||||
@callback(data.overview.view, data)
|
||||
|
||||
get: (view) ->
|
||||
@overview[view]
|
||||
|
@ -70,6 +63,14 @@ class _Singleton
|
|||
delete @callbacks[counter]
|
||||
|
||||
fetch: (view) =>
|
||||
if App.WebSocket.support()
|
||||
App.WebSocket.send(
|
||||
event: 'ticket_overview_list'
|
||||
view: view
|
||||
)
|
||||
return
|
||||
|
||||
App.OverviewIndexCollection.fetch()
|
||||
return if @fetchActive[view]
|
||||
@fetchActive[view] = true
|
||||
App.Ajax.request(
|
||||
|
@ -81,15 +82,10 @@ class _Singleton
|
|||
processData: true,
|
||||
success: (data) =>
|
||||
@fetchActive[view] = false
|
||||
|
||||
# proccess assets, delete them later
|
||||
if data.assets
|
||||
App.Collection.loadAssets( data.assets )
|
||||
delete data.assets
|
||||
|
||||
@overview[data.view] = data
|
||||
|
||||
@callback(view, data)
|
||||
App.Collection.loadAssets(data.assets)
|
||||
@overview[data.index.overview.view] = data.index
|
||||
@callback(view, data.index)
|
||||
error: =>
|
||||
@fetchActive[view] = false
|
||||
)
|
|
@ -30,6 +30,11 @@ class App.WebSocket
|
|||
_instance ?= new _webSocketSingleton
|
||||
_instance.spool()
|
||||
|
||||
@support: ->
|
||||
if _instance == undefined
|
||||
_instance ?= new _webSocketSingleton
|
||||
_instance.support()
|
||||
|
||||
# The actual Singleton class
|
||||
class _webSocketSingleton extends App.Controller
|
||||
@include App.LogInclude
|
||||
|
@ -103,6 +108,9 @@ class _webSocketSingleton extends App.Controller
|
|||
channel: ->
|
||||
@backend
|
||||
|
||||
support: ->
|
||||
@supported
|
||||
|
||||
send: (data) =>
|
||||
if @backend is 'ajax'
|
||||
@_ajaxSend(data)
|
||||
|
@ -180,6 +188,7 @@ class _webSocketSingleton extends App.Controller
|
|||
connect: =>
|
||||
|
||||
if !window.WebSocket
|
||||
@supported = false
|
||||
@backend = 'ajax'
|
||||
@log 'debug', 'no support of websocket, use ajax long polling'
|
||||
@_ajaxInit()
|
||||
|
|
|
@ -10,80 +10,42 @@ class TicketOverviewsController < ApplicationController
|
|||
|
||||
# get navbar overview data
|
||||
if !params[:view]
|
||||
result = Ticket::Overviews.list(
|
||||
current_user: current_user,
|
||||
)
|
||||
render json: result
|
||||
return
|
||||
end
|
||||
|
||||
# get real overview data
|
||||
if params[:array]
|
||||
overview = Ticket::Overviews.list(
|
||||
view: params[:view],
|
||||
current_user: current_user,
|
||||
array: true,
|
||||
)
|
||||
tickets = []
|
||||
overview[:tickets].each {|ticket_id|
|
||||
data = { id: ticket_id }
|
||||
tickets.push data
|
||||
}
|
||||
|
||||
# return result
|
||||
render json: {
|
||||
overview: overview[:overview],
|
||||
tickets: tickets,
|
||||
tickets_count: overview[:tickets_count],
|
||||
}
|
||||
return
|
||||
end
|
||||
overview = Ticket::Overviews.list(
|
||||
view: params[:view],
|
||||
current_user: current_user,
|
||||
array: true,
|
||||
)
|
||||
if !overview
|
||||
render json: { error: "No such view #{params[:view]}!" }, status: :unprocessable_entity
|
||||
return
|
||||
end
|
||||
|
||||
# get related users
|
||||
index_and_lists = Ticket::Overviews.index(current_user)
|
||||
indexes = []
|
||||
index_and_lists.each { |index|
|
||||
assets = {}
|
||||
overview[:ticket_ids].each {|ticket_id|
|
||||
ticket = Ticket.lookup( id: ticket_id )
|
||||
overview = Overview.lookup(id: index[:overview][:id])
|
||||
meta = {
|
||||
name: overview.name,
|
||||
prio: overview.prio,
|
||||
link: overview.link,
|
||||
count: index[:count],
|
||||
}
|
||||
indexes.push meta
|
||||
}
|
||||
render json: indexes
|
||||
return
|
||||
end
|
||||
|
||||
index_and_lists = Ticket::Overviews.index(current_user)
|
||||
|
||||
assets = {}
|
||||
result = {}
|
||||
index_and_lists.each { |index|
|
||||
next if index[:overview][:view] != params[:view]
|
||||
|
||||
overview = Overview.lookup(id: index[:overview][:id])
|
||||
assets = overview.assets(assets)
|
||||
index[:tickets].each {|ticket_meta|
|
||||
ticket = Ticket.lookup(id: ticket_meta[:id])
|
||||
assets = ticket.assets(assets)
|
||||
}
|
||||
|
||||
# get groups
|
||||
group_ids = []
|
||||
Group.where( active: true ).each { |group|
|
||||
group_ids.push group.id
|
||||
}
|
||||
agents = {}
|
||||
User.of_role('Agent').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
|
||||
assets = user.assets( assets )
|
||||
}
|
||||
result = index
|
||||
}
|
||||
|
||||
# return result
|
||||
render json: {
|
||||
view: params[:view],
|
||||
overview: overview[:overview],
|
||||
ticket_ids: overview[:ticket_ids],
|
||||
tickets_count: overview[:tickets_count],
|
||||
bulk: {
|
||||
group_id__owner_id: groups_users,
|
||||
},
|
||||
assets: assets,
|
||||
index: result,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ class Overview < ApplicationModel
|
|||
before_create :fill_link
|
||||
before_update :fill_link
|
||||
|
||||
latest_change_support
|
||||
|
||||
private
|
||||
|
||||
# fill link
|
||||
|
|
|
@ -3,10 +3,10 @@ module Ticket::Overviews
|
|||
|
||||
=begin
|
||||
|
||||
all overview by user
|
||||
all overviews by user
|
||||
|
||||
result = Ticket::Overviews.all(
|
||||
:current_user => User.find(123),
|
||||
current_user: User.find(123),
|
||||
)
|
||||
|
||||
returns
|
||||
|
@ -15,137 +15,105 @@ returns
|
|||
|
||||
=end
|
||||
|
||||
def self.all (data)
|
||||
def self.all(data)
|
||||
|
||||
# get customer overviews
|
||||
if data[:current_user].role?('Customer')
|
||||
role = Role.find_by( name: 'Customer' )
|
||||
role = Role.find_by(name: 'Customer')
|
||||
overviews = if data[:current_user].organization_id && data[:current_user].organization.shared
|
||||
Overview.where( role_id: role.id, active: true )
|
||||
Overview.where(role_id: role.id, active: true)
|
||||
else
|
||||
Overview.where( role_id: role.id, organization_shared: false, active: true )
|
||||
Overview.where(role_id: role.id, organization_shared: false, active: true)
|
||||
end
|
||||
return overviews
|
||||
end
|
||||
|
||||
# get agent overviews
|
||||
return if !data[:current_user].role?( 'Agent' )
|
||||
role = Role.find_by( name: 'Agent' )
|
||||
Overview.where( role_id: role.id, active: true )
|
||||
return if !data[:current_user].role?('Agent')
|
||||
role = Role.find_by(name: 'Agent')
|
||||
Overview.where(role_id: role.id, active: true)
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
selected overview by user
|
||||
|
||||
result = Ticket::Overviews.list(
|
||||
current_user: User.find(123),
|
||||
view: 'some_view_url',
|
||||
)
|
||||
result = Ticket::Overviews.index(User.find(123))
|
||||
|
||||
returns
|
||||
|
||||
result = {
|
||||
tickets: tickets, # [ticket1, ticket2, ticket3]
|
||||
tickets_count: tickets_count, # count of tickets
|
||||
overview: overview_selected_raw, # overview attributes
|
||||
[
|
||||
{
|
||||
overview: {
|
||||
id: 123,
|
||||
updated_at: ...,
|
||||
},
|
||||
count: 3,
|
||||
tickets: [
|
||||
{
|
||||
id: 1,
|
||||
updated_at: ...,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
updated_at: ...,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
updated_at: ...,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
...
|
||||
}
|
||||
]
|
||||
|
||||
=end
|
||||
|
||||
def self.list (data)
|
||||
|
||||
overviews = all(data)
|
||||
return if !overviews
|
||||
|
||||
# build up attributes hash
|
||||
overview_selected = nil
|
||||
overview_selected_raw = nil
|
||||
|
||||
overviews.each { |overview|
|
||||
|
||||
# remember selected view
|
||||
if data[:view] && data[:view] == overview.link
|
||||
overview_selected = overview
|
||||
overview_selected_raw = Marshal.load( Marshal.dump(overview.attributes) )
|
||||
end
|
||||
}
|
||||
|
||||
if data[:view] && !overview_selected
|
||||
raise "No such view '#{data[:view]}'"
|
||||
end
|
||||
def self.index(user)
|
||||
overviews = Ticket::Overviews.all(
|
||||
current_user: user,
|
||||
)
|
||||
|
||||
# get only tickets with permissions
|
||||
access_condition = Ticket.access_condition( data[:current_user] )
|
||||
access_condition = Ticket.access_condition(user)
|
||||
|
||||
# overview meta for navbar
|
||||
if !overview_selected
|
||||
list = []
|
||||
overviews.each {|overview|
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview.condition, user)
|
||||
|
||||
# loop each overview
|
||||
result = []
|
||||
overviews.each { |overview|
|
||||
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview.condition, data[:current_user])
|
||||
|
||||
# get count
|
||||
count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count()
|
||||
|
||||
# get meta info
|
||||
all = {
|
||||
name: overview.name,
|
||||
prio: overview.prio,
|
||||
link: overview.link,
|
||||
}
|
||||
|
||||
# push to result data
|
||||
result.push all.merge( { count: count } )
|
||||
}
|
||||
return result
|
||||
order_by = "#{overview.order[:by]} #{overview.order[:direction]}"
|
||||
if overview.group_by && !overview.group_by.empty?
|
||||
order_by = "#{overview.group_by}_id, #{order_by}"
|
||||
end
|
||||
|
||||
# get result list
|
||||
if data[:array]
|
||||
order_by = overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s
|
||||
if overview_selected.group_by && !overview_selected.group_by.empty?
|
||||
order_by = overview_selected.group_by + '_id, ' + order_by
|
||||
end
|
||||
ticket_result = Ticket.select('id, updated_at')
|
||||
.where(access_condition)
|
||||
.where(query_condition, *bind_condition)
|
||||
.order(order_by)
|
||||
.limit(500)
|
||||
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
|
||||
|
||||
tickets = Ticket.select('id')
|
||||
.where( access_condition )
|
||||
.where( query_condition, *bind_condition )
|
||||
.order( order_by )
|
||||
.limit( 500 )
|
||||
|
||||
ticket_ids = []
|
||||
tickets.each { |ticket|
|
||||
ticket_ids.push ticket.id
|
||||
tickets = []
|
||||
ticket_result.each { |ticket|
|
||||
ticket_item = {
|
||||
id: ticket.id,
|
||||
updated_at: ticket.updated_at,
|
||||
}
|
||||
|
||||
tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count()
|
||||
|
||||
return {
|
||||
ticket_ids: ticket_ids,
|
||||
tickets_count: tickets_count,
|
||||
overview: overview_selected_raw,
|
||||
tickets.push ticket_item
|
||||
}
|
||||
end
|
||||
|
||||
# get tickets for overview
|
||||
data[:start_page] ||= 1
|
||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
|
||||
tickets = Ticket.where( access_condition )
|
||||
.where( query_condition, *bind_condition )
|
||||
.order( overview_selected[:order][:by].to_s + ' ' + overview_selected[:order][:direction].to_s )
|
||||
|
||||
tickets_count = Ticket.where( access_condition ).where( query_condition, *bind_condition ).count()
|
||||
|
||||
{
|
||||
count = Ticket.where(access_condition).where(query_condition, *bind_condition).count()
|
||||
item = {
|
||||
overview: {
|
||||
id: overview.id,
|
||||
view: overview.link,
|
||||
updated_at: overview.updated_at,
|
||||
},
|
||||
tickets: tickets,
|
||||
tickets_count: tickets_count,
|
||||
overview: overview_selected_raw,
|
||||
count: count,
|
||||
}
|
||||
|
||||
list.push item
|
||||
}
|
||||
list
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
class Sessions::Backend::TicketOverviewIndex
|
||||
def initialize(user, client = nil, client_id = nil, ttl = 7)
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
@last_ticket_change = nil
|
||||
end
|
||||
|
||||
def load
|
||||
|
||||
# get whole collection
|
||||
overview = Ticket::Overviews.list(
|
||||
current_user: @user,
|
||||
)
|
||||
|
||||
# no data exists
|
||||
return if !overview
|
||||
|
||||
# no change exists
|
||||
return if @last_change == overview
|
||||
|
||||
# remember last state
|
||||
@last_change = overview
|
||||
|
||||
overview
|
||||
end
|
||||
|
||||
def client_key
|
||||
"as::load::#{self.class}::#{@user.id}::#{@client_id}"
|
||||
end
|
||||
|
||||
def push
|
||||
|
||||
# check check interval
|
||||
return if Sessions::CacheIn.get(client_key)
|
||||
|
||||
# reset check interval
|
||||
Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds })
|
||||
|
||||
# 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
|
||||
data = load
|
||||
|
||||
return if !data
|
||||
|
||||
if !@client
|
||||
return {
|
||||
event: 'ticket_overview_index',
|
||||
data: data,
|
||||
}
|
||||
end
|
||||
|
||||
@client.log "push overview_index for user #{@user.id}"
|
||||
@client.send(
|
||||
event: 'ticket_overview_index',
|
||||
data: data,
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,127 +1,125 @@
|
|||
class Sessions::Backend::TicketOverviewList
|
||||
def initialize(user, client = nil, client_id = nil, ttl = 7)
|
||||
|
||||
def self.reset(user_id)
|
||||
key = "TicketOverviewPull::#{user_id}"
|
||||
Cache.write(key, { needed: true })
|
||||
end
|
||||
|
||||
def initialize(user, client = nil, client_id = nil, ttl = 8)
|
||||
@user = user
|
||||
@client = client
|
||||
@client_id = client_id
|
||||
@ttl = ttl
|
||||
@last_change = nil
|
||||
@last_overview = {}
|
||||
@last_overview_change = nil
|
||||
@last_ticket_change = nil
|
||||
end
|
||||
|
||||
def load
|
||||
|
||||
# get whole collection
|
||||
overviews = Ticket::Overviews.all(
|
||||
current_user: @user,
|
||||
)
|
||||
return if !overviews
|
||||
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
|
||||
}
|
||||
index_and_lists = Ticket::Overviews.index(@user)
|
||||
|
||||
# no data exists
|
||||
return if !result || result.empty?
|
||||
return if !index_and_lists || index_and_lists.empty?
|
||||
|
||||
# no change exists
|
||||
return if @last_change == result
|
||||
return if @last_change == index_and_lists
|
||||
|
||||
# remember last state
|
||||
@last_change = result
|
||||
@last_change = index_and_lists
|
||||
|
||||
result
|
||||
index_and_lists
|
||||
end
|
||||
|
||||
def client_key
|
||||
"as::load::#{self.class}::#{@user.id}::#{@client_id}"
|
||||
end
|
||||
|
||||
def work_needed?
|
||||
key = "TicketOverviewPull::#{@user.id}"
|
||||
if Cache.get(key)
|
||||
Cache.delete(key)
|
||||
return true
|
||||
end
|
||||
return false if Sessions::CacheIn.get(client_key)
|
||||
true
|
||||
end
|
||||
|
||||
def push
|
||||
|
||||
# check interval
|
||||
return if Sessions::CacheIn.get(client_key)
|
||||
return if !work_needed?
|
||||
|
||||
# reset check interval
|
||||
Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds })
|
||||
|
||||
# check if min one ticket has changed
|
||||
# check if min one ticket or overview has changed
|
||||
last_overview_change = Overview.latest_change
|
||||
last_ticket_change = Ticket.latest_change
|
||||
return if last_ticket_change == @last_ticket_change
|
||||
return if last_ticket_change == @last_ticket_change && last_overview_change == @last_overview_change
|
||||
@last_overview_change = last_overview_change
|
||||
@last_ticket_change = last_ticket_change
|
||||
|
||||
# load current data
|
||||
items = load
|
||||
return if !items
|
||||
index_and_lists = load
|
||||
return if !index_and_lists
|
||||
|
||||
# push overview index
|
||||
indexes = []
|
||||
index_and_lists.each { |index|
|
||||
assets = {}
|
||||
overview = Overview.lookup(id: index[:overview][:id])
|
||||
meta = {
|
||||
name: overview.name,
|
||||
prio: overview.prio,
|
||||
link: overview.link,
|
||||
count: index[:count],
|
||||
}
|
||||
indexes.push meta
|
||||
}
|
||||
if @client
|
||||
@client.log "push overview_index for user #{@user.id}"
|
||||
@client.send(
|
||||
event: 'ticket_overview_index',
|
||||
data: indexes,
|
||||
)
|
||||
end
|
||||
|
||||
# push overviews
|
||||
results = []
|
||||
items.each { |item|
|
||||
index_and_lists.each { |index|
|
||||
|
||||
overview_data = item[:list]
|
||||
# do not deliver unchanged lists
|
||||
next if @last_overview[index[:overview][:id]] == index
|
||||
@last_overview[index[:overview][:id]] = index
|
||||
|
||||
assets = {}
|
||||
overview_data[:ticket_ids].each {|ticket_id|
|
||||
ticket = Ticket.find(ticket_id)
|
||||
overview = Overview.lookup(id: index[:overview][:id])
|
||||
assets = overview.assets(assets)
|
||||
index[:tickets].each {|ticket_meta|
|
||||
ticket = Ticket.lookup(id: ticket_meta[:id])
|
||||
assets = ticket.assets(assets)
|
||||
}
|
||||
|
||||
# get groups
|
||||
group_ids = []
|
||||
Group.where(active: true).each { |group|
|
||||
group_ids.push group.id
|
||||
}
|
||||
agents = {}
|
||||
User.of_role('Agent').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
|
||||
}
|
||||
}
|
||||
|
||||
if !@client
|
||||
result = {
|
||||
event: 'navupdate_ticket_overview',
|
||||
data: item[:index],
|
||||
event: 'ticket_overview_list',
|
||||
data: index,
|
||||
}
|
||||
results.push result
|
||||
else
|
||||
|
||||
@client.log "push overview_list for user #{@user.id}"
|
||||
@client.log "push overview_list #{overview.link} for user #{@user.id}"
|
||||
|
||||
# send update to browser
|
||||
@client.send(
|
||||
event: 'loadAssets',
|
||||
data: assets,
|
||||
event: 'loadAssets'
|
||||
)
|
||||
@client.send(
|
||||
data: {
|
||||
view: item[:index].link.to_s,
|
||||
overview: overview_data[:overview],
|
||||
ticket_ids: overview_data[:ticket_ids],
|
||||
tickets_count: overview_data[:tickets_count],
|
||||
bulk: {
|
||||
group_id__owner_id: groups_users,
|
||||
owner_id: [],
|
||||
},
|
||||
},
|
||||
event: 'ticket_overview_rebuild',
|
||||
event: 'ticket_overview_list',
|
||||
data: index,
|
||||
)
|
||||
end
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ module Sessions::CacheIn
|
|||
@@expires_in_ttl = {}
|
||||
# rubocop:enable Style/ClassVars
|
||||
|
||||
def self.delete( key )
|
||||
@@data.delete( key )
|
||||
@@data_time.delete( key )
|
||||
def self.delete(key)
|
||||
@@data.delete(key)
|
||||
@@data_time.delete(key)
|
||||
end
|
||||
|
||||
def self.set( key, value, params = {} )
|
||||
def self.set(key, value, params = {})
|
||||
if params[:expires_in]
|
||||
@@expires_in[key] = Time.zone.now + params[:expires_in]
|
||||
@@expires_in_ttl[key] = params[:expires_in]
|
||||
|
@ -21,7 +21,7 @@ module Sessions::CacheIn
|
|||
@@data_time[ key ] = Time.zone.now
|
||||
end
|
||||
|
||||
def self.expired( key, params = {} )
|
||||
def self.expired(key, params = {})
|
||||
|
||||
# expire if value never was set
|
||||
return true if !@@data.include? key
|
||||
|
@ -47,8 +47,8 @@ module Sessions::CacheIn
|
|||
false
|
||||
end
|
||||
|
||||
def self.get( key, params = {} )
|
||||
return if expired( key, params )
|
||||
def self.get(key, params = {})
|
||||
return if expired( key, params)
|
||||
@@data[ key ]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,6 @@ class Sessions::Client
|
|||
def fetch
|
||||
|
||||
backends = [
|
||||
'Sessions::Backend::TicketOverviewIndex',
|
||||
'Sessions::Backend::TicketOverviewList',
|
||||
'Sessions::Backend::Collections',
|
||||
'Sessions::Backend::Rss',
|
||||
|
@ -24,11 +23,11 @@ class Sessions::Client
|
|||
loop do
|
||||
|
||||
# get connection user
|
||||
session_data = Sessions.get( @client_id )
|
||||
session_data = Sessions.get(@client_id)
|
||||
return if !session_data
|
||||
return if !session_data[:user]
|
||||
return if !session_data[:user]['id']
|
||||
user = User.lookup( id: session_data[:user]['id'] )
|
||||
user = User.lookup(id: session_data[:user]['id'])
|
||||
return if !user
|
||||
|
||||
# init new backends
|
||||
|
@ -66,11 +65,11 @@ class Sessions::Client
|
|||
end
|
||||
|
||||
# send update to browser
|
||||
def send( data )
|
||||
Sessions.send( @client_id, data )
|
||||
def send(data)
|
||||
Sessions.send(@client_id, data)
|
||||
end
|
||||
|
||||
def log( msg )
|
||||
def log(msg)
|
||||
Rails.logger.debug "client(#{@client_id}) #{msg}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,30 @@ class Sessions::Event::Base
|
|||
end
|
||||
end
|
||||
|
||||
def valid_session?
|
||||
if !@session
|
||||
error = {
|
||||
event: 'error',
|
||||
data: {
|
||||
state: 'no_session',
|
||||
},
|
||||
}
|
||||
Sessions.send(@client_id, error)
|
||||
return
|
||||
end
|
||||
if !@session['id']
|
||||
error = {
|
||||
event: 'error',
|
||||
data: {
|
||||
state: 'no_session_user_id',
|
||||
},
|
||||
}
|
||||
Sessions.send(@client_id, error)
|
||||
return
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def log(level, data, client_id = nil)
|
||||
if !@options[:v]
|
||||
return if level == 'debug'
|
||||
|
|
8
lib/sessions/event/ticket_overview_index.rb
Normal file
8
lib/sessions/event/ticket_overview_index.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Sessions::Event::TicketOverviewIndex < Sessions::Event::Base
|
||||
|
||||
def run
|
||||
return if !valid_session?
|
||||
Sessions::Backend::TicketOverviewList.reset(@session['id'])
|
||||
end
|
||||
|
||||
end
|
8
lib/sessions/event/ticket_overview_list.rb
Normal file
8
lib/sessions/event/ticket_overview_list.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class Sessions::Event::TicketOverviewList < Sessions::Event::Base
|
||||
|
||||
def run
|
||||
return if !valid_session?
|
||||
Sessions::Backend::TicketOverviewList.reset(@session['id'])
|
||||
end
|
||||
|
||||
end
|
|
@ -637,7 +637,7 @@ class TestCase < Test::Unit::TestCase
|
|||
if params[:slow]
|
||||
sleep 2
|
||||
else
|
||||
sleep 0.6
|
||||
sleep 0.3
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1171,7 +1171,7 @@ wait untill text in selector disabppears
|
|||
instance = params[:browser] || @browser
|
||||
|
||||
(1..100).each do
|
||||
sleep 1
|
||||
sleep 0.2
|
||||
begin
|
||||
if instance.find_elements(css: '.navigation .tasks .task:first-child')[0]
|
||||
instance.mouse.move_to(instance.find_elements(css: '.navigation .tasks .task:first-child')[0])
|
||||
|
@ -1193,7 +1193,6 @@ wait untill text in selector disabppears
|
|||
# try again
|
||||
end
|
||||
end
|
||||
sleep 1
|
||||
assert(true, 'all tasks closed')
|
||||
end
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@ require 'test_helper'
|
|||
|
||||
class SessionBasicTicketTest < ActiveSupport::TestCase
|
||||
|
||||
test 'b ticket_overview_index' do
|
||||
test 'b ticket_overview_List' do
|
||||
UserInfo.current_user_id = 1
|
||||
Ticket.destroy_all
|
||||
|
||||
# create users
|
||||
roles = Role.where( name: [ 'Agent' ] )
|
||||
roles = Role.where(name: ['Agent'])
|
||||
groups = Group.all
|
||||
|
||||
agent1 = User.create_or_update(
|
||||
|
@ -22,81 +23,54 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
|||
)
|
||||
|
||||
agent1.roles = roles
|
||||
assert( agent1.save, 'create/update agent1' )
|
||||
assert(agent1.save, 'create/update agent1')
|
||||
|
||||
Ticket.create( title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 )
|
||||
|
||||
user = User.lookup( id: agent1.id )
|
||||
client1 = Sessions::Backend::TicketOverviewIndex.new(user, false, '123-1', 5)
|
||||
|
||||
# get as stream
|
||||
result1 = client1.push
|
||||
assert( result1, 'check ticket_overview_index' )
|
||||
|
||||
# next check should be empty / no changes
|
||||
result1 = client1.push
|
||||
assert( !result1, 'check ticket_overview_index - recall' )
|
||||
|
||||
# next check should be empty / no changes
|
||||
sleep 6
|
||||
result1 = client1.push
|
||||
assert( !result1, 'check ticket_overview_index - recall 2' )
|
||||
|
||||
# create ticket
|
||||
ticket = Ticket.create( title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 )
|
||||
sleep 6
|
||||
|
||||
# get as stream
|
||||
result1 = client1.push
|
||||
assert( result1, 'check ticket_overview_index - recall 3' )
|
||||
end
|
||||
|
||||
test 'b ticket_overview_list' do
|
||||
UserInfo.current_user_id = 1
|
||||
|
||||
# create users
|
||||
roles = Role.where( name: [ 'Agent' ] )
|
||||
groups = Group.all
|
||||
|
||||
agent1 = User.create_or_update(
|
||||
login: 'session-basic-ticket-agent-1',
|
||||
firstname: 'Session',
|
||||
lastname: 'session basic ' + rand(99_999).to_s,
|
||||
email: 'session-basic-ticket-agent-1@example.com',
|
||||
password: 'agentpw',
|
||||
active: true,
|
||||
roles: roles,
|
||||
groups: groups,
|
||||
)
|
||||
|
||||
agent1.roles = roles
|
||||
assert( agent1.save, 'create/update agent1' )
|
||||
|
||||
Ticket.create( title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 )
|
||||
|
||||
user = User.lookup( id: agent1.id )
|
||||
Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||
|
||||
user = User.lookup(id: agent1.id)
|
||||
client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1', 5)
|
||||
|
||||
# get as stream
|
||||
result1 = client1.push
|
||||
assert( result1, 'check ticket_overview_list' )
|
||||
assert(result1, 'check ticket_overview_List')
|
||||
|
||||
# next check should be empty / no changes
|
||||
result1 = client1.push
|
||||
assert( !result1, 'check ticket_overview_list - recall' )
|
||||
assert(!result1, 'check ticket_overview_index - recall')
|
||||
|
||||
# next check should be empty / no changes
|
||||
sleep 6
|
||||
result1 = client1.push
|
||||
assert( !result1, 'check ticket_overview_list - recall 2' )
|
||||
assert(!result1, 'check ticket_overview_index - recall 2')
|
||||
|
||||
# create ticket
|
||||
ticket = Ticket.create( title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1 )
|
||||
ticket = Ticket.create(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||
sleep 6
|
||||
|
||||
# get as stream
|
||||
result1 = client1.push
|
||||
assert( result1, 'check ticket_overview_list - recall 3' )
|
||||
assert(result1, 'check ticket_overview_index - recall 3')
|
||||
sleep 6
|
||||
|
||||
# chnage overview
|
||||
overviews = Ticket::Overviews.all(
|
||||
current_user: user,
|
||||
)
|
||||
overviews.first.touch
|
||||
|
||||
result1 = client1.push
|
||||
assert(result1, 'check ticket_overview_index - recall 4')
|
||||
|
||||
result1 = client1.push
|
||||
assert(!result1, 'check ticket_overview_index - recall 5')
|
||||
|
||||
Sessions::Backend::TicketOverviewList.reset(user.id)
|
||||
result1 = client1.push
|
||||
assert(!result1, 'check ticket_overview_index - recall 6')
|
||||
|
||||
ticket = Ticket.create(title: '12323 - 2', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||
Sessions::Backend::TicketOverviewList.reset(user.id)
|
||||
result1 = client1.push
|
||||
assert(result1, 'check ticket_overview_index - recall 7')
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue