Improved AJAX pulling.
This commit is contained in:
parent
8a1226a708
commit
54d5cab51d
9 changed files with 222 additions and 158 deletions
|
@ -539,7 +539,29 @@ class App.Controller extends Spine.Controller
|
|||
|
||||
return newInstance
|
||||
|
||||
interval: (action, interval, interval_id) =>
|
||||
|
||||
# check global var
|
||||
if !@intervalID
|
||||
@intervalID = {}
|
||||
|
||||
action()
|
||||
|
||||
# auto save
|
||||
every = (ms, cb) -> setInterval cb, ms
|
||||
|
||||
# clear auto save
|
||||
clearInterval( @intervalID[interval_id] ) if @intervalID[interval_id]
|
||||
|
||||
# request new data
|
||||
@intervalID[interval_id] = every interval, () =>
|
||||
action()
|
||||
|
||||
userPopups: (position = 'right') ->
|
||||
|
||||
# remove old popovers
|
||||
$('.popover-inner').parent().remove()
|
||||
|
||||
# show user popup
|
||||
$('.user-data').popover(
|
||||
delay: { show: 500, hide: 1200 },
|
||||
|
@ -570,6 +592,10 @@ class App.Controller extends Spine.Controller
|
|||
)
|
||||
|
||||
userTicketPopups: (data) ->
|
||||
|
||||
# remove old popovers
|
||||
$('.popover-inner').parent().remove()
|
||||
|
||||
# get data
|
||||
@tickets = {}
|
||||
ajax = new App.Ajax
|
||||
|
|
|
@ -6,22 +6,33 @@ class App.DashboardActivityStream extends App.Controller
|
|||
|
||||
constructor: ->
|
||||
super
|
||||
# @log 'aaaa', @el
|
||||
|
||||
@items = []
|
||||
|
||||
# refresh list ever 140 sec.
|
||||
@interval( @fetch, 140000, 'dashboard_activity_stream' )
|
||||
|
||||
fetch: =>
|
||||
|
||||
# use cache of first page
|
||||
if window.LastRefresh[ 'dashboard_activity_stream' ]
|
||||
@render( window.LastRefresh[ 'dashboard_activity_stream' ] )
|
||||
|
||||
# get data
|
||||
if @req
|
||||
@req.abort()
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/activity_stream',
|
||||
data: {
|
||||
limit: @limit,
|
||||
}
|
||||
processData: true,
|
||||
# data: JSON.stringify( view: @view ),
|
||||
success: (data, status, xhr) =>
|
||||
@items = data.activity_stream
|
||||
success: @load
|
||||
)
|
||||
|
||||
load: (data) =>
|
||||
items = data.activity_stream
|
||||
|
||||
# load user collection
|
||||
@loadCollection( type: 'User', data: data.users )
|
||||
|
@ -29,23 +40,24 @@ class App.DashboardActivityStream extends App.Controller
|
|||
# load ticket collection
|
||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||
|
||||
@render()
|
||||
)
|
||||
# set cache
|
||||
window.LastRefresh[ 'dashboard_activity_stream' ] = items
|
||||
|
||||
@render(items)
|
||||
|
||||
render: ->
|
||||
render: (items) ->
|
||||
|
||||
# load user data
|
||||
for item in @items
|
||||
for item in items
|
||||
item.created_by = App.User.find(item.created_by_id)
|
||||
|
||||
# load ticket data
|
||||
for item in @items
|
||||
for item in items
|
||||
item.ticket = App.Ticket.find(item.o_id)
|
||||
|
||||
html = App.view('dashboard/activity_stream')(
|
||||
head: 'Activity Stream',
|
||||
items: @items
|
||||
items: items
|
||||
)
|
||||
html = $(html)
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@ class App.DashboardRecentViewed extends App.Controller
|
|||
@items = []
|
||||
|
||||
# get data
|
||||
if @req
|
||||
@req.abort()
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/recent_viewed',
|
||||
data: {
|
||||
|
|
|
@ -3,13 +3,22 @@ $ = jQuery.sub()
|
|||
class App.DashboardRss extends App.Controller
|
||||
constructor: ->
|
||||
super
|
||||
# @log 'aaaa', @el
|
||||
|
||||
@items = []
|
||||
|
||||
# refresh list ever 600 sec.
|
||||
@interval( @fetch, 6000000, 'dashboard_rss' )
|
||||
|
||||
fetch: =>
|
||||
|
||||
# use cache of first page
|
||||
if window.LastRefresh[ 'dashboard_rss' ]
|
||||
@render( window.LastRefresh[ 'dashboard_rss' ] )
|
||||
|
||||
# get data
|
||||
if @req
|
||||
@req.abort()
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/rss_fetch',
|
||||
data: {
|
||||
|
@ -17,15 +26,21 @@ class App.DashboardRss extends App.Controller
|
|||
url: @url,
|
||||
}
|
||||
processData: true,
|
||||
success: (data, status, xhr) =>
|
||||
@items = data.items || []
|
||||
@render()
|
||||
success: @load
|
||||
)
|
||||
|
||||
render: ->
|
||||
load: (data) =>
|
||||
items = data.items || []
|
||||
|
||||
# set cache
|
||||
window.LastRefresh[ 'dashboard_rss' ] = items
|
||||
|
||||
@render(items)
|
||||
|
||||
render: (items) ->
|
||||
html = App.view('dashboard/rss')(
|
||||
head: @head,
|
||||
items: @items
|
||||
items: items
|
||||
)
|
||||
html = $(html)
|
||||
@html html
|
||||
|
|
|
@ -13,13 +13,23 @@ class App.DashboardTicket extends App.Controller
|
|||
@start_page = 1
|
||||
@navupdate '#'
|
||||
|
||||
@fetch()
|
||||
# refresh list ever 60 sec.
|
||||
@interval( @fetch, 60000, 'dashboard_ticket_overview_' + @view )
|
||||
|
||||
fetch: ->
|
||||
fetch: =>
|
||||
|
||||
# set new key
|
||||
@key = @view
|
||||
|
||||
# use cache of first page
|
||||
if window.LastRefresh[ @key ] && @start_page is 1
|
||||
@render( window.LastRefresh[ @key ] )
|
||||
|
||||
# get data
|
||||
if @req
|
||||
@req.abort()
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/ticket_overviews',
|
||||
data: {
|
||||
|
@ -28,17 +38,18 @@ class App.DashboardTicket extends App.Controller
|
|||
start_page: @start_page,
|
||||
}
|
||||
processData: true,
|
||||
# data: JSON.stringify( view: @view ),
|
||||
success: (data, status, xhr) =>
|
||||
success: @load
|
||||
)
|
||||
|
||||
load: (data) =>
|
||||
|
||||
# get meta data
|
||||
@overview = data.overview
|
||||
App.Overview.refresh( @overview, options: { clear: true } )
|
||||
App.Overview.refresh( data.overview, options: { clear: true } )
|
||||
|
||||
App.Overview.unbind('local:rerender')
|
||||
App.Overview.bind 'local:rerender', (record) =>
|
||||
@log 'rerender...', record
|
||||
@render()
|
||||
@render(data)
|
||||
|
||||
App.Overview.unbind('local:refetch')
|
||||
App.Overview.bind 'local:refetch', (record) =>
|
||||
|
@ -51,13 +62,16 @@ class App.DashboardTicket extends App.Controller
|
|||
# load ticket collection
|
||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||
|
||||
@tickets = data.tickets
|
||||
# set cache
|
||||
window.LastRefresh[ @key ] = data
|
||||
|
||||
@render( data )
|
||||
|
||||
render: (data) ->
|
||||
|
||||
@overview = data.overview
|
||||
@tickets_count = data.tickets_count
|
||||
|
||||
@render()
|
||||
)
|
||||
|
||||
render: ->
|
||||
@tickets = data.tickets
|
||||
|
||||
pages_total = parseInt( ( @tickets_count / @overview.view.d.per_page ) + 0.99999 ) || 1
|
||||
html = App.view('dashboard/ticket')(
|
||||
|
@ -80,7 +94,7 @@ class App.DashboardTicket extends App.Controller
|
|||
|
||||
if _.isEmpty(@tickets)
|
||||
table = ''
|
||||
# table = '-none-'
|
||||
table = '-none-'
|
||||
|
||||
# append content table
|
||||
html.find('.table-overview').append(table)
|
||||
|
|
|
@ -29,7 +29,9 @@ class Index extends App.Controller
|
|||
fetch: () ->
|
||||
# get data
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
if @req
|
||||
@req.abort()
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/ticket_create',
|
||||
data: {
|
||||
|
|
|
@ -31,10 +31,11 @@ class Index extends App.Controller
|
|||
|
||||
fetch: ->
|
||||
|
||||
|
||||
# get data
|
||||
if @req
|
||||
@req.abort()
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/ticket_overviews',
|
||||
data: {
|
||||
|
|
|
@ -10,10 +10,10 @@ class App.Navigation extends App.Controller
|
|||
@render()
|
||||
|
||||
sync_ticket_overview = =>
|
||||
@sync(@ticket_overview, 30000,'interval_id_ticket_overview')
|
||||
@interval( @ticket_overview, 30000, 'nav_ticket_overview' )
|
||||
|
||||
sync_recent_viewed = =>
|
||||
@sync(@recent_viewed, 40000, 'interval_id_recent_viewed')
|
||||
@interval( @recent_viewed, 40000, 'nav_recent_viewed' )
|
||||
|
||||
Spine.bind 'navupdate', (data) =>
|
||||
@update(arguments[0])
|
||||
|
@ -29,8 +29,6 @@ class App.Navigation extends App.Controller
|
|||
|
||||
# rerender if new overview data is there
|
||||
@delay( sync_ticket_overview, 800 )
|
||||
@delay( sync_ticket_overview, 2000 )
|
||||
|
||||
@delay( sync_recent_viewed, 1000 )
|
||||
|
||||
render: (user) ->
|
||||
|
@ -128,24 +126,6 @@ class App.Navigation extends App.Controller
|
|||
@el.find("[href=\"#{url}\"]").parents('li').addClass('active')
|
||||
# @el.find("[href*=\"#{url}\"]").parents('li').addClass('active')
|
||||
|
||||
sync: (action, interval, interval_id) =>
|
||||
|
||||
# check global var
|
||||
if !@intervalID
|
||||
@intervalID = {}
|
||||
|
||||
action()
|
||||
|
||||
# auto save
|
||||
every = (ms, cb) -> setInterval cb, ms
|
||||
|
||||
# clear auto save
|
||||
clearInterval(@intervalID[interval_id]) if @intervalID[interval_id]
|
||||
|
||||
# request new data
|
||||
@intervalID[interval_id] = every interval, () =>
|
||||
action()
|
||||
|
||||
# get data
|
||||
ticket_overview: =>
|
||||
|
||||
|
@ -158,8 +138,12 @@ class App.Navigation extends App.Controller
|
|||
if !window.Session['id']
|
||||
return
|
||||
|
||||
# only of lod request is already done
|
||||
|
||||
if !@req_overview
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
# @req_overview.abort()
|
||||
@req_overview = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/ticket_overviews',
|
||||
data: {},
|
||||
|
@ -184,8 +168,10 @@ class App.Navigation extends App.Controller
|
|||
|
||||
# rebuild navbar
|
||||
Spine.trigger 'navrebuild', window.Session
|
||||
)
|
||||
|
||||
# reset ajax call
|
||||
@req_overview = undefined
|
||||
)
|
||||
|
||||
# get data
|
||||
recent_viewed: =>
|
||||
|
@ -199,8 +185,10 @@ class App.Navigation extends App.Controller
|
|||
if !window.Session['id']
|
||||
return
|
||||
|
||||
# only of lod request is already done
|
||||
if !@req_recent_viewed
|
||||
@ajax = new App.Ajax
|
||||
@ajax.ajax(
|
||||
@req_recent_viewed = @ajax.ajax(
|
||||
type: 'GET',
|
||||
url: '/recent_viewed',
|
||||
data: {
|
||||
|
@ -246,4 +234,7 @@ class App.Navigation extends App.Controller
|
|||
|
||||
# rebuild navbar
|
||||
Spine.trigger 'navrebuild', window.Session
|
||||
|
||||
# reset ajax call
|
||||
@req_recent_viewed = undefined
|
||||
)
|
||||
|
|
|
@ -6,3 +6,4 @@ Config.product_name = 'Zammad'
|
|||
Config.requested_url = ''
|
||||
var Store = {};
|
||||
var Session = {};
|
||||
var LastRefresh = {};
|
||||
|
|
Loading…
Reference in a new issue