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
|
@html elLocal
|
||||||
|
|
||||||
|
@bind 'overview:fetch', =>
|
||||||
|
update = =>
|
||||||
|
App.OverviewListCollection.fetch(@view)
|
||||||
|
@delay(update, 2800, 'overview:fetch')
|
||||||
|
|
||||||
active: (state) =>
|
active: (state) =>
|
||||||
@activeState = state
|
@activeState = state
|
||||||
|
|
||||||
|
@ -197,16 +202,16 @@ class Table extends App.Controller
|
||||||
super
|
super
|
||||||
|
|
||||||
if @view
|
if @view
|
||||||
@bindId = App.OverviewCollection.bind(@view, @render)
|
@bindId = App.OverviewListCollection.bind(@view, @render)
|
||||||
|
|
||||||
# rerender view, e. g. on langauge change
|
# rerender view, e. g. on langauge change
|
||||||
@bind 'ui:rerender', =>
|
@bind 'ui:rerender', =>
|
||||||
return if !@authenticate(true)
|
return if !@authenticate(true)
|
||||||
@render(App.OverviewCollection.get(@view))
|
@render(App.OverviewListCollection.get(@view))
|
||||||
|
|
||||||
release: =>
|
release: =>
|
||||||
if @bindId
|
if @bindId
|
||||||
App.OverviewCollection.unbind(@bindId)
|
App.OverviewListCollection.unbind(@bindId)
|
||||||
|
|
||||||
update: (params) =>
|
update: (params) =>
|
||||||
for key, value of params
|
for key, value of params
|
||||||
|
@ -219,24 +224,20 @@ class Table extends App.Controller
|
||||||
|
|
||||||
if @view
|
if @view
|
||||||
if @bindId
|
if @bindId
|
||||||
App.OverviewCollection.unbind(@bindId)
|
App.OverviewListCollection.unbind(@bindId)
|
||||||
@bindId = App.OverviewCollection.bind(@view, @render)
|
@bindId = App.OverviewListCollection.bind(@view, @render)
|
||||||
|
|
||||||
render: (data) =>
|
render: (data) =>
|
||||||
return if !data
|
return if !data
|
||||||
|
|
||||||
# use cache
|
# use cache
|
||||||
overview = data.overview
|
overview = data.overview
|
||||||
tickets_count = data.tickets_count
|
tickets = data.tickets
|
||||||
ticket_ids = data.ticket_ids
|
|
||||||
|
|
||||||
# use cache if no local change
|
|
||||||
App.Overview.refresh(overview, { clear: true })
|
|
||||||
|
|
||||||
# get ticket list
|
# get ticket list
|
||||||
ticket_list_show = []
|
ticket_list_show = []
|
||||||
for ticket_id in ticket_ids
|
for ticket in tickets
|
||||||
ticket_list_show.push App.Ticket.fullLocal(ticket_id)
|
ticket_list_show.push App.Ticket.fullLocal(ticket.id)
|
||||||
|
|
||||||
# if customer and no ticket exists, show the following message only
|
# if customer and no ticket exists, show the following message only
|
||||||
if !ticket_list_show[0] && @isRole('Customer')
|
if !ticket_list_show[0] && @isRole('Customer')
|
||||||
|
@ -622,8 +623,7 @@ class BulkForm extends App.Controller
|
||||||
@hide()
|
@hide()
|
||||||
|
|
||||||
# fetch overview data again
|
# fetch overview data again
|
||||||
App.OverviewIndexCollection.fetch()
|
App.Event.trigger('overview:fetch')
|
||||||
App.OverviewCollection.fetch(@view)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@holder.find('.table-overview').find('[name="bulk"]:checked').prop('checked', false)
|
@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
|
# fetch overview data again
|
||||||
if @reload_needed
|
if @reload_needed
|
||||||
App.OverviewIndexCollection.fetch()
|
App.OverviewListCollection.fetch(@overview.link)
|
||||||
App.OverviewCollection.fetch(@overview.link)
|
|
||||||
else
|
else
|
||||||
App.OverviewIndexCollection.trigger()
|
App.OverviewIndexCollection.trigger()
|
||||||
App.OverviewCollection.trigger(@overview.link)
|
App.OverviewListCollection.trigger(@overview.link)
|
||||||
|
|
||||||
# close modal
|
# close modal
|
||||||
@close()
|
@close()
|
||||||
|
|
|
@ -618,25 +618,25 @@ class App.TicketZoom extends App.Controller
|
||||||
if @overview_id
|
if @overview_id
|
||||||
current_position = 0
|
current_position = 0
|
||||||
overview = App.Overview.find(@overview_id)
|
overview = App.Overview.find(@overview_id)
|
||||||
list = App.OverviewCollection.get(overview.link)
|
list = App.OverviewListCollection.get(overview.link)
|
||||||
for ticket_id in list.ticket_ids
|
for ticket in list.tickets
|
||||||
current_position += 1
|
current_position += 1
|
||||||
if ticket_id is @ticket_id
|
if ticket.id is @ticket_id
|
||||||
next = list.ticket_ids[current_position]
|
next = list.tickets[current_position]
|
||||||
if next
|
if next
|
||||||
# close task
|
# close task
|
||||||
App.TaskManager.remove(@task_key)
|
App.TaskManager.remove(@task_key)
|
||||||
|
|
||||||
# open task via task manager to get overview information
|
# open task via task manager to get overview information
|
||||||
App.TaskManager.execute(
|
App.TaskManager.execute(
|
||||||
key: 'Ticket-' + next
|
key: 'Ticket-' + next.id
|
||||||
controller: 'TicketZoom'
|
controller: 'TicketZoom'
|
||||||
params:
|
params:
|
||||||
ticket_id: next
|
ticket_id: next.id
|
||||||
overview_id: @overview_id
|
overview_id: @overview_id
|
||||||
show: true
|
show: true
|
||||||
)
|
)
|
||||||
@navigate "ticket/zoom/#{next}"
|
@navigate "ticket/zoom/#{next.id}"
|
||||||
return
|
return
|
||||||
|
|
||||||
# fallback, close task
|
# fallback, close task
|
||||||
|
@ -658,6 +658,8 @@ class App.TicketZoom extends App.Controller
|
||||||
|
|
||||||
# enable form
|
# enable form
|
||||||
@formEnable(e)
|
@formEnable(e)
|
||||||
|
|
||||||
|
App.Event.trigger('overview:fetch')
|
||||||
)
|
)
|
||||||
|
|
||||||
bookmark: (e) ->
|
bookmark: (e) ->
|
||||||
|
|
|
@ -12,12 +12,12 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
||||||
@delay(@render, 2600, 'overview-navigator')
|
@delay(@render, 2600, 'overview-navigator')
|
||||||
|
|
||||||
@overview = App.Overview.find(@overview_id)
|
@overview = App.Overview.find(@overview_id)
|
||||||
@bindId = App.OverviewCollection.bind(@overview.link, lateUpdate, false)
|
@bindId = App.OverviewListCollection.bind(@overview.link, lateUpdate, false)
|
||||||
|
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
release: =>
|
release: =>
|
||||||
App.OverviewCollection.unbind(@bindId)
|
App.OverviewListCollection.unbind(@bindId)
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
if !@overview_id
|
if !@overview_id
|
||||||
|
@ -25,17 +25,17 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
||||||
return
|
return
|
||||||
|
|
||||||
# get overview data
|
# get overview data
|
||||||
overview = App.OverviewCollection.get(@overview.link)
|
overview = App.OverviewListCollection.get(@overview.link)
|
||||||
return if !overview
|
return if !overview
|
||||||
current_position = 0
|
current_position = 0
|
||||||
found = false
|
found = false
|
||||||
next = false
|
item_next = false
|
||||||
previous = false
|
item_previous = false
|
||||||
for ticket_id in overview.ticket_ids
|
for ticket in overview.tickets
|
||||||
current_position += 1
|
current_position += 1
|
||||||
next = overview.ticket_ids[current_position]
|
item_next = overview.tickets[current_position]
|
||||||
previous = overview.ticket_ids[current_position-2]
|
item_previous = overview.tickets[current_position-2]
|
||||||
if ticket_id is @ticket_id
|
if ticket.id is @ticket_id
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -44,10 +44,10 @@ class App.TicketZoomOverviewNavigator extends App.Controller
|
||||||
return
|
return
|
||||||
|
|
||||||
# get next/previous ticket
|
# get next/previous ticket
|
||||||
if next
|
if item_next
|
||||||
next = App.Ticket.find(next)
|
next = App.Ticket.find(item_next.id)
|
||||||
if previous
|
if item_previous
|
||||||
previous = App.Ticket.find(previous)
|
previous = App.Ticket.find(item_previous.id)
|
||||||
|
|
||||||
@html App.view('ticket_zoom/overview_navigator')(
|
@html App.view('ticket_zoom/overview_navigator')(
|
||||||
title: overview.overview.name
|
title: overview.overview.name
|
||||||
|
|
|
@ -53,5 +53,7 @@ class App.TicketZoomTitle extends App.Controller
|
||||||
# update taskbar with new meta data
|
# update taskbar with new meta data
|
||||||
@metaTaskUpdate()
|
@metaTaskUpdate()
|
||||||
|
|
||||||
|
App.Event.trigger('overview:fetch')
|
||||||
|
|
||||||
release: =>
|
release: =>
|
||||||
App.Ticket.unsubscribe(@subscribeId)
|
App.Ticket.unsubscribe(@subscribeId)
|
||||||
|
|
|
@ -44,6 +44,10 @@ class App._CollectionSingletonBase
|
||||||
delete @callbacks[counter]
|
delete @callbacks[counter]
|
||||||
|
|
||||||
fetch: =>
|
fetch: =>
|
||||||
|
if App.WebSocket.support()
|
||||||
|
App.WebSocket.send(event: @event)
|
||||||
|
return
|
||||||
|
|
||||||
return if @fetchActive
|
return if @fetchActive
|
||||||
@fetchActive = true
|
@fetchActive = true
|
||||||
App.Ajax.request(
|
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
|
_instance = undefined # Must be declared here to force the closure on the class
|
||||||
|
|
||||||
@get: (view) ->
|
@get: (view) ->
|
||||||
|
@ -35,18 +35,11 @@ class _Singleton
|
||||||
@counter = 0
|
@counter = 0
|
||||||
|
|
||||||
# websocket updates
|
# websocket updates
|
||||||
App.Event.bind 'ticket_overview_rebuild', (data) =>
|
App.Event.bind 'ticket_overview_list', (data) =>
|
||||||
if !@overview[data.view]
|
if !@overview[data.overview.view]
|
||||||
@overview[data.view] = {}
|
@overview[data.overview.view] = {}
|
||||||
|
@overview[data.overview.view] = data
|
||||||
# proccess assets, delete them later
|
@callback(data.overview.view, data)
|
||||||
if data.assets
|
|
||||||
App.Collection.loadAssets( data.assets )
|
|
||||||
delete data.assets
|
|
||||||
|
|
||||||
@overview[data.view] = data
|
|
||||||
|
|
||||||
@callback(data.view, data)
|
|
||||||
|
|
||||||
get: (view) ->
|
get: (view) ->
|
||||||
@overview[view]
|
@overview[view]
|
||||||
|
@ -70,6 +63,14 @@ class _Singleton
|
||||||
delete @callbacks[counter]
|
delete @callbacks[counter]
|
||||||
|
|
||||||
fetch: (view) =>
|
fetch: (view) =>
|
||||||
|
if App.WebSocket.support()
|
||||||
|
App.WebSocket.send(
|
||||||
|
event: 'ticket_overview_list'
|
||||||
|
view: view
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
App.OverviewIndexCollection.fetch()
|
||||||
return if @fetchActive[view]
|
return if @fetchActive[view]
|
||||||
@fetchActive[view] = true
|
@fetchActive[view] = true
|
||||||
App.Ajax.request(
|
App.Ajax.request(
|
||||||
|
@ -81,15 +82,10 @@ class _Singleton
|
||||||
processData: true,
|
processData: true,
|
||||||
success: (data) =>
|
success: (data) =>
|
||||||
@fetchActive[view] = false
|
@fetchActive[view] = false
|
||||||
|
|
||||||
# proccess assets, delete them later
|
|
||||||
if data.assets
|
if data.assets
|
||||||
App.Collection.loadAssets(data.assets)
|
App.Collection.loadAssets(data.assets)
|
||||||
delete data.assets
|
@overview[data.index.overview.view] = data.index
|
||||||
|
@callback(view, data.index)
|
||||||
@overview[data.view] = data
|
|
||||||
|
|
||||||
@callback(view, data)
|
|
||||||
error: =>
|
error: =>
|
||||||
@fetchActive[view] = false
|
@fetchActive[view] = false
|
||||||
)
|
)
|
|
@ -30,6 +30,11 @@ class App.WebSocket
|
||||||
_instance ?= new _webSocketSingleton
|
_instance ?= new _webSocketSingleton
|
||||||
_instance.spool()
|
_instance.spool()
|
||||||
|
|
||||||
|
@support: ->
|
||||||
|
if _instance == undefined
|
||||||
|
_instance ?= new _webSocketSingleton
|
||||||
|
_instance.support()
|
||||||
|
|
||||||
# The actual Singleton class
|
# The actual Singleton class
|
||||||
class _webSocketSingleton extends App.Controller
|
class _webSocketSingleton extends App.Controller
|
||||||
@include App.LogInclude
|
@include App.LogInclude
|
||||||
|
@ -103,6 +108,9 @@ class _webSocketSingleton extends App.Controller
|
||||||
channel: ->
|
channel: ->
|
||||||
@backend
|
@backend
|
||||||
|
|
||||||
|
support: ->
|
||||||
|
@supported
|
||||||
|
|
||||||
send: (data) =>
|
send: (data) =>
|
||||||
if @backend is 'ajax'
|
if @backend is 'ajax'
|
||||||
@_ajaxSend(data)
|
@_ajaxSend(data)
|
||||||
|
@ -180,6 +188,7 @@ class _webSocketSingleton extends App.Controller
|
||||||
connect: =>
|
connect: =>
|
||||||
|
|
||||||
if !window.WebSocket
|
if !window.WebSocket
|
||||||
|
@supported = false
|
||||||
@backend = 'ajax'
|
@backend = 'ajax'
|
||||||
@log 'debug', 'no support of websocket, use ajax long polling'
|
@log 'debug', 'no support of websocket, use ajax long polling'
|
||||||
@_ajaxInit()
|
@_ajaxInit()
|
||||||
|
|
|
@ -10,80 +10,42 @@ class TicketOverviewsController < ApplicationController
|
||||||
|
|
||||||
# get navbar overview data
|
# get navbar overview data
|
||||||
if !params[:view]
|
if !params[:view]
|
||||||
result = Ticket::Overviews.list(
|
index_and_lists = Ticket::Overviews.index(current_user)
|
||||||
current_user: current_user,
|
indexes = []
|
||||||
)
|
index_and_lists.each { |index|
|
||||||
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
|
|
||||||
assets = {}
|
assets = {}
|
||||||
overview[:ticket_ids].each {|ticket_id|
|
overview = Overview.lookup(id: index[:overview][:id])
|
||||||
ticket = Ticket.lookup( id: ticket_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)
|
assets = ticket.assets(assets)
|
||||||
}
|
}
|
||||||
|
result = index
|
||||||
# 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 )
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# return result
|
|
||||||
render json: {
|
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,
|
assets: assets,
|
||||||
|
index: result,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ class Overview < ApplicationModel
|
||||||
before_create :fill_link
|
before_create :fill_link
|
||||||
before_update :fill_link
|
before_update :fill_link
|
||||||
|
|
||||||
|
latest_change_support
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# fill link
|
# fill link
|
||||||
|
|
|
@ -3,10 +3,10 @@ module Ticket::Overviews
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
all overview by user
|
all overviews by user
|
||||||
|
|
||||||
result = Ticket::Overviews.all(
|
result = Ticket::Overviews.all(
|
||||||
:current_user => User.find(123),
|
current_user: User.find(123),
|
||||||
)
|
)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -36,116 +36,84 @@ returns
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
selected overview by user
|
result = Ticket::Overviews.index(User.find(123))
|
||||||
|
|
||||||
result = Ticket::Overviews.list(
|
|
||||||
current_user: User.find(123),
|
|
||||||
view: 'some_view_url',
|
|
||||||
)
|
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
|
||||||
result = {
|
[
|
||||||
tickets: tickets, # [ticket1, ticket2, ticket3]
|
{
|
||||||
tickets_count: tickets_count, # count of tickets
|
overview: {
|
||||||
overview: overview_selected_raw, # overview attributes
|
id: 123,
|
||||||
|
updated_at: ...,
|
||||||
|
},
|
||||||
|
count: 3,
|
||||||
|
tickets: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
updated_at: ...,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
updated_at: ...,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
updated_at: ...,
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.list (data)
|
def self.index(user)
|
||||||
|
overviews = Ticket::Overviews.all(
|
||||||
overviews = all(data)
|
current_user: user,
|
||||||
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
|
|
||||||
|
|
||||||
# get only tickets with permissions
|
# get only tickets with permissions
|
||||||
access_condition = Ticket.access_condition( data[:current_user] )
|
access_condition = Ticket.access_condition(user)
|
||||||
|
|
||||||
# overview meta for navbar
|
list = []
|
||||||
if !overview_selected
|
|
||||||
|
|
||||||
# loop each overview
|
|
||||||
result = []
|
|
||||||
overviews.each {|overview|
|
overviews.each {|overview|
|
||||||
|
query_condition, bind_condition = Ticket.selector2sql(overview.condition, user)
|
||||||
|
|
||||||
query_condition, bind_condition = Ticket.selector2sql(overview.condition, data[:current_user])
|
order_by = "#{overview.order[:by]} #{overview.order[:direction]}"
|
||||||
|
if overview.group_by && !overview.group_by.empty?
|
||||||
# get count
|
order_by = "#{overview.group_by}_id, #{order_by}"
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# get result list
|
ticket_result = Ticket.select('id, updated_at')
|
||||||
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
|
|
||||||
|
|
||||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
|
|
||||||
|
|
||||||
tickets = Ticket.select('id')
|
|
||||||
.where(access_condition)
|
.where(access_condition)
|
||||||
.where(query_condition, *bind_condition)
|
.where(query_condition, *bind_condition)
|
||||||
.order(order_by)
|
.order(order_by)
|
||||||
.limit(500)
|
.limit(500)
|
||||||
|
|
||||||
ticket_ids = []
|
tickets = []
|
||||||
tickets.each { |ticket|
|
ticket_result.each { |ticket|
|
||||||
ticket_ids.push ticket.id
|
ticket_item = {
|
||||||
|
id: ticket.id,
|
||||||
|
updated_at: ticket.updated_at,
|
||||||
}
|
}
|
||||||
|
tickets.push ticket_item
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
end
|
count = Ticket.where(access_condition).where(query_condition, *bind_condition).count()
|
||||||
|
item = {
|
||||||
# get tickets for overview
|
overview: {
|
||||||
data[:start_page] ||= 1
|
id: overview.id,
|
||||||
query_condition, bind_condition = Ticket.selector2sql(overview_selected.condition, data[:current_user])
|
view: overview.link,
|
||||||
tickets = Ticket.where( access_condition )
|
updated_at: overview.updated_at,
|
||||||
.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()
|
|
||||||
|
|
||||||
{
|
|
||||||
tickets: tickets,
|
tickets: tickets,
|
||||||
tickets_count: tickets_count,
|
count: count,
|
||||||
overview: overview_selected_raw,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list.push item
|
||||||
|
}
|
||||||
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
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
|
@user = user
|
||||||
@client = client
|
@client = client
|
||||||
@client_id = client_id
|
@client_id = client_id
|
||||||
@ttl = ttl
|
@ttl = ttl
|
||||||
@last_change = nil
|
@last_change = nil
|
||||||
|
@last_overview = {}
|
||||||
|
@last_overview_change = nil
|
||||||
@last_ticket_change = nil
|
@last_ticket_change = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def load
|
def load
|
||||||
|
|
||||||
# get whole collection
|
# get whole collection
|
||||||
overviews = Ticket::Overviews.all(
|
index_and_lists = Ticket::Overviews.index(@user)
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
# no data exists
|
# no data exists
|
||||||
return if !result || result.empty?
|
return if !index_and_lists || index_and_lists.empty?
|
||||||
|
|
||||||
# no change exists
|
# no change exists
|
||||||
return if @last_change == result
|
return if @last_change == index_and_lists
|
||||||
|
|
||||||
# remember last state
|
# remember last state
|
||||||
@last_change = result
|
@last_change = index_and_lists
|
||||||
|
|
||||||
result
|
index_and_lists
|
||||||
end
|
end
|
||||||
|
|
||||||
def client_key
|
def client_key
|
||||||
"as::load::#{self.class}::#{@user.id}::#{@client_id}"
|
"as::load::#{self.class}::#{@user.id}::#{@client_id}"
|
||||||
end
|
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
|
def push
|
||||||
|
|
||||||
# check interval
|
return if !work_needed?
|
||||||
return if Sessions::CacheIn.get(client_key)
|
|
||||||
|
|
||||||
# reset check interval
|
# reset check interval
|
||||||
Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds })
|
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
|
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
|
@last_ticket_change = last_ticket_change
|
||||||
|
|
||||||
# load current data
|
# load current data
|
||||||
items = load
|
index_and_lists = load
|
||||||
return if !items
|
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
|
# push overviews
|
||||||
results = []
|
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 = {}
|
assets = {}
|
||||||
overview_data[:ticket_ids].each {|ticket_id|
|
overview = Overview.lookup(id: index[:overview][:id])
|
||||||
ticket = Ticket.find(ticket_id)
|
assets = overview.assets(assets)
|
||||||
|
index[:tickets].each {|ticket_meta|
|
||||||
|
ticket = Ticket.lookup(id: ticket_meta[:id])
|
||||||
assets = ticket.assets(assets)
|
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
|
if !@client
|
||||||
result = {
|
result = {
|
||||||
event: 'navupdate_ticket_overview',
|
event: 'ticket_overview_list',
|
||||||
data: item[:index],
|
data: index,
|
||||||
}
|
}
|
||||||
results.push result
|
results.push result
|
||||||
else
|
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
|
# send update to browser
|
||||||
@client.send(
|
@client.send(
|
||||||
|
event: 'loadAssets',
|
||||||
data: assets,
|
data: assets,
|
||||||
event: 'loadAssets'
|
|
||||||
)
|
)
|
||||||
@client.send(
|
@client.send(
|
||||||
data: {
|
event: 'ticket_overview_list',
|
||||||
view: item[:index].link.to_s,
|
data: index,
|
||||||
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',
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ class Sessions::Client
|
||||||
def fetch
|
def fetch
|
||||||
|
|
||||||
backends = [
|
backends = [
|
||||||
'Sessions::Backend::TicketOverviewIndex',
|
|
||||||
'Sessions::Backend::TicketOverviewList',
|
'Sessions::Backend::TicketOverviewList',
|
||||||
'Sessions::Backend::Collections',
|
'Sessions::Backend::Collections',
|
||||||
'Sessions::Backend::Rss',
|
'Sessions::Backend::Rss',
|
||||||
|
|
|
@ -25,6 +25,30 @@ class Sessions::Event::Base
|
||||||
end
|
end
|
||||||
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)
|
def log(level, data, client_id = nil)
|
||||||
if !@options[:v]
|
if !@options[:v]
|
||||||
return if level == 'debug'
|
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]
|
if params[:slow]
|
||||||
sleep 2
|
sleep 2
|
||||||
else
|
else
|
||||||
sleep 0.6
|
sleep 0.3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1171,7 +1171,7 @@ wait untill text in selector disabppears
|
||||||
instance = params[:browser] || @browser
|
instance = params[:browser] || @browser
|
||||||
|
|
||||||
(1..100).each do
|
(1..100).each do
|
||||||
sleep 1
|
sleep 0.2
|
||||||
begin
|
begin
|
||||||
if instance.find_elements(css: '.navigation .tasks .task:first-child')[0]
|
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])
|
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
|
# try again
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep 1
|
|
||||||
assert(true, 'all tasks closed')
|
assert(true, 'all tasks closed')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@ require 'test_helper'
|
||||||
|
|
||||||
class SessionBasicTicketTest < ActiveSupport::TestCase
|
class SessionBasicTicketTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'b ticket_overview_index' do
|
test 'b ticket_overview_List' do
|
||||||
UserInfo.current_user_id = 1
|
UserInfo.current_user_id = 1
|
||||||
|
Ticket.destroy_all
|
||||||
|
|
||||||
# create users
|
# create users
|
||||||
roles = Role.where(name: ['Agent'])
|
roles = Role.where(name: ['Agent'])
|
||||||
|
@ -27,11 +28,10 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
||||||
Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
|
||||||
|
|
||||||
user = User.lookup(id: agent1.id)
|
user = User.lookup(id: agent1.id)
|
||||||
client1 = Sessions::Backend::TicketOverviewIndex.new(user, false, '123-1', 5)
|
client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1', 5)
|
||||||
|
|
||||||
# get as stream
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert( result1, 'check ticket_overview_index' )
|
assert(result1, 'check ticket_overview_List')
|
||||||
|
|
||||||
# next check should be empty / no changes
|
# next check should be empty / no changes
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
|
@ -46,57 +46,31 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
||||||
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
|
sleep 6
|
||||||
|
|
||||||
# get as stream
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert(result1, 'check ticket_overview_index - recall 3')
|
assert(result1, 'check ticket_overview_index - recall 3')
|
||||||
end
|
sleep 6
|
||||||
|
|
||||||
test 'b ticket_overview_list' do
|
# chnage overview
|
||||||
UserInfo.current_user_id = 1
|
overviews = Ticket::Overviews.all(
|
||||||
|
current_user: user,
|
||||||
# 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,
|
|
||||||
)
|
)
|
||||||
|
overviews.first.touch
|
||||||
|
|
||||||
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 )
|
|
||||||
|
|
||||||
client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1', 5)
|
|
||||||
|
|
||||||
# get as stream
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert( result1, 'check ticket_overview_list' )
|
assert(result1, 'check ticket_overview_index - recall 4')
|
||||||
|
|
||||||
# next check should be empty / no changes
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert( !result1, 'check ticket_overview_list - recall' )
|
assert(!result1, 'check ticket_overview_index - recall 5')
|
||||||
|
|
||||||
# next check should be empty / no changes
|
Sessions::Backend::TicketOverviewList.reset(user.id)
|
||||||
sleep 6
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert( !result1, 'check ticket_overview_list - recall 2' )
|
assert(!result1, 'check ticket_overview_index - recall 6')
|
||||||
|
|
||||||
# create ticket
|
ticket = Ticket.create(title: '12323 - 2', 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 )
|
Sessions::Backend::TicketOverviewList.reset(user.id)
|
||||||
sleep 6
|
|
||||||
|
|
||||||
# get as stream
|
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert( result1, 'check ticket_overview_list - recall 3' )
|
assert(result1, 'check ticket_overview_index - recall 7')
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue