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

View file

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

View file

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