Improved background fetching of data.
This commit is contained in:
parent
54d5cab51d
commit
355b32d715
2 changed files with 68 additions and 44 deletions
|
@ -13,8 +13,8 @@ class App.DashboardTicket extends App.Controller
|
|||
@start_page = 1
|
||||
@navupdate '#'
|
||||
|
||||
# refresh list ever 60 sec.
|
||||
@interval( @fetch, 60000, 'dashboard_ticket_overview_' + @view )
|
||||
# refresh list ever 40 sec.
|
||||
@interval( @fetch, 400000, 'dashboard_ticket_overview_' + @view )
|
||||
|
||||
fetch: =>
|
||||
|
||||
|
@ -63,6 +63,7 @@ class App.DashboardTicket extends App.Controller
|
|||
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||
|
||||
# set cache
|
||||
if @start_page is 1
|
||||
window.LastRefresh[ @key ] = data
|
||||
|
||||
@render( data )
|
||||
|
|
|
@ -18,7 +18,7 @@ class Index extends App.Controller
|
|||
|
||||
# set title
|
||||
@title ''
|
||||
@navupdate '#ticket_view'
|
||||
@navupdate '#ticket/view/' + @view
|
||||
|
||||
@tickets = []
|
||||
@tickets_count = 0
|
||||
|
@ -26,10 +26,23 @@ class Index extends App.Controller
|
|||
@meta = {}
|
||||
@bulk = {}
|
||||
|
||||
# @render()
|
||||
@fetch()
|
||||
# set controller to active
|
||||
Config['ActiveController'] = '#ticket_overview_' + @view
|
||||
|
||||
fetch: ->
|
||||
# refresh list ever 40 sec.
|
||||
@interval( @fetch, 400000, 'ticket_overview_' + @view )
|
||||
|
||||
fetch: =>
|
||||
|
||||
# set new key
|
||||
@key = @view
|
||||
|
||||
# use cache of first page
|
||||
if window.LastRefresh[ @key ] && @start_page is 1
|
||||
@overview = window.LastRefresh[ @key ].overview
|
||||
@tickets_count = window.LastRefresh[ @key ].tickets_count
|
||||
@tickets = window.LastRefresh[ @key ].tickets
|
||||
@render()
|
||||
|
||||
# get data
|
||||
if @req
|
||||
|
@ -44,7 +57,10 @@ class Index extends App.Controller
|
|||
start_page: @start_page,
|
||||
}
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
success: @load
|
||||
)
|
||||
|
||||
load: (data) =>
|
||||
|
||||
# get meta data
|
||||
@overview = data.overview
|
||||
|
@ -70,18 +86,23 @@ class Index extends App.Controller
|
|||
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||
|
||||
# remember ticket order
|
||||
if @start_page is 1
|
||||
@tickets = data.tickets
|
||||
else
|
||||
@tickets = @tickets.concat( data.tickets )
|
||||
|
||||
# remember ticket count
|
||||
@tickets_count = data.tickets_count
|
||||
|
||||
|
||||
# remeber bulk attributes
|
||||
@bulk = data.bulk
|
||||
|
||||
# set cache
|
||||
if @start_page is 1
|
||||
window.LastRefresh[ @key ] = data
|
||||
|
||||
# render page
|
||||
@render()
|
||||
)
|
||||
|
||||
# refresh/load default collections
|
||||
# for key, value of data.default_collections
|
||||
|
@ -89,6 +110,8 @@ class Index extends App.Controller
|
|||
|
||||
render: ->
|
||||
|
||||
return if Config['ActiveController'] isnt '#ticket_overview_' + @view
|
||||
|
||||
# get total pages
|
||||
pages_total = parseInt( ( @tickets_count / @overview.view[@view_mode].per_page ) + 0.99999 ) || 1
|
||||
|
||||
|
|
Loading…
Reference in a new issue