Reduced rerendering of attribute bar in ticket zoom

This commit is contained in:
Martin Edenhofer 2016-03-29 14:57:49 +02:00
parent e0e4fa249c
commit 16ee920cf9
5 changed files with 48 additions and 20 deletions

View file

@ -94,6 +94,7 @@ class App.TaskbarWidget extends App.Controller
new Remove( new Remove(
key: key key: key
ui: @ ui: @
event: e
) )
return return
@ -131,6 +132,6 @@ class Remove extends App.ControllerModal
content: -> content: ->
App.i18n.translateContent('Tab has changed, you really want to close it?') App.i18n.translateContent('Tab has changed, you really want to close it?')
onSubmit: (e) => onSubmit: =>
@close() @close()
@ui.remove(e, @key, true) @ui.remove(@event, @key, true)

View file

@ -51,7 +51,7 @@ class App.TicketZoom extends App.Controller
update = => update = =>
@fetch(@ticket_id, false) @fetch(@ticket_id, false)
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, 1200, '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
@ -100,7 +100,7 @@ class App.TicketZoom extends App.Controller
@activeState = true @activeState = true
# start autosave # start autosave
@autosaveStart() @delay(@autosaveStart, 800, "ticket-zoom-auto-save-#{@ticket_id}")
# if ticket is shown the first time # if ticket is shown the first time
if !@shown if !@shown
@ -122,6 +122,7 @@ class App.TicketZoom extends App.Controller
@positionPageHeaderStop() @positionPageHeaderStop()
# stop autosave # stop autosave
@clearDelay("ticket-zoom-auto-save-#{@ticket_id}")
@autosaveStop() @autosaveStop()
changed: => changed: =>
@ -687,12 +688,12 @@ class App.TicketZoom extends App.Controller
processData: false processData: false
) )
# reset edit ticket / reset new article
App.Event.trigger('ui::ticket::taskReset', { ticket_id: @ticket.id })
# hide reset button # hide reset button
@$('.js-reset').addClass('hide') @$('.js-reset').addClass('hide')
# reset edit ticket / reset new article
App.Event.trigger('ui::ticket::taskReset', { ticket_id: @ticket.id })
# remove change flag on tab # remove change flag on tab
@$('.tabsSidebar-tab[data-tab="ticket"]').removeClass('is-changed') @$('.tabsSidebar-tab[data-tab="ticket"]').removeClass('is-changed')

View file

@ -1,7 +1,7 @@
class App.TicketZoomAttributeBar extends App.Controller class App.TicketZoomAttributeBar extends App.Controller
elements: elements:
'.js-submitDropdown': 'buttonDropdown' '.js-submitDropdown': 'buttonDropdown'
'.js-secondaryActionButtonLabel': 'secondaryActionButton' '.js-reset': 'resetButton'
events: events:
'mousedown .js-openDropdownMacro': 'toggleDropdownMacro' 'mousedown .js-openDropdownMacro': 'toggleDropdownMacro'
@ -16,7 +16,7 @@ class App.TicketZoomAttributeBar extends App.Controller
@secondaryAction = 'stayOnTab' @secondaryAction = 'stayOnTab'
@subscribeId = App.Macro.subscribe(@render) @subscribeId = App.Macro.subscribe(@checkMacroChanges)
@render() @render()
# rerender, e. g. on language change # rerender, e. g. on language change
@ -28,15 +28,31 @@ class App.TicketZoomAttributeBar extends App.Controller
App.Macro.unsubscribe(@subscribeId) App.Macro.unsubscribe(@subscribeId)
render: => render: =>
# remember current reset state
resetButtonShown = false
if @resetButton.get(0) && !@resetButton.hasClass('hide')
resetButtonShown = true
macros = App.Macro.all() macros = App.Macro.all()
@macroLastUpdated = App.Macro.lastUpdatedAt()
if _.isEmpty(macros) || !@isRole('Agent') if _.isEmpty(macros) || !@isRole('Agent')
macroDisabled = true macroDisabled = true
@html App.view('ticket_zoom/attribute_bar')(
localeEl = $(App.view('ticket_zoom/attribute_bar')(
macros: macros macros: macros
macroDisabled: macroDisabled macroDisabled: macroDisabled
overview_id: @overview_id overview_id: @overview_id
) resetButtonShown: resetButtonShown
@setSecondaryAction() ))
@setSecondaryAction(@secondaryAction, localeEl)
@html localeEl
checkMacroChanges: =>
macroLastUpdated = App.Macro.lastUpdatedAt()
return if macroLastUpdated is @macroLastUpdated
@render()
toggleDropdownMacro: => toggleDropdownMacro: =>
if @buttonDropdown.hasClass 'is-open' if @buttonDropdown.hasClass 'is-open'
@ -65,12 +81,12 @@ class App.TicketZoomAttributeBar extends App.Controller
chooseSecondaryAction: (e) => chooseSecondaryAction: (e) =>
type = $(e.currentTarget).find('.js-secondaryActionLabel').data('type') type = $(e.currentTarget).find('.js-secondaryActionLabel').data('type')
@setSecondaryAction(type) @setSecondaryAction(type, @el)
setSecondaryAction: (type = @secondaryAction) => setSecondaryAction: (type, localEl) ->
element = @$(".js-secondaryActionLabel[data-type=#{type}]") element = localEl.find(".js-secondaryActionLabel[data-type=#{type}]")
text = element.text() text = element.text()
@$('.js-secondaryAction .js-selectedIcon.is-selected').removeClass('is-selected') localEl.find('.js-secondaryAction .js-selectedIcon.is-selected').removeClass('is-selected')
element.closest('.js-secondaryAction').find('.js-selectedIcon').addClass('is-selected') element.closest('.js-secondaryAction').find('.js-selectedIcon').addClass('is-selected')
@secondaryActionButton.text(text) localEl.find('.js-secondaryActionButtonLabel').text(text)
@secondaryActionButton.data('type', type) localEl.find('.js-secondaryActionButtonLabel').data('type', type)

View file

@ -666,3 +666,13 @@ class App.Model extends Spine.Model
activityMessage: (item) -> activityMessage: (item) ->
return "Need own activityMessage() in model to generate text (#{@objectDisplayName()}/#{item.type})." return "Need own activityMessage() in model to generate text (#{@objectDisplayName()}/#{item.type})."
@lastUpdatedAt: ->
updated_at
for item in @all()
if item.updated_at
if !updated_at
updated_at = item.updated_at
else if item.updated_at > updated_at
updated_at = item.updated_at
updated_at

View file

@ -1,4 +1,4 @@
<div class="buttonDropdown btn js-reset hide"><%- @T('Discard your unsaved changes.') %></div> <div class="buttonDropdown btn js-reset <% if !@resetButtonShown: %>hide<% end %>"><%- @T('Discard your unsaved changes.') %></div>
<div class="buttonDropdown dropdown dropdown--actions dropup"> <div class="buttonDropdown dropdown dropdown--actions dropup">
<div class="btn btn--text btn--icon--last" data-toggle="dropdown"> <div class="btn btn--text btn--icon--last" data-toggle="dropdown">
<span class="js-secondaryActionButtonLabel"></span> <%- @Icon('arrow-up') %> <span class="js-secondaryActionButtonLabel"></span> <%- @Icon('arrow-up') %>