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
|
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') ->
|
userPopups: (position = 'right') ->
|
||||||
|
|
||||||
|
# remove old popovers
|
||||||
|
$('.popover-inner').parent().remove()
|
||||||
|
|
||||||
# show user popup
|
# show user popup
|
||||||
$('.user-data').popover(
|
$('.user-data').popover(
|
||||||
delay: { show: 500, hide: 1200 },
|
delay: { show: 500, hide: 1200 },
|
||||||
|
@ -570,6 +592,10 @@ class App.Controller extends Spine.Controller
|
||||||
)
|
)
|
||||||
|
|
||||||
userTicketPopups: (data) ->
|
userTicketPopups: (data) ->
|
||||||
|
|
||||||
|
# remove old popovers
|
||||||
|
$('.popover-inner').parent().remove()
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
@tickets = {}
|
@tickets = {}
|
||||||
ajax = new App.Ajax
|
ajax = new App.Ajax
|
||||||
|
|
|
@ -6,46 +6,58 @@ class App.DashboardActivityStream extends App.Controller
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
# @log 'aaaa', @el
|
|
||||||
|
|
||||||
@items = []
|
@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
|
# get data
|
||||||
|
if @req
|
||||||
|
@req.abort()
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/activity_stream',
|
url: '/activity_stream',
|
||||||
data: {
|
data: {
|
||||||
limit: @limit,
|
limit: @limit,
|
||||||
}
|
}
|
||||||
processData: true,
|
processData: true,
|
||||||
# data: JSON.stringify( view: @view ),
|
success: @load
|
||||||
success: (data, status, xhr) =>
|
|
||||||
@items = data.activity_stream
|
|
||||||
|
|
||||||
# load user collection
|
|
||||||
@loadCollection( type: 'User', data: data.users )
|
|
||||||
|
|
||||||
# load ticket collection
|
|
||||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
|
||||||
|
|
||||||
@render()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
load: (data) =>
|
||||||
|
items = data.activity_stream
|
||||||
|
|
||||||
render: ->
|
# load user collection
|
||||||
|
@loadCollection( type: 'User', data: data.users )
|
||||||
|
|
||||||
|
# load ticket collection
|
||||||
|
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||||
|
|
||||||
|
# set cache
|
||||||
|
window.LastRefresh[ 'dashboard_activity_stream' ] = items
|
||||||
|
|
||||||
|
@render(items)
|
||||||
|
|
||||||
|
render: (items) ->
|
||||||
|
|
||||||
# load user data
|
# load user data
|
||||||
for item in @items
|
for item in items
|
||||||
item.created_by = App.User.find(item.created_by_id)
|
item.created_by = App.User.find(item.created_by_id)
|
||||||
|
|
||||||
# load ticket data
|
# load ticket data
|
||||||
for item in @items
|
for item in items
|
||||||
item.ticket = App.Ticket.find(item.o_id)
|
item.ticket = App.Ticket.find(item.o_id)
|
||||||
|
|
||||||
html = App.view('dashboard/activity_stream')(
|
html = App.view('dashboard/activity_stream')(
|
||||||
head: 'Activity Stream',
|
head: 'Activity Stream',
|
||||||
items: @items
|
items: items
|
||||||
)
|
)
|
||||||
html = $(html)
|
html = $(html)
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,10 @@ class App.DashboardRecentViewed extends App.Controller
|
||||||
@items = []
|
@items = []
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
|
if @req
|
||||||
|
@req.abort()
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/recent_viewed',
|
url: '/recent_viewed',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -3,13 +3,22 @@ $ = jQuery.sub()
|
||||||
class App.DashboardRss extends App.Controller
|
class App.DashboardRss extends App.Controller
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
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
|
# get data
|
||||||
|
if @req
|
||||||
|
@req.abort()
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/rss_fetch',
|
url: '/rss_fetch',
|
||||||
data: {
|
data: {
|
||||||
|
@ -17,15 +26,21 @@ class App.DashboardRss extends App.Controller
|
||||||
url: @url,
|
url: @url,
|
||||||
}
|
}
|
||||||
processData: true,
|
processData: true,
|
||||||
success: (data, status, xhr) =>
|
success: @load
|
||||||
@items = data.items || []
|
|
||||||
@render()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
render: ->
|
load: (data) =>
|
||||||
|
items = data.items || []
|
||||||
|
|
||||||
|
# set cache
|
||||||
|
window.LastRefresh[ 'dashboard_rss' ] = items
|
||||||
|
|
||||||
|
@render(items)
|
||||||
|
|
||||||
|
render: (items) ->
|
||||||
html = App.view('dashboard/rss')(
|
html = App.view('dashboard/rss')(
|
||||||
head: @head,
|
head: @head,
|
||||||
items: @items
|
items: items
|
||||||
)
|
)
|
||||||
html = $(html)
|
html = $(html)
|
||||||
@html html
|
@html html
|
||||||
|
|
|
@ -13,13 +13,23 @@ class App.DashboardTicket extends App.Controller
|
||||||
@start_page = 1
|
@start_page = 1
|
||||||
@navupdate '#'
|
@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
|
# get data
|
||||||
|
if @req
|
||||||
|
@req.abort()
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/ticket_overviews',
|
url: '/ticket_overviews',
|
||||||
data: {
|
data: {
|
||||||
|
@ -28,36 +38,40 @@ class App.DashboardTicket extends App.Controller
|
||||||
start_page: @start_page,
|
start_page: @start_page,
|
||||||
}
|
}
|
||||||
processData: true,
|
processData: true,
|
||||||
# data: JSON.stringify( view: @view ),
|
success: @load
|
||||||
success: (data, status, xhr) =>
|
|
||||||
|
|
||||||
# get meta data
|
|
||||||
@overview = data.overview
|
|
||||||
App.Overview.refresh( @overview, options: { clear: true } )
|
|
||||||
|
|
||||||
App.Overview.unbind('local:rerender')
|
|
||||||
App.Overview.bind 'local:rerender', (record) =>
|
|
||||||
@log 'rerender...', record
|
|
||||||
@render()
|
|
||||||
|
|
||||||
App.Overview.unbind('local:refetch')
|
|
||||||
App.Overview.bind 'local:refetch', (record) =>
|
|
||||||
@log 'refetch...', record
|
|
||||||
@fetch()
|
|
||||||
|
|
||||||
# load user collection
|
|
||||||
@loadCollection( type: 'User', data: data.users )
|
|
||||||
|
|
||||||
# load ticket collection
|
|
||||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
|
||||||
|
|
||||||
@tickets = data.tickets
|
|
||||||
@tickets_count = data.tickets_count
|
|
||||||
|
|
||||||
@render()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
render: ->
|
load: (data) =>
|
||||||
|
|
||||||
|
# get meta data
|
||||||
|
App.Overview.refresh( data.overview, options: { clear: true } )
|
||||||
|
|
||||||
|
App.Overview.unbind('local:rerender')
|
||||||
|
App.Overview.bind 'local:rerender', (record) =>
|
||||||
|
@log 'rerender...', record
|
||||||
|
@render(data)
|
||||||
|
|
||||||
|
App.Overview.unbind('local:refetch')
|
||||||
|
App.Overview.bind 'local:refetch', (record) =>
|
||||||
|
@log 'refetch...', record
|
||||||
|
@fetch()
|
||||||
|
|
||||||
|
# load user collection
|
||||||
|
@loadCollection( type: 'User', data: data.users )
|
||||||
|
|
||||||
|
# load ticket collection
|
||||||
|
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||||
|
|
||||||
|
# set cache
|
||||||
|
window.LastRefresh[ @key ] = data
|
||||||
|
|
||||||
|
@render( data )
|
||||||
|
|
||||||
|
render: (data) ->
|
||||||
|
|
||||||
|
@overview = data.overview
|
||||||
|
@tickets_count = data.tickets_count
|
||||||
|
@tickets = data.tickets
|
||||||
|
|
||||||
pages_total = parseInt( ( @tickets_count / @overview.view.d.per_page ) + 0.99999 ) || 1
|
pages_total = parseInt( ( @tickets_count / @overview.view.d.per_page ) + 0.99999 ) || 1
|
||||||
html = App.view('dashboard/ticket')(
|
html = App.view('dashboard/ticket')(
|
||||||
|
@ -80,7 +94,7 @@ class App.DashboardTicket extends App.Controller
|
||||||
|
|
||||||
if _.isEmpty(@tickets)
|
if _.isEmpty(@tickets)
|
||||||
table = ''
|
table = ''
|
||||||
# table = '-none-'
|
table = '-none-'
|
||||||
|
|
||||||
# append content table
|
# append content table
|
||||||
html.find('.table-overview').append(table)
|
html.find('.table-overview').append(table)
|
||||||
|
|
|
@ -29,7 +29,9 @@ class Index extends App.Controller
|
||||||
fetch: () ->
|
fetch: () ->
|
||||||
# get data
|
# get data
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
if @req
|
||||||
|
@req.abort()
|
||||||
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/ticket_create',
|
url: '/ticket_create',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -31,10 +31,11 @@ class Index extends App.Controller
|
||||||
|
|
||||||
fetch: ->
|
fetch: ->
|
||||||
|
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
|
if @req
|
||||||
|
@req.abort()
|
||||||
@ajax = new App.Ajax
|
@ajax = new App.Ajax
|
||||||
@ajax.ajax(
|
@req = @ajax.ajax(
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: '/ticket_overviews',
|
url: '/ticket_overviews',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -10,10 +10,10 @@ class App.Navigation extends App.Controller
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
sync_ticket_overview = =>
|
sync_ticket_overview = =>
|
||||||
@sync(@ticket_overview, 30000,'interval_id_ticket_overview')
|
@interval( @ticket_overview, 30000, 'nav_ticket_overview' )
|
||||||
|
|
||||||
sync_recent_viewed = =>
|
sync_recent_viewed = =>
|
||||||
@sync(@recent_viewed, 40000, 'interval_id_recent_viewed')
|
@interval( @recent_viewed, 40000, 'nav_recent_viewed' )
|
||||||
|
|
||||||
Spine.bind 'navupdate', (data) =>
|
Spine.bind 'navupdate', (data) =>
|
||||||
@update(arguments[0])
|
@update(arguments[0])
|
||||||
|
@ -29,8 +29,6 @@ class App.Navigation extends App.Controller
|
||||||
|
|
||||||
# rerender if new overview data is there
|
# rerender if new overview data is there
|
||||||
@delay( sync_ticket_overview, 800 )
|
@delay( sync_ticket_overview, 800 )
|
||||||
@delay( sync_ticket_overview, 2000 )
|
|
||||||
|
|
||||||
@delay( sync_recent_viewed, 1000 )
|
@delay( sync_recent_viewed, 1000 )
|
||||||
|
|
||||||
render: (user) ->
|
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')
|
||||||
# @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
|
# get data
|
||||||
ticket_overview: =>
|
ticket_overview: =>
|
||||||
|
|
||||||
|
@ -158,34 +138,40 @@ class App.Navigation extends App.Controller
|
||||||
if !window.Session['id']
|
if !window.Session['id']
|
||||||
return
|
return
|
||||||
|
|
||||||
@ajax = new App.Ajax
|
# only of lod request is already done
|
||||||
@ajax.ajax(
|
|
||||||
type: 'GET',
|
|
||||||
url: '/ticket_overviews',
|
|
||||||
data: {},
|
|
||||||
processData: true,
|
|
||||||
success: (data, status, xhr) =>
|
|
||||||
|
|
||||||
# remove old views
|
if !@req_overview
|
||||||
for key of Config.NavBar
|
@ajax = new App.Ajax
|
||||||
if Config.NavBar[key].parent is '#ticket/view'
|
# @req_overview.abort()
|
||||||
delete Config.NavBar[key]
|
@req_overview = @ajax.ajax(
|
||||||
|
type: 'GET',
|
||||||
|
url: '/ticket_overviews',
|
||||||
|
data: {},
|
||||||
|
processData: true,
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
# add new views
|
# remove old views
|
||||||
for item in data
|
for key of Config.NavBar
|
||||||
Config.NavBar['TicketOverview' + item.url] = {
|
if Config.NavBar[key].parent is '#ticket/view'
|
||||||
prio: item.prio,
|
delete Config.NavBar[key]
|
||||||
parent: '#ticket/view',
|
|
||||||
name: item.name,
|
|
||||||
count: item.count,
|
|
||||||
target: '#ticket/view/' + item.url,
|
|
||||||
role: ['Agent'],
|
|
||||||
}
|
|
||||||
|
|
||||||
# rebuild navbar
|
# add new views
|
||||||
Spine.trigger 'navrebuild', window.Session
|
for item in data
|
||||||
)
|
Config.NavBar['TicketOverview' + item.url] = {
|
||||||
|
prio: item.prio,
|
||||||
|
parent: '#ticket/view',
|
||||||
|
name: item.name,
|
||||||
|
count: item.count,
|
||||||
|
target: '#ticket/view/' + item.url,
|
||||||
|
role: ['Agent'],
|
||||||
|
}
|
||||||
|
|
||||||
|
# rebuild navbar
|
||||||
|
Spine.trigger 'navrebuild', window.Session
|
||||||
|
|
||||||
|
# reset ajax call
|
||||||
|
@req_overview = undefined
|
||||||
|
)
|
||||||
|
|
||||||
# get data
|
# get data
|
||||||
recent_viewed: =>
|
recent_viewed: =>
|
||||||
|
@ -199,51 +185,56 @@ class App.Navigation extends App.Controller
|
||||||
if !window.Session['id']
|
if !window.Session['id']
|
||||||
return
|
return
|
||||||
|
|
||||||
@ajax = new App.Ajax
|
# only of lod request is already done
|
||||||
@ajax.ajax(
|
if !@req_recent_viewed
|
||||||
type: 'GET',
|
@ajax = new App.Ajax
|
||||||
url: '/recent_viewed',
|
@req_recent_viewed = @ajax.ajax(
|
||||||
data: {
|
type: 'GET',
|
||||||
limit: 5,
|
url: '/recent_viewed',
|
||||||
}
|
data: {
|
||||||
processData: true,
|
limit: 5,
|
||||||
success: (data, status, xhr) =>
|
}
|
||||||
|
processData: true,
|
||||||
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
items = data.recent_viewed
|
items = data.recent_viewed
|
||||||
|
|
||||||
# load user collection
|
# load user collection
|
||||||
@loadCollection( type: 'User', data: data.users )
|
@loadCollection( type: 'User', data: data.users )
|
||||||
|
|
||||||
# load ticket collection
|
# load ticket collection
|
||||||
@loadCollection( type: 'Ticket', data: data.tickets )
|
@loadCollection( type: 'Ticket', data: data.tickets )
|
||||||
|
|
||||||
# remove old views
|
# remove old views
|
||||||
for key of Config.NavBarRight
|
for key of Config.NavBarRight
|
||||||
if Config.NavBarRight[key].parent is '#current_user'
|
if Config.NavBarRight[key].parent is '#current_user'
|
||||||
part = Config.NavBarRight[key].target.split '::'
|
part = Config.NavBarRight[key].target.split '::'
|
||||||
if part is 'RecendViewed'
|
if part is 'RecendViewed'
|
||||||
delete Config.NavBarRight[key]
|
delete Config.NavBarRight[key]
|
||||||
|
|
||||||
# add new views
|
# add new views
|
||||||
prio = 5000
|
prio = 5000
|
||||||
for item in items
|
for item in items
|
||||||
divider = false
|
divider = false
|
||||||
navheader = false
|
navheader = false
|
||||||
if prio is 5000
|
if prio is 5000
|
||||||
divider = true
|
divider = true
|
||||||
navheader = 'Recent Viewed'
|
navheader = 'Recent Viewed'
|
||||||
ticket = App.Ticket.find(item.o_id)
|
ticket = App.Ticket.find(item.o_id)
|
||||||
prio++
|
prio++
|
||||||
Config.NavBarRight['RecendViewed::' + ticket.id] = {
|
Config.NavBarRight['RecendViewed::' + ticket.id] = {
|
||||||
prio: prio,
|
prio: prio,
|
||||||
parent: '#current_user',
|
parent: '#current_user',
|
||||||
name: item.history_object.name + ' (' + ticket.title + ')',
|
name: item.history_object.name + ' (' + ticket.title + ')',
|
||||||
target: '#ticket/zoom/' + ticket.id,
|
target: '#ticket/zoom/' + ticket.id,
|
||||||
role: ['Agent'],
|
role: ['Agent'],
|
||||||
divider: divider,
|
divider: divider,
|
||||||
navheader: navheader
|
navheader: navheader
|
||||||
}
|
}
|
||||||
|
|
||||||
# rebuild navbar
|
# rebuild navbar
|
||||||
Spine.trigger 'navrebuild', window.Session
|
Spine.trigger 'navrebuild', window.Session
|
||||||
)
|
|
||||||
|
# reset ajax call
|
||||||
|
@req_recent_viewed = undefined
|
||||||
|
)
|
||||||
|
|
|
@ -6,3 +6,4 @@ Config.product_name = 'Zammad'
|
||||||
Config.requested_url = ''
|
Config.requested_url = ''
|
||||||
var Store = {};
|
var Store = {};
|
||||||
var Session = {};
|
var Session = {};
|
||||||
|
var LastRefresh = {};
|
||||||
|
|
Loading…
Reference in a new issue