Reduced rerendering of ticket zoom. Improved code layout in ticket create.

This commit is contained in:
Martin Edenhofer 2016-06-08 21:18:40 +02:00
parent 4c0c3165af
commit e9bb0aafc0
3 changed files with 80 additions and 58 deletions

View file

@ -361,7 +361,7 @@ class App.TicketCreate extends App.Controller
e.preventDefault()
@navigate '#'
submit: (e) ->
submit: (e) =>
e.preventDefault()
# get params
@ -443,10 +443,9 @@ class App.TicketCreate extends App.Controller
form: e.target
errors: errors
)
return
# save ticket, create article
else
# check attachment
if article['body']
if App.Utils.checkAttachmentReference(article['body'])

View file

@ -29,14 +29,14 @@ class App.TicketZoom extends App.Controller
else
@overview_id = false
@key = 'ticket::' + @ticket_id
@key = "ticket::#{@ticket_id}"
cache = App.SessionStorage.get(@key)
if cache
@load(cache)
update = =>
@fetch(@ticket_id, false)
# check if ticket has beed updated every 30 min
update = =>
@fetch()
@interval(update, 1800000, 'pull_check')
# fetch new data if triggered
@ -48,29 +48,46 @@ class App.TicketZoom extends App.Controller
# check if we already have the request queued
#@log 'notice', 'TRY', @ticket_id, new Date(data.updated_at), new Date(@ticketUpdatedAtLastCall)
update = =>
@fetch(@ticket_id, false)
@fetch()
if !@ticketUpdatedAtLastCall || ( new Date(data.updated_at).toString() isnt new Date(@ticketUpdatedAtLastCall).toString() )
@delay(update, 500, "ticket-zoom-#{@ticket_id}")
@delay(update, 1200, "ticket-zoom-#{@ticket_id}")
)
# rerender view, e. g. on langauge change
@bind('ui:rerender', =>
@fetch(@ticket_id, true)
@fetch(true)
)
fetch: (ticket_id, force) ->
fetchStart: (force) =>
if !force && @fetchIsRunning
@fetchIsRunningAgain = true
return false
if force
@fetchIsRunningAgain = false
@fetchIsRunning = true
true
fetchDone: =>
@fetchIsRunning = false
if @fetchIsRunningAgain
@fetchIsRunningAgain = false
@fetch()
fetch: (force) =>
return if !@Session.get()
return if !@fetchStart(force)
# get data
@ajax(
id: "ticket_zoom_#{ticket_id}"
id: "ticket_zoom_#{@ticket_id}"
type: 'GET'
url: "#{@apiPath}/tickets/#{ticket_id}?all=true"
url: "#{@apiPath}/tickets/#{@ticket_id}?all=true"
processData: true
success: (data, status, xhr) =>
@fetchDone()
# check if ticket has changed
newTicketRaw = data.assets.Ticket[ticket_id]
newTicketRaw = data.assets.Ticket[@ticket_id]
if @ticketUpdatedAtLastCall && !force
# return if ticket hasnt changed
@ -88,10 +105,11 @@ class App.TicketZoom extends App.Controller
if !@doNotLog
@doNotLog = 1
@recentView('Ticket', ticket_id)
@recentView('Ticket', @ticket_id)
error: (xhr) =>
@renderDone = false
@fetchDone()
statusText = xhr.statusText
status = xhr.status
detail = xhr.responseText
@ -99,6 +117,8 @@ class App.TicketZoom extends App.Controller
# ignore if request is aborted
return if statusText is 'abort'
@renderDone = false
# if ticket is already loaded, ignore status "0" - network issues e. g. temp. not connection
if @ticketUpdatedAtLastCall && status is 0
console.log('network issues e. g. temp. not connection', status, statusText, detail)
@ -190,9 +210,6 @@ class App.TicketZoom extends App.Controller
return
@activeState = true
# start autosave
@autosaveStart()
# if ticket is shown the first time
if !@shown
@shown = true
@ -206,6 +223,9 @@ class App.TicketZoom extends App.Controller
# observe content header position
@positionPageHeaderStart()
# start autosave
@autosaveStart()
hide: =>
@activeState = false
@ -349,6 +369,8 @@ class App.TicketZoom extends App.Controller
task_key: @task_key
formMeta: @formMeta
markForm: @markForm
tags: @tags
links: @links
)
# render init content
@ -667,7 +689,7 @@ class App.TicketZoom extends App.Controller
@autosaveStart()
@muteTask()
@fetch(ticket.id, false)
@fetch()
# enable form
@formEnable(e)

View file

@ -53,7 +53,7 @@ class TaskbarTaskTest < TestCase
tasks_close_all()
click(css: 'a[href="#new"]')
click(css: 'a[href="#ticket/create"]', wait: 2)
click(css: 'a[href="#ticket/create"]', wait: 0.8)
set(
css: '.active .newTicket input[name="title"]',
value: 'INBOUND TEST#1',
@ -62,9 +62,10 @@ class TaskbarTaskTest < TestCase
css: '.active .newTicket [data-name="body"]',
value: 'INBOUND BODY TEST#1',
)
sleep 2
click(css: 'a[href="#new"]')
click(css: 'a[href="#ticket/create"]', wait: 2)
click(css: 'a[href="#ticket/create"]', wait: 0.8)
set(
css: '.active .newTicket input[name="title"]',
value: 'OUTBOUND TEST#1',
@ -73,7 +74,7 @@ class TaskbarTaskTest < TestCase
css: '.active .newTicket [data-name="body"]',
value: 'OUTBOUND BODY TEST#1',
)
sleep 4
sleep 2
logout()
sleep 4